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 set up cross domain tracking using the autoLink plugin, a tool that simplifies the cross domain setup process, though you can also complete this process manually (see the section for developers at the end of this page for more information).

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

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.

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 tracking code 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 descriptions in this article for cross domain tracking to work property.

Step 2: Edit the tracking code on the 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-01', 'example-1.com');

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

  ga('create', 'UA-XXXXXXX-01', 'auto');
  ga('require', 'linker');
  ga('linker:autoLink', ['example-2.com'] );

Remember to replace the example the tracking ID (UA-XXXXXX-01) 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.

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-XXXXXX-Y', 'auto');
ga('require', 'linker');
ga('linker:autoLink', ['example-2.com']);

ga('send', 'pageview');

</script>

You can also set up cross domain tracking for three or more domains following this example. To do this, include the additional domains you want to track in the autoLink plugin (the changes you need to make are in bold red text, and even the comma is important):

  ga('create', 'UA-XXXXXXX-01', ['example-2.com',’example-3.com’]);

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

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

   ga('create', 'UA-XXXXXXX-01', 'auto', {
   'allowLinker': true
  });

Remember to replace the example the tracking ID (UA-XXXXXX-01) with your own tracking ID.

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

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-XXXXXX-01', 'auto', {
  'allowLinker': true
});

ga('send', 'pageview');

</script>

If you’re setting up cross domain tracking for three or more domains, make this exact change to the tracking code snippet included on all webpages of all subordinate domains (all your domains except the primary domain).

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.