Mobile app version of vmapp.org
Login or Join
Kimberly868

: Cross domain tracking with new analytics.js syntax? I am using Google Analytics and I am trying to set cross domain tracking for my website. I've read Google's cross domain tracking guide, but

@Kimberly868

Posted in: #GoogleAnalytics

I am using Google Analytics and I am trying to set cross domain tracking for my website. I've read Google's cross domain tracking guide, but I am confused as to how to implement it properly.

The issue I am having is that the example code they give looks nothing like the tracking code I was given through my Google Analytics admin console.

My tracking code looks like this:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'MyTrackingID', 'MyDomain');
ga('send', 'pageview');
</script>


(My actual tracking ID and my domain have been censored out with MyTrackingID and MyDomain, respectively.)

However, the example tracking code given in the guide looks like this:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>


How do I add the _gaq.push(['_setDomainName', 'A.com']); "option" to my tracking code as instructed?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Kimberly868

2 Comments

Sorted by latest first Latest Oldest Best

 

@Heady270

Use the Google Analytics admin interface to generate the proper tracking code for you. It will has an option specifically for multiple top level domains.


Log into Google Analytics
Select "Admin" in the orange bar
Look under "Property" for ".js Tracking Info"
Set "Multiple top-level domains" to "On"
Install the new tracking code that it gives you into your website






Edit: If you have selected the new tracking style, Google no longer gives you a nice user interface these options. Instead you have to figure out the code yourself manually from their help document

Based on that documentation, your tracking code should be:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('require','linker');
ga(‘linker:autoLink’,[‘example.com’,‘otherexample.com’]);
ga(‘create’,'UA-XXXXXX-X',{‘allowLinker’:true});
ga('send','pageview');
</script>

10% popularity Vote Up Vote Down


 

@Nimeshi995

The example tacking code you're referring to is for ga.js which is used with standard (non-universal) Google Analytics, as indicated in the link you provided:


This information applies to the ga.js tracking method only.


Universal Analytics uses analytics.js tracking code, as can be seen here. Therefore, you'd want to refer to this instead: Cross Domain Tracking - Web Tracking (analytics.js)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme