Google Analytics Cross Domain Tracking explained like never before

 

I have written about cross domain tracking in Google Analytics (ga.js) in the past, which to be honest is quite difficult to implement. But Universal Analytics (analytics.js) has made cross domain tracking quite easy and with the advent of Google Tag Manager, implementation should be a walk in the park.

But judging by the volume of questions I get, and see on cross domain tracking each month and my own personal doubts about certain aspect(s) of cross domain tracking, it is fair to assume that, cross domain tracking is not easy to understand let alone implement.

Cross domain tracking is a very technical concept. It may look easy on the surface, but deep down, it deals with: cookies, client IDs, tracking objects, referrers, sessions, linker parameters…. etc.

These are all the nuts and bolts of cross domain tracking. And if understanding these nuts and bolts do not excite you, than probably cross domain tracking is best left to those who love to live and breath ‘Google Analytics Developers environment’.

Depending upon a website’s front end and/or back end configurations, implementing cross domain tracking can be either a walk in the park or a tough nut to crack.

So the first step towards learning and implementing cross domain tracking, is to consciously realise the fact that you are dealing with something highly technical in nature.

In this article I will start from the very basics and then go into great technical details, while keeping everything as easy to understand as technically possible.

 

Why do you need cross domain tracking?

Without cross domain tracking set-up, you won’t be able to understand and track a user’s journey which span across multiple domains.

For example,

