Tracking Google Analytics Linking Across Domains
3 min read

Tracking Google Analytics Linking Across Domains

Tracking Google Analytics Linking Across Domains
Photo by JOHN TOWNER / Unsplash

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 “,”.

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

Example of Multiple Root Domains (two different domains)

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(“”);

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

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);

OLD CODE (urchin.js)
-> _udn=”none”
-> _ulink=1;

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

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

Example old urchin.js :
.. href=””> 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=”” onSubmit=”javascript:pageTracker._linkByPost(this)”

Example old urchin.js :
.. action=”” 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

Join many curious data-driven marketers who grow with us each week

Great! Check your inbox and click the link.
Sorry, something went wrong. Please try again.