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:

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga('create', 'MyTrackingID', 'MyDomain');
ga('send', 'pageview');

(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]);

(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);

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

2 Answers 2


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)


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:

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  • 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, 2013 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, 2013 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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