If a user landed on your website say abc.com via the search term ‘top men shoes’ on Google and then made a purchase on another website say xyz.com/abc-cart (where both the shopping cart and the order confirmation page are hosted) then without cross domain tracking set up, Google Analytics will treat the same user as two different users (one user visited abc.com and a different user visited xyz.com/abc-cart and the user session that actually span across the two domains will be counted as two different sessions instead of a single session.

So the GA report of abc.com may tell you that a user visited abc.com via the search term ‘top men shoes‘ on google but didn’t make a purchase.

The GA report of the website, xyz.com may tell you that a user visited xyz.com/abc-cart from abc.com and then made a purchase.

So without cross domain tracking setup, abc.com would endup getting all the credit for conversion instead of the search term ‘top men shoes‘ and google organic search traffic.

 

Another example,

If a user landed on your website abc.com via the search term ‘top men shoes’ on Google, went to checkout on another website, xyz.com/abc-cart (where the shopping cart is hosted but not the order confirmation page) and then completed the purchase on your website abc.com, as the order confirmation page is hosted on your website, in that case, GA may attribute the sales to xyz.com.

Thus, without cross domain tracking setup you may have a hard time determining the original source of your goal conversion and/or ecommerce transaction.

Without cross domain tracking setup, most of your conversions could end up being attributed to direct traffic or to a wrong website.

Another advantage of cross domain tracking is that, when you implement it, you can collect data from multiple websites into a single reporting view.

 

When do you need cross domain tracking?

You need cross domain tracking when your Google Analytics session spans across two or more domains/subdomains and you want Google Analytics, to treat GA sessions across different domains/subdomain as a single session.

Your Google Analytics session can span across two or more domains in following scenarios:

#1 When your checkout process occurs on a different domain (quite common, when you use a third party shopping cart like shopify)

#2 When your goal conversions or ecommerce transactions take place on a different domain (quite common in case of affiliate websites).

 

Requirements for understanding and implementing Cross Domain Tracking

In order to understand and set up cross domain tracking, you first need to understand following terms:

#1 Google Analytics Cookies

#2 Client ID

#3 Domains and subdomains

#4 Cookie’s configurations

In cross domain tracking, we share cookie information between two or more domains. The domain can be a primary domain or subdomain.

The cookie information that we pass from one domain to another is the  client ID.

This client ID is stored in the Google Analytics cookie _ga.

The client ID behave according to the cookie’s configurations (cookie domain, cookie path and expiry date).

So before we are in the position to understand cross domain tracking, we need to first understand Google Analytics cookies,client ID and the concept of domains and subdomains.

 

Introduction to Google Analytics Cookies

In the context of Google Analytics, a cookie is a text file which is used to:

  1. Identify unique users
  2. Identify unique sessions
  3. Store information (like traffic source) about users’ GA sessions and campaigns.
  4. Throttle the request rate

There are two types of GA cookies:

#1 First Party GA Cookies – It is the GA cookie issued by the website being visited and only the website which issued the cookie can read it. Examples of first party GA cookies: _ga and _gat

#2 Third Party GA Cookies – It is the GA cookie issued by the website other than the website being visited. Example of third party GA cookies: doubleclick cookies.

 

Google Analytics uses cookies based on the JavaScript library being used.

#1 If you are using the classic Google Analytics, then you are using ga.js JavaScript library.

#1 If you are using the latest Google Analytics version (Universal Analytics) then, you are using analytics.js JavaScript library.

 

The ga.js javaScript library sets the following first party cookies:

  1. _utma (unique visitor cookie)
  2. _utmb (session cookie)
  3. _utmc (session cookie)
  4. _utmt
  5. _utmv (visitor segmentation cookie)
  6. _utmx (Google Analytics Content Experiment cookie)
  7. _utmz (Campaign cookie)

 

The analytics.js javaScript library sets following cookies:

#1  _ga cookie (it is used to identify unique users and it expires after 2 years).

#2  _gat cookie (it is used to throttle the request rate and it expires after 10 minutes).

#3 Doubleclick cookies (these are used when you use Google display advertising features like remarketing)

Google Analytics set up a cookie on your hard disk, as soon as you visit a webpage, on which a valid Google Analytics tracking code is installed.

 

Introduction to Client ID

When a user visit your website (say website A) for the first time, a unique ID is assigned to him called the ‘client ID’. This client ID is stored in the Google Analytics cookie _ga.

This ‘client ID’ is used to identify the user as new and unique and to combine all of his hits (pageviews, screenviews, events, transactions etc) together to form a GA session.

When the same user later, again visit your website, Google Analytics is able to identify the user as returning user through his client ID.

When the same user visit another website say website ‘B’ (which also has got GA installed), the GA tag of the website ‘B’ sets a completely different ‘Client ID’ for the user and thus the same user is treated as a different user by website B.

Since _ga cookie is a first party cookie, it can only be read by the website which issued it. Consequently,   _ga cookie set up by website ‘A’ can not (by default) be read/shared by website ‘B’ and vice versa.

Because of this reason, by default, cross domain tracking between two or more primary domains is not possible.

 

Also worth noting, that by default, cross web browsers tracking and cross device tracking is also not possible.

The _ga cookie can exist only on the device and browser where it has been set. Since client ID is stored in a GA cookie, the client ID will also exist only on the device and browser where it has been set. Because of this reason, by default, GA can’t identify unique users across different web browsers and devices.

So by default, cross web browsers tracking and cross device tracking is not possible.

Note: Client ID can be used to differentiate one _ga cookie from another. So if two _ga cookies have got same client ID then they are ost likely the same cookie.

 

Introduction to Domains

A Uniform Resource Locator (URL) is used to uniquely identify a web resource (like a web page) on the internet.

The URL is made up of internet protocol, internet hostname (also called domain name) and request URI (Uniform Request Identifier).

Following is an example of a URL:

https://www.optimizesmart.com/

Here,

https’ is the internet protocol.

www.optimizesmart.com’ is the internet host name or domain name

‘/’ is the request URI

Note: Technically speaking, ‘internet hostname’ can be different from a ‘network hostname’ as a network can be public (internet) or private (intranet). So hostname and domain name are not always the same thing.

That’s why i used the word ‘internet’, in ‘internet hostname’. However many web developers use the words ‘internet hostname’ and ‘hostname’ interchangeably, as they usually work on the internet and not on private networks.

 

A domain (also known as domain name) is a string which is used to uniquely identify a website on the internet.

A domain name is made up of two or more substrings separated by dot symbol ‘.’

Following is an example of a domain name:

www.optimizesmart.com

Here, ‘www’, ‘optimizesmart’ and ‘com’ are three substrings, each separated by a single dot symbol.

Each dot symbol represents one domain level.

The highest level domain is called the top level domain or TLD

For example, in the domain name www.optimizesmart.com

‘.com’ is the TLD

 

The top level domain can be generic, location specific or business/industry specific.

# Following are examples of generic TLDs: ‘.com’, ‘.net’, ‘.edu’, ‘.info’ etc

# Following are examples of location specific TLDs: ‘.uk’, ‘.fr’, ‘.de’, ‘.in’ etc

# Following are examples of business/industry specific TLDs: : ‘travel’, ‘tv’, ‘restaurant’ etc.

 

The second highest level domain is called the primary domain.

For example, in the domain name www.optimizesmart.com

‘Optimizesmart’ is the primary domain (without the ‘www’ prefix).

 

The third highest level domain is called the subdomain.

For example, in the domain name music.optimizesmart.com

music’ is the subdomain of the primary domain ‘optimizesmart’

 

The fourth highest level domain is called the sub subdomain.

For example, in the domain name asian.music.optimizesmart.com

asian’ is the sub subdomain of the primary domain ‘optimizesmart’

 

Note: Technically it is possible to create dozens of domain levels but i have never seen one being used on internet.

 

Introduction to Cookie Domain

In the context of Google Analytics, a cookie domain is the domain at which the Google Analytics cookie _ga is set up.

You can set up _ga cookie at a domain by simply installing Google Analytics tracking code on the domain.

 

Setting up Cookie domain

By default, Google Analytics cookie ‘_ga’ is set up at the second highest level domain of the current hostname of a web page.

The default Google Analytics tracking code (i.e. the code without any modification done to it), look like the one below:

<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’,’https://www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-XXXXX-YY’, ‘auto’);

ga(‘send’, ‘pageview’);

</script>

If you place the aforementioned Google Analytics Tracking code on a web page whose URL is say: http://music.abc.com/jazz

Then Google Analytics will set up ‘_ga’ cookie at ‘.abc.com’

In the URL: http://music.abc.com/jazz

#1 The current hostname is: ‘music.abc.com

#2 The request URI is: /jazz

#3 Top level domain (or TLD) is: ‘.com’. Google Analytics can not set up cookie at the TLD level.

#4 The second highest level domain (also called primary domain) is: ‘.abc.com’ (without the ‘www’ prefix). By default, Google Analytics setup cookie at this level.

#5 The third highest level domain (also called sub domain) is: ‘music.abc.com

 

Similarly, if you place the aforementioned Google Analytics Tracking code on a web page whose URL is say: http://asian.music.abc.com/

Then the second highest level domain of the current hostname (asian.music.abc.com) will still be ‘.abc.com’

Since by default, Google Analytics setup cookie at the second highest level domain of the current hostname, so the _ga cookie will be set at ‘.abc.com’

Now if you place the aforementioned Google Analytics Tracking code on a web page whose URL is say: http://www.abc.com/

Then also Google Analytics will set up ‘_ga’ cookie at ‘.abc.com’ as the second highest level domain of the current hostname (www.abc.com) is ‘abc.com

 

Automatic Cookie Domain Configuration

Now let’s look at the default Google Analytics tracking code (i.e. the code without any modification done to it) once again:

<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’,’https://www.google-analytics.com/analytics.js’,’ga’);

  ga(‘create’, ‘UA-XXXXX-YY’, ‘auto‘);

  ga(‘send’, ‘pageview’);

</script>

Note that ‘auto’ configuration parameter used in the tracking code.

This configuration parameter tells Google Analytics to automatically find the second highest level domain and always set the _ga cookie at the second highest level domain.

The advantage of setting up the _ga cookie at the second highest level domain (aka primary domain) is that, the client ID will always be shared among primary domain and its subdomains, whether a user navigates from primary domain to one of its subdomain or vice versa,  provided:

#1 both primary domain and its subdomains, use the same Google Analytics Tracking Code (in other words, use the same GA property ID)

#2 both primary domain and its subdomains use the ‘auto’ configuration parameter in their Google Analytics Tracking Code.

So by default, you don’t need to set up cross domain tracking between primary domains and its subdomains as cookie information is automatically shared between them, provided both primary domain and its subdomains, use the same Google Analytics Tracking Code and use the ‘auto’ configuration parameter in their Google Analytics Tracking Code.

 

Now, if we remove the ‘auto’ configuration parameter from our Google Analytics Tracking Code (GATC), then the tracking code will look like the one below:

<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’,’https://www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-XXXXX-YY’);

ga(‘send’, ‘pageview’);

</script>

Now since the ‘auto’ configuration parameter is missing from the tracking code, Google Analytics will not automatically find the second highest level domain and may not always set the _ga cookie at the second highest level domain.

What Google Analytics will now do is, set the _ga cookie at the current level domain, which may or may not be the second highest level domain.

So if the current level domain is the second highest level domain, then only _ga cookie will be set at the second highest level domain, otherwise not.

Without ‘auto’ configuration parameter there is no guarantee that the cookie information will always be shared among primary domain and its subdomains.

For example, if you use the Google Analytics tracking code without ‘auto’ configuration parameter on a web page whose URL is say: http://music.abc.com/jazz

Then Google Analytics will set up ‘_ga’ cookie at the current domain level which is  ‘.music.abc.com’ (instead of ‘.abc.com’, the second highest level domain).

You can share this _ga cookie with subdomains of ‘.music.abc.com’ like ‘asian.music.abc.com’

However you won’t able to share the ‘_ga’ cookie set up at  ‘music.abc.com’ with a higher level domain like ‘abc.com

So what will happen, when a user navigates from ‘music.abc.com’ to a higher level domain like ‘abc.com’, the client ID won’t pass from ‘music.abc.com’ to ‘abc.com’ and hence a new GA session will start and same user will be counted as a different user on the ‘abc.com’ website. In other words, cross domain tracking won’t work.

Now, when you use the Google Analytics tracking code without ‘auto’ configuration parameter on a web page whose URL is: http://www.abc.com/

Then Google Analytics will set up ‘_ga’ cookie at the current domain level which is now ‘.abc.com’ and you can share this cookie with all of the subdomains like music.abc.com.

So what will happen, when a user navigates from ‘abc.com’ to a lower level domain like ‘music.abc.com’, the client ID will pass from ‘abc.com’ to ‘music.abc.com’ and hence no new GA session will start and same user will not be counted as different user on the ‘music.abc.com’ website. In other words, cross domain tracking will work.

So what we can conclude that, if the ‘auto’ configuration parameter is missing from the Google Analytics tracking code, the client ID will be shared among primary domain and its subdomains, only when a user navigates from primary domain to one of its subdomain and both primary domain and its subdomain, use the same Google Analytics Tracking Code.

But when the same user navigates back from the subdomain to its primary domain, the client ID will not be shared and hence new GA session will start and the same user will be counted as two different users.

 

Similarly, if you use the Google Analytics tracking code without ‘auto’ configuration parameter on a web page whose URL is say: http://games.abc.com/

Then Google Analytics will set up ‘_ga’ cookie at the current domain level which is now ‘.games.abc.com’.

You can share the ‘_ga’ cookie set up at  ‘.games.abc.com’ with its subdomain like ‘a1.games.abc.com’ but not with any higher level domain like ‘.abc.com’ or same level domain like ‘music.abc.com

So what will happen, when a user navigates from ‘games.abc.com’ to a same level domain like ‘music.abc.com’, the client ID will not pass from ‘games.abc.com’ to ‘music.abc.com’ and hence new GA session will start and same user will be counted as different user on the ‘music.abc.com’ website. In other words, cross domain tracking will not work between two subdomains.

So if you want to make sure that cookie information is always passed whether a user navigate from primary domain to its subdomain and vice versa or whether a user navigates back and forth between two or more subdomains, then use the ‘auto’ configuration parameter in your Google Analytics Tracking Code.

 

Cookie domain needs to be the ancestor of the destination domain(s)

Cookie domain is the domain at which a Google Analytics cookie is set up.

Destination domain(s) is the domain to which you want to pass the client ID.

If you wish to set up cross domain tracking in Google Analytics, then always make sure that the cookie domain is the ancestor of the destination domain(s).

A primary domain is always the ancestor of its subdomain(s).

So, if you wish to set up cross domain tracking between a primary domain like www.abc.com and its subdomain like music.abc.com then set up _ga cookie at the ‘.abc.com’ domain as it is the ancestor of ‘music.abc.com’ subdomain.

You can set up _ga cookie at the ‘.abc.com’ domain by adding following line of code in the Google Analytics tracking code meant for www.abc.com and music.abc.com:

ga(‘create’, ‘UA-12345-1’, {‘cookieDomain’: ‘.abc.com’});

Similarly, if you wish to set up cross domain tracking between music.abc.com and asian.music.abc.com then set up _ga cookie either at the ‘music.abc.com’ domain or ‘.abc.com’ domain as both are ancestor of ‘asian.music.abc.com’ subdomain.

If you wish to set up cross domain tracking between two subdomains like music.abc.com and games.abc.com then set up _ga cookie at the primary domain ‘.abc.com’ as it is the ancestor of both ‘music.abc.com’ and games.abc.com subdomains.

 

Introduction to Cookie Path

Cookie Path is the path at which the cookie is set up.

By default the _ga cookie is set on the second highest level domain with the root level (/) path. Because of that reason, the cookie set up at the primary domain level , can be shared with all of its web pages and subdirectories.

But if for some reason, you want the _ga cookie set up at the primary domain level to be shared only with a particular subdirectory, then you can do that, by using the ‘cookiePath’ configuration parameter.

For example, let us suppose you want the _ga cookie set up at www.abc.com to be shared only with one of its subdirectory named ‘gin’. To do that, set the ‘cookiePath‘ field to ‘/gin/’:

ga(‘create’, ‘UA-XXXX-Y’, {‘cookiePath’: ‘/gin/’});

Then add this line of code in the Google Analytics Tracking Code meant for www.abc.com:

<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’,’https://www.google-analytics.com/analytics.js’,’ga’);

  ga(‘create’, ‘UA-XXXX-Y’, {‘cookiePath’: ‘/gin/’});

  ga(‘send’, ‘pageview’);

</script>

 

Introduction to Cookie Expires

Cookie Expires is the time in seconds, after which the _ga cookie will expire.

By default _ga cookie expires after 2 years from the date it was last refreshed.

Every time a new hit is sent to google analytics, the _ga cookie is refreshed.

You can set your own cookie expiration time by using the cookieExpires field:

ga(‘create’, ‘UA-XXXX-Y’, {‘cookieExpires’: 180});

Here we set the _ga cookie to expire after 2 minutes.

The cookie expires, play an important role in cross domain tracking.

For example if the _ga cookie expires after 2 minutes, then the same user can be treated as new user by Google Analytics even before he navigates to a different domain.

 

Referral exclusion list

A referral exclusion list is the list of domains whose incoming traffic will be treated as direct traffic (instead of referral traffic) by Google Analytics.

Direct traffic is a web session (or visit) which starts without a referrer being passed by a user’s browser.

By default all referrals trigger a new web session in Google Analytics.

This can affect the total number of web sessions in your analytics reports.

For example: let us suppose a user started his journey (GA session) on www.xyz.com website.

He then navigates to www.abc.com website from xyz website. As soon as the user arrived on the abc website, he will be treated as a new user (as client ID is not shared across domains by default) and his existing GA session (with xyz website) will continue but a new GA session (with abc website) will start.

When the user navigates back to xyz website from abc website, his existing GA session (with abc website) will continue and a new GA session (with xyz website) will start.

Now, if you do not want the new GA session to be triggered for abc website, when the user navigates from xyz website to abc website then you need to add the domain xyz.com in the referral exclusion list of the GA view meant for abc website.

Similarly, if you do not want the new GA session to be triggered for xyz website, when the user navigates from abc website to xyz website then you need to add the domain abc.com in the referral exclusion list of the GA view meant for xyz website.

 

Implementing tracking across primary domain and its sub-domains

Follow the steps below to track across primary domain (say abc.com) and its sub-domains (say music.abc.com and games.abc.com):

Step-1: Use the Google Analytics tracking code meant for the primary domain on all of the web pages of the sub-domains.

Step-2: In the Google Analytics view of the primary domain (abc.com) add ‘abc.com’ in the referral exclusion list so that it automatically put all the subdomains of abc.com in the referral exclusion list.

Step-3: In the Google Analytics view of the sub-domain: ‘music.abc.com’, add ‘abc.com’ in the referral exclusion list.

Step-4: In the Google Analytics view of the sub-domain: ‘games.abc.com’, add ‘abc.com’ in the referral exclusion list.

 

Requirements for setting up cross domain tracking between primary domains

Before you can implement cross domain tracking between two or more primary domains, you need to get familiar with following concepts:

  1. Cross Domain Links
  2. allowLinker
  3. autoLink plugin
  4. linker:autoLink Command
  5. Linker Parameter
  6. Decorating links

 

Introduction to ‘Cross Domain Links’

Cross domain link is the hyperlink which can move the traffic from one domain to another.

In cross domain tracking, a user’s client ID is passed from one domain to another via cross domain links and/or via form submission.

For example if you have set up cross domain tracking between abc.com and xyz.com then all the links on abc.com that go to xyz.com and all the links on xyz.com that go to abc.com, are called cross domain links.

Cross domain traffic is the traffic which moves back and forth between different domains via cross domain links.

The cookie information (Client ID) is attached to the query string of the cross domain links which you can see in the browser window:

client id

Google Analytics tag is designed to look for client ID in the query string and use it if it exist. So if a user has got same client ID across two or more domains than Google Analytics can identify the user across multiple domains.

In order to track a user across domains, you need to share users’ cookie information (Client ID) among domains. The easiest way to do that is by using the autoLink plugin

 

Introduction to ‘allowLinker’

‘allowLinker’ is a tracker configuration parameter which must be set to true to allow a domain to pass / accept client ID.

In case of cross domain tracking we have got two categories of primary domains:

1) Source domain

