Tracking Multiple Domains

Set up cross domain tracking

To set up cross domain tracking for multiple top-level domains, you need to set up the web tracking code on both domains and set up the autoLink plugin. You should have a basic knowledge of HTML and JavaScript or work with a developer to do this.

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 the web tracking code on all domains.

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, but you need to edit the snippet to specify each domain name.

For example, if you are tracking example-1.com and example-2.com, edit the snippet on all example-1.com pages to include example-1.com as the domain name (in bold):

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

Edit for the snippet on all example-2.com pages to include example-2.com as the domain name (in bold):

  ga('create', 'UA-XXXXXXX-01', 'example-2.com');

Remember to replace example-1.com and example-2.com with your real domain names, and replace the example the tracking ID (UA-XXXXXX-01) with your own tracking ID. Notice, however, that the tracking ID needs to be the same on both domains for cross domain tracking to work.

If you’re tracking three or more domains, do the same thing for each additional domain as demonstrated with example-1.com and example-2.com in this example.

For more set up help, follow the instructions on how to set up the web tracking code, but remember: You must customise the snippet using the descriptions in this article for cross domain tracking to work properly.

Step 2: Add the autoLink plugin to your tracking code.

How the autoLink plugin works

When you add the autoLink plugin to your tracking code, it automatically loads with your pages and does a substring match on all your links. It then recognises any links that include a domain name that you’ve specified in your tracking code. Any traffic that clicks a link to those domains get counted as cross domain traffic.

For example, you might have two domains, example-1.com and example-2.com and have set up the web tracking code for cross domain tracking by following the example above. When you use the autoLink plugin, it recognises links on example-1.com that go to example-2.com. This means that when a user visits a page on example-1.com and clicks a link to example-2.com, the autoLink plugin counts the navigation as cross domain traffic.

Although the autoLink plugin is designed to work automatically after it’s set up, it’s possible to have pages that are set up in ways that stop the plugin from working. We recommend that you test the plugin on one page before implementing it on your entire site.

How to add the autoLink plugin to your tracking code

To set up the autoLink plugin, you must add the plugin to your tracking code snippet, define the domains that you want to track and tell each page to allow the plugin to run.

For example, if you have the two domains example-1.com and example-2.com, you should edit your tracking code snippet on all of the example-1.com pages so it looks like the example below (except the tracking ID and domain names should be replaced with your actual tracking ID and domain names). The parts you need to add to your tracking code are in bold:

<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', ‘example-1.com' ‘auto’, {
  ‘allowLinker’: true
});
ga('require', 'linker');
ga('linker:autoLink', ['example-2.com'] );

ga('send', 'pageview');

</script>

You also need to edit the tracking code snippet on all the example-2.com pages look the tracking code should also look like this example, but put example-2.com in the create command, and example-1.com in the autoLink.

You can also set up cross domain tracking for three or more domains following this example, but include the additional domains in the autoLink plugin. For example, in bold:

  ga('linker:autoLink', ['example-2.com',’example-3.com’] );

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.

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 drop-down 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.