Tracking across multiple domains

Set up cross domain tracking

To set up cross domain tracking for multiple top-level domains, you need to set up and edit the web tracking code on both domains.

This article explains how to use the autoLink plugin to track traffic traveling between two domains, regardless of where the traffic originates and how many times it moves back and forth between different domains.

If you need to set up cross domain tracking for another configuration, like multiple domain aliases, refer to our Developer Guides and work with a developer to complete the process.

You should have a basic knowledge of HTML and JavaScript or work with a developer to set up cross domain tracking.

The changes you need to make depend on which tracking code you’re using. See if you have Classic Analytics (ga.js) or Universal Analytics (analytics.js).

The examples in this article use the Universal Analytics tracking code snippet (analytics.js). If you’re using Classic Analytics (ga.js), refer to the Developer Guide on Classic Analytics (ga.js) for more information.

Step 1: Set up a property in your Google Analytics account.

For cross domain tracking, set up one property in your Google Analytics account. Use the same tracking code snippet and tracking ID from that property for all of your domains.

You need to edit the tracking code snippet for cross domain tracking to work. If you haven’t already included the snippet on all your webpages, you might want copy and paste it into a text editor before continuing with the instructions here. This way, you only have to make the changes once before including the modified snippet on all your webpages.

For details on setup help, follow the instructions on how to set up the web tracking code, but remember: You must customize the snippet using the instructions in this article for cross domain tracking to work property.

Step 2: Edit the tracking code for the primary domain.

Find the create line in the snippet. For a website called example-1.com, it looks like this:

  ga('create', 'UA-XXXXXXX-Y', 'example-1.com');

Make the following changes to the snippet (the changes you need to make are in bold red text):

  ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
  ga('require', 'linker');
  ga('linker:autoLink', ['example-2.com'] );

Remember to replace the example the tracking ID (UA-XXXXXX-Y) with your own tracking ID, and replace the example secondary domain (example-2.com) with your own secondary domain name.

The tracking code snippet must contain these changes every place it appears on your primary domain.

For three or more domains

Follow the example above, but add the other domains to the autoLink plugin. Even the additional comma here is important:

ga('linker:autoLink', ['example-2.com', 'example-3.com'] );
See what this looks like in full context

The tracking code snippet on your primary domain should look 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', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['example-2.com'] );

ga('send', 'pageview');

</script>

Step 3: Edit the tracking code on the secondary domain.

Find the create line in the snippet. Make the following changes to the snippet (the changes you need to make are in bold red text):

  ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
  ga('require', 'linker');
  ga('linker:autoLink', ['example-1.com'] );

Remember to replace the example the tracking ID (UA-XXXXXX-Y) with your own tracking ID, and replace the example primary domain (example-1.com) with your own primary domain name.

The tracking code snippet must contain these changes every place it appears on your primary domain.

For three or more domains

Follow the example above, but add the other domains to the autoLink plugin. Even the additional comma here is important:

ga('linker:autoLink', ['example-1.com', 'example-3.com'] );
See what this looks like in full context

The tracking code snippet on your secondary domain(s) should look 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', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['example-1.com'] );

ga('send', 'pageview');

</script>

Next Steps

Set up more reporting views and add filters

By default, Google Analytics only includes the page path and page name, not the domains name. For example, you might see your pages appear in the Site Content report like this:

  • /about/contactUs.html
  • /about/contactUs.html
  • /products/buy.html

Because the domain names aren’t listed, it might be hard to tell which domain each page belongs to.

To get the domain names to appear in your reports you need to do two things: Create a copy of your reporting view that includes data from all your domains in it and add an advanced filter to that new view. The filter will tell Google Analytics to display domain names in your reports.

Follow this example to set up a view filter that displays domain names in your reports when you have cross domain tracking set up. For some fields, you need to select an item from the dropdown menu. For others, you need to input the characters here:

  • Filter Type: Custom filter > Advanced
  • Field A: Hostname Extract A: (.*)
  • Field B: Request URI Extract: (.*)
  • Output To: Request URI Constructor: $A1$B1

Click Save to create the filter.

For developers: Set up cross domain tracking manually

The autoLink plugin is the easiest way to set up cross domain tracking with Google Analytics, but advanced users and developers can set up cross domain tracking manually. This requires that you change your tracking code snippet on every page on both domains, and that you manually tag all of your interdomain links.

For more information, visit our Developer Guide on Cross Domain Tracking.