2) Destination domain(s)

The default value for allowLinker is ‘false’. So by default:

#1 A source domain is not allowed to pass the client ID to the destination domain.

#2 A destination domain is not allowed to accept the client ID from the source domain.

You can set up cross domain tracking between a source domain and a destination domain only when the following two conditions are met:

#1 The source domain is allowed to pass the client ID to the destination domain.

#2 The destination domain is allowed to accept the client ID from the source domain.

 

#FAQ: How you can allow the source domain to pass client ID to the destination domain?

Add following line of code in the GATC (Google Analytics Tracking Code) of the source domain:

ga(‘create’, ‘UA-XXXXX-YY’, ‘auto’,{‘allowLinker’: true }); // allow source domain to pass cookie information

So final code may look like the one below:

 <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-1556844-26‘, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

.

.

ga(‘send’, ‘pageview’);

</script>

 

#FAQ: How you can allow the destination domain to accept client ID from the source domain?

Add following line of code in the GATC of the destination domain:

ga(‘create’, ‘UA-XXXX-YY’, ‘auto’,{‘allowLinker’: true }); // allow destination domain to accept cookie information.

 So final code may look like the one below:

<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-1556844-27‘, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

.

.

ga(‘send’, ‘pageview’);

</script>

 

Introduction to ‘autoLink’ Plugin

