Photo by JOHN TOWNER / Unsplash

Tracking Google Analytics Linking Across Domains

Kris
Kris

Table of Contents

The best approach in my view to track cross domain is to use Google Tag Manager and save yourself some time and headache to manage any future changes to your Google Analytics tracking set up.

Here are the steps you need to take.

Step 1:  Set Auto Link Domains Variable

In GTM, create a custom variable where variable type is constant, with a value set to list of domains that you want to track across.  If you have multiple domains, just set it to like “abc.com, xyz.com”.

Google Tag Manager Auto Link Domains

Step 2: Add Auto Link Domains to Pageview tag and set Allow Linker

Now that you have a constant variable Auto Link Domains, you’ll have to assign that to Page View tag for GA.  It is highlighted in below image.

Now, you’ll have to make sure the allowLinker field is set to “true”.

This set up essentially tells GA which domains to cross track.

Google Tag Manager Allow Linker

Step 3:  Update the Referral Exclusion List

In this step, under the admin panel in property, you’ll have to make sure to set the list of domains you own so that the new sessions are generated each time user go across domains.  By setting up the exclusions, you’ll telling GA to keep the original session, so the referring source/medium persists.

Google Analytics Referral Exclusion List

-- Legacy ga.js tracking below --

There are two ways in approaching tracking the website across multiple domains using Google Analytics. First, note the difference between “multiple subdomains” and “multiple root domains”.

Example of Multiple Subdomains
www.example_site.com
and
blog.example_site.com

Example of Multiple Root Domains (two different domains)
www.example_site.com
and
www.example_store.com

How to track the subdomains of the website in one profile

1) You can track subdomains within the same profile as the domain by adding an extra line into your tracking code (in bold).


NEW CODE (ga.js)
var pageTracker = _gat._getTracker(“UA-xxxxxx-x”);
-> pageTracker._setDomainName(“example_site.com”);
pageTracker._initData();

OLD CODE (urchin.js)
_uacct = “UA-xxxx-x”
-> _udn=”example_site.com”;
urchinTracker();

Keep in mind that this will allow you to track subdomains within one profile, but you may not be able to distinguish between pages coming from the main domain versus the subdomain.

2) If you need to distinguish between the subdomains, advanced filter for your profile needs to be set.

For Example:

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

How to track the site across multiple domains

1) You need to add the following lines (in bold) to your Google Analytics tracking code.

NEW CODE (ga.js)
var pageTracker = _gat._getTracker(“UA-12345-1”);
-> pageTracker._setDomainName(“none”);
-> pageTracker._setAllowLinker(true);
pageTracker._initData();

OLD CODE (urchin.js)
_uacct=”UA-xxxx-x”
-> _udn=”none”
-> _ulink=1;
urchinTracker();

2) Next, you will need to add the _link function to any links between the domains.

Example for new ga.js :
.. href=”http://www.example_store.com”> onclick=”pageTracker._link(this.href); return false;”…

Example old urchin.js :
.. href=”http://www.example_store.com”> onclick=”javascript:__utmLinker(this.href); return false;”…

3) If you send information between domains using forms, you’ll need to apply the following.

Example for new ga.js :
.. action=”http://newdomain.com/form.cgi” onSubmit=”javascript:pageTracker._linkByPost(this)”

Example old urchin.js :
.. action=”http://newdomain.com/form.cgi” onSubmit=”javascript:__utmLinkPost(this)”

4) The data in the report will only include the request URI and not the domain name. If you want to see the domain names, then you need to create an Advanced filter for your profile.

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

Analytics

Kris

As a data journalist, I enjoy curating and analyzing marketing trends, and data. The things that fascinate me the most are the transforming business landscape due to evolving marketing technologies.