Cross Domain Tracking

cross domain tracking

What is cross domain tracking?

Cross domain tracking is an approach to allow Google Analytics to track a visitor as a continuous session on two or more related sites, domains or subdomains. You can track one user on multiple domains, or subdomains, with one session. This will be helpful to determine where your user is coming from, and what the best traffic sources are to convert them.

Why cross domain tracking needed

So you have a website with two or more different domains or subdomain names (e.g. and not wanting to waste time looking at two sets of information in GA instead you might want to consolidate the data from both the URLs into one report. To achieve this in Google Analytics we will have to use cross domain tracking.

I will explain a bit more with the below example:

The user is coming from twitter on User navigates through a few pages and is interested in your package. He clicks from to in order to purchase the flower package. Without cross domain tracking setup Google Analytics will treat the same user as two different users. Whereas as the user session that actually span across the two domains will be counted as two different sessions instead of a single session.

In order to fix this, you’ll need to setup cross-domain tracking setup.

  •         Example of subdomain site (we will use these domains as an example throughout the post):, and
  •         Example of different domain site(we will use these domains as an example throughout the pos):, and

How to setup cross domain tracking by modifying the tracking code

By default Universal Analytics can track traffic across all pages, subdirectories and subdomains of your website.

Universal Analytics can’t track traffic across different primary domains by default. As Universal Analytics uses a first party cookie, it cannot share this information with other domains. This is where Cross Domain Tracking comes into play. In this case we need to instruct it to share the values of the cookie with the cookie of

To setup cross-domain tracking for your domains, you’ll need to modify the universal tracking code on each domain. Basic knowledge of JavaScript and HTML will be sufficient to get this done. You need to edit the tracking code snippet across the web pages for cross domain tracking to work.

Find the create line in the tracking code snippet. Below is how the code snipped for a website called looks like:

ga('create', 'UA-XXXXXXX-Y', '');

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', [''] );

Don’t forget to replace the example tracking ID (UA-XXXXXX-Y) with your own tracking ID, and replace the example domain with your domain name.

Note: Knowledge of cookies will help you greatly in implementing and debugging cross domain tracking.

If you like my articles,