autoLink plugin is a Google Analytics plugin which is used to share client ID among two or more primary domains.

This plugin provides the easiest way to implement cross domain tracking in Google Analytics. Google recommends implementing cross domain tracking via autoLink plugin.

You can also implement cross domain tracking without using this plugin i.e. manually, but it is more prone to errors.

The word ‘autoLink’ means ‘automatic linking’.

This plugin automatically implements cross domain linking (not to be confused with the word ‘cross domain tracking’) between two or more primary domains.

In order to set up this plugin, you need to add the plugin code to your Google Analytics tracking code.

Following line of code is used to load the ‘autoLink’ plugin:

 ga(‘require’, ‘linker’);

You need to add this line of code to the Google Analytics tracking code of both your source and destination domains.

So final Google Analytics tracking code for the source domain may look like the one below:

<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-1556844-26‘, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

.

ga(‘send’, ‘pageview’);

</script>

Similarly, the final Google Analytics tracking code for the destination domain may look like the one below:

<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-1556844-27‘, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

.

ga(‘send’, ‘pageview’);

</script>

 

#FAQ: Is it required to setup the autolink plugin on the destination domain(s)?

No it is not required but you should, in order to implement bi-directional cross domain tracking. So that you can track traffic from Website A going to Website B and vice versa.

