Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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)

share|improve this answer
add comment

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

Google Analytics Multiple top-level domains setting


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>
share|improve this answer
    
It appears this option is only available for ga.js (non-universal Google Analytics) and not analytics.js which Universal Analytics uses. –  dan Sep 30 '13 at 16:06
    
Using the autoLink plugin is Experimental. The OP, and anyone else reading this, really needs to read that help doc (the same one I already linked to), and output their specific tracking code from the Universal Analytics interface first. –  dan Sep 30 '13 at 19:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.