Note: It is possible for your website pages to block the ‘autoLink plugin’ from working or working correctly. So test the plugin on one page before implementing it site wide.

 

Introduction to ‘linker:autoLink’ Command

The purpose of linker:autoLink command is to define the domain(s) that need to be automatically cross linked.

In GA lingo, ‘automatically cross linked’ is known as ‘auto linked’.

There are two methods through which you can define the domains that need to be automatically cross linked, while setting up the autoLink plugin:

1) by using array of domain substrings.

2) by using array of domain regular expressions.

 

Array of domain substrings

Following are examples of array of domain substrings:

#1 [‘destination.com’]

#2 [‘destination1.com’, ‘destination2.com’]

#3 [‘destination1.com’, ‘destination2.com’,’destination3.com’]

Here ‘destination.com’, ‘destination1.com’, ‘destination2.com’, ‘destination3.com’ are the domains that need to be auto linked.

For example:

ga(‘linker:autoLink’, [‘xyz.com’]); => autolink the source domain with ‘xyz.com’ destination domain.

ga(‘linker:autoLink’, [‘xyz.com’, ‘pqr.com’]); => autolink the source domain with ‘xyz.com’ and ‘pqr.com’ destination domains.

ga(‘linker:autoLink’, [‘xyz.com’, ‘pqr.com’,’drt.net’]); => autolink the source domain with ‘xyz.com’, ‘pqr.com’ and ‘drt.net’ destination domains.

 

Array of domain regular expressions

Following is an example of array of domain regular expression:

[/^example\.(com|net)$/]

Here example.com and example.net are the domains that need to be auto linked.

For example:

ga(‘linker:autoLink’, [/^example\.(com|net)$/]);

If www.xyz.com is your source domain and www.pqr.com is your destination domain and you want to set up cross domain tracking between the two domains, then your Google Analytics tracking code for the source domain may look like the one below:

<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-1556844-26‘, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

ga(‘linker:autoLink’, [‘pqr.com’]);

ga(‘send’, ‘pageview’);

</script>

Similarly, your Google Analytics tracking code for the destination domain (pqr.com) may look like the one below:

<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-1556844-27‘, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

ga(‘linker:autoLink’, [‘xyz.com’]);

ga(‘send’, ‘pageview’);

</script>

 

Introduction to Linker Parameter

A linker parameter is a query parameter which is attached to a cross domain link, once it is clicked.

For example in the following destination domain URL:

https://www.destination-1.com/productA.php?_ga=1.153530484435.69385205830.8479429413352

Here the linker parameter is: _ga=1.153530484435.69385205830.8479429413352

 

Introduction to Decorating Links

Decorating a link means adding linker parameter to the link.

Following is an example of an undecorated link:

https://www.destination-1.com/productA.php

Following is an example of a decorated link:

https://www.destination-1.com/productA.php?_ga=1.153530484435.69385205830.8479429413352

Note: You can decorate links manually or through autolink plugin. 

 

Cross domain tracking Code

The cross domain tracking code in Google Analytics is made up of:

#1 ‘allowLinker’ tracker configuration parameter

#2  ‘autoLink’ Plugin

#3 ‘linker:autoLink’ Command

Following is an example of cross domain tracking code in GA:

ga(‘create’, ‘UA-1556844-27’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

ga(‘linker:autoLink’, [‘xyz.com’]);

This cross domain tracking code is added to the Google Analytics tracking code of the source and destination domains.

 

Implementing cross domain tracking between two primary domains

The fundamental requirement for tracking across primary domains is that, you need to share client ID with the destination domain and the destination domain must give permission to do that.

For the purpose of giving an example, let us suppose, we need to set up cross domain tracking between xyz.com and pqr.com, where xyz.com is the source domain and pqr.com is the destination domain.

Follow the steps below, to track across two primary domains:

Step-1: In the GA view of xyz.com, go to Admin > Property > Tracking Info > Referral exclusion list. Add ‘xyz.com’ and ‘pqr.com’ in the ‘referral exclusion’ list. xyz.com is added to avoid self referral issues

Step-2: In the GA view of pqr.com, go to Admin > Property > Tracking Info > Referral exclusion list. Add ‘pqr.com’  and ‘xyz.com’ in the ‘referral exclusion’ list. pqr.com is added to avoid self referral issues.

Step-3: Create cross domain tracking code for your source domain (xyz.com) according to your understanding of:

#1 ‘allowLinker’ tracker configuration parameter

#2  ‘autoLink’ Plugin

#3 ‘linker:autoLink’ Command

The cross domain tracking code for your source domain (xyz.com), may look like the one below:

ga(‘create’, ‘UA-1556844-26’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

 ga(‘linker:autoLink’, [‘pqr.com’]); // auto link to pqr website

 

Step-4: Create cross domain tracking code for your destination domain (pqr.com)

ga(‘create’, ‘UA-1556844-76’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup linker plugin

 ga(‘linker:autoLink’, [‘xyz.com’]); // link to xyz website

Step-5: Add the cross domain tracking code meant for your source domain (xyz.com) to the Google Analytics tracking code of your source domain (xyz.com). For example:

<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-1556844-26’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

 ga(‘linker:autoLink’, [‘pqr.com’]); // auto link to pqr website

ga(‘send’, ‘pageview’);

</script>

 

Step-6: Add the cross domain tracking code meant for your destination domain (pqr.com) to the Google Analytics tracking code of your destination domain (pqr.com).

For example:

<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-1556844-76’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup linker plugin

 ga(‘linker:autoLink’, [‘xyz.com’]); // link to xyz website

ga(‘send’, ‘pageview’);

</script>

 

Implementing cross domain tracking between three primary domains

If you want to set up cross domain tracking between 3 primary domains say: abc.com, xyz.com and pqr.com then follow the steps below:

Step-1: In the GA view of abc.com, go to Admin > Property > Tracking Info > Referral exclusion list. Add ‘abc.com’, ‘xyz.com’ and ‘pqr.com’ in the ‘referral exclusion’ list.

Step-2: In the GA view of xyz.com, go to Admin > Property > Tracking Info > Referral exclusion list. Add ‘abc.com’, ‘xyz.com’ and ‘pqr.com’ in the ‘referral exclusion’ list.

Step-3: In the GA view of pqr.com, go to Admin > Property > Tracking Info > Referral exclusion list. Add ‘abc.com’, ‘xyz.com’ and ‘pqr.com’ in the ‘referral exclusion’ list.

Step-4: Create cross domain tracking code for the domain abc.com .This code may look like the one below:

ga(‘create’, ‘UA-1556844-25’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

 ga(‘linker:autoLink’, [‘xyz.com’,’pqr.com’]); // auto link to ‘xyz’ and ‘pqr’ websites.

 

Step-5: Create cross domain tracking code for the domain xyz.com. This code may look like the one below:

ga(‘create’, ‘UA-1556844-26’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

 ga(‘linker:autoLink’, [‘abc.com’,’pqr.com’]); // auto link to ‘abc’ and ‘pqr’ websites.

 

Step-6: Create cross domain tracking for the domain pqr.com. This code may look like the one below:

ga(‘create’, ‘UA-1556844-27’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

 ga(‘linker:autoLink’, [‘abc.com’,’xyz.com’]); // auto link to ‘abc’ and ‘xyz’ websites.

 

Step-7: Add the cross domain tracking code meant for the domain abc.com to the Google Analytics tracking code of the domain abc.com. For example:

<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-1556844-25’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

 ga(‘linker:autoLink’, [‘xyz.com’,’pqr.com’]); // auto link to ‘xyz’ and ‘pqr’ websites.

ga(‘send’, ‘pageview’);

</script>

 

Step-8: Add the cross domain tracking code meant for the domain xyz.com to the Google Analytics tracking code of the domain xyz.com. For example:

<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-1556844-26’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

 ga(‘linker:autoLink’, [‘abc.com’,’pqr.com’]); // auto link to ‘abc’ and ‘pqr’ websites.

ga(‘send’, ‘pageview’);

</script>

 

Step-9: Add the cross domain tracking code meant for the domain pqr.com to the Google Analytics tracking code of the domain pqr.com. For example:

<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-1556844-27’, ‘auto’,{‘allowLinker’: true }); // set allowLinker to true

 ga(‘require’, ‘linker’); // setup autoLink plugin

 ga(‘linker:autoLink’, [‘abc.com’,’xyz.com’]); // auto link to ‘abc’ and ‘xyz’ websites.

ga(‘send’, ‘pageview’);

</script>

 

Tracking across top level domains

Top level domain (or TLD) is the last part of the domain name. For example, in the domain name www.abc.com, the top level domain is ‘com’. Similalrly, in the domain name www.abc.org , the top level domain is ‘org’

Tracking across top level domains is similar to tracking across different primary domains.

 

Using same Google Analytics  tracking code on multiple primary domains for cross domain tracking

Wouldn’t it be easy to track across multiple primary domains, just by using the same GA tracking code on all of the primary domains?

Yes that would be the easiest solution but it comes with its own set of critical issues which can not be fixed:

Issue #1: Self referrals – expect significant level of self referral issues in your GA reports if you used same GA tracking code on multiple websites. Even if you exclude all of the domains that are part of the cross domain tracking setup, from referral traffic (via referral exclusion list), it will still not fix your problem.

Then Google Analytics will treat the self referral traffic as direct traffic. So you could then end up, with abnormally large amount of direct traffic in your GA reports.

Issue #2: Inaccurate data – significant level of self referral issues would greatly skew your analytics data and any decision based on inaccurate data can not produce optimum results. Since by default all referrals trigger a new web session in Google analytics, expect inflated sessions data.

Issues #3: Attribution issues – you may have a hard time determining the original source of your conversions and/or ecommerce transaction. Majority of your conversions could end up being attributed to direct traffic or your own website (self referral).

 

Cross domain tracking and rollup reporting

Cross domain tracking and rollup reporting are not the same thing. Just because you have implemented cross domain tracking, does not mean that you will automatically see the cross domain traffic data in your GA reports.

Rollup reporting is the reporting of data in aggregated form from multiple digital properties (websites, mobile apps).

For example, if you have setup separate websites for each country then through rollup reporting, you can aggregate all of your websites data in one view and see aggregated global performance metrics and/or compare the performance of various country specific websites to each other.

In Google Analytics, a website or mobile application is called a property (also known as web property or digital property). Each property is identified by a unique ID known as property ID (or tracking ID).

This tracking ID is in the format: UA-XXXX-YY

For example: UA-1235-21

Each property contains one or more views and each view contain multiple reports:

properties and views

A roll up property is the web property whose hit data comes from other Google Analytics properties.

google-analytics-rollup-property

If you have implemented rollup reporting then with the help of multiple trackers you can get cross domain traffic in your roll up property:

crossDomainTracking

This is a bit advanced cross domain tracking set up, which I explained in great detail in this article: Understanding trackers in Google Analytics

To learn more about roll up reporting, read this article: Implementing rollup reporting in Google Analytics

Announcement about my new books

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Himanshu Sharma

Certified web analyst and founder of OptimizeSmart.com

My name is Himanshu Sharma and I help businesses find and fix their Google Analytics and conversion issues. If you have any questions or comments please contact me.

  • Over eleven years' experience in SEO, PPC and web analytics
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of OptimizeSmart.com and EventEducation.com

I am also the author of three books:

error: Content is protected !!