Analytics and Search Marketing Tips

2 Simple Steps to Cross Domain Tracking in Universal Analytics

2 Simple Steps to Cross Domain Tracking in Universal Analytics

November 24, 2014           Analytics, Google Analytics

Cross domain tracking has been one of those thorns in Google Analytics implementations. Although, it isn’t technically that complicated, there are many things that can (and usually do) go wrong.

For most implementations, it isn’t much of a problem once the initial implementation is figured out. However, for the larger enterprise level companies with an expanding number of websites, it can get to be one of those persistent thorns you have to keep an eye out for.

Fortunately, Google’s Universal Analytics simplifies the setup process, and we’ve provided some valuable tips in this article that will help you solve common needs and avoid typical issues.

Why is Cross Domain Tracking Important?

In case you aren’t familiar with cross domain tracking, it’s mainly used when you have scenarios where people are moving between domains, and it’s important for the session (and visitor identification) to be retained. This is especially true when you have a website with a checkout process hosted on a separate or secured domain.

If your Goals or Conversions take place on the separate domain, you will lose traffic attribution data unless your implementation is configured properly for cross-domain tracking. The adverse impact on your reports is that they will show most all conversions tied to either direct traffic or the domain itself (which is considered a self-referral).

I’m pretty sure tracking the source of your conversions is vital, so you can evaluate the effectiveness of your marketing campaigns. So let’s talk about how to fix this.

Two Step Process for Cross Domain Tracking in UA

Universal Analytics, along with all the wonderful new features has truly simplified this process. It’s down to a simple 2 step process:

STEP #1: Exclude Self Referrals

You need to configure your Google Analytics property to ignore the domains you are looking to track across within the admin section of the Google Analytics web interface under “Tracking Info > Referral Exclusion List”.

On the Referral Exclusion List page, click the ‘+ Add Referral Exclusion’ button and add your origination domain (e.g. maindomain.com) and target domain (e.g. targetdomain.com) to the list (as shown below).

2014-10-10_16-50-29

STEP #2: Modify Tracking Code

Make the following changes to your Google Universal Analytics Tracking Code:

  • Set “allowLinker” to true on the domains involved (shown in line 6 of sample code below)
  • Add a line of code to include a “linker” plugin (shown in line 8 of sample code below)
  • Set the “linker” to “autoLink” and provide an array with all of the domain names to cross domain to (shown in line 9 of sample code below)

Sample Code

To help you further, here’s some sample Google Universal Analytics code to serve as a reference for our provided cross domain tracking changes. Feel free to grab and use as you desire:

 
(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-XXXXXXXX-X', 'auto', {'allowLinker': true });

  ga('require', 'linker');
  ga('linker:autoLink', ['maindomain.com','targetdomain.com']);

  ga('send', 'pageview');

Code Option 1: Hash/Anchor

As an option, if you want to have the autolinker use a hash/anchor (#) instead of passing the cookie info as a query, modify the linker:autolink line of code by adding a “true” at the end like this (Note: In this configuration, you don’t have to set allowAnchor for cross-domain to get this working):

 ga('linker:autoLink', ['maindomain.com','targetdomain.com'], true);

Code Option 2: Add Form Support

If you want your forms to handle cross domain linking, modify the linker:autolink line of code (which is line 8 in the Sample Code above) by adding another “true” parameter as shown below:

 ga('linker:autoLink', ['maindomain.com','targetdomain.com'], true, true); 

Caveat Emptor

Last thing, a bit of a warning. This may not work on pages with particular methods of linking. More specifically, it would not work if:

  • your site has JavaScript within the href of the link to load the link, instead of a clean URL (example below)
    <a id="ApplyButton" class="apply top" href="javascript:doSomething();">apply</a>
  • you have an element with an “onclick” attribute, the URL specified in the onclick (example below)
    <a id="ApplyButton" class="apply top" href="#" onclick="doSomething()">apply</a>

In either situation, the doSomething() function will probably have a return false or preventDefault() to keep the anchor from working normally. The function will do something and then redirect the page to the desired URL. You’ll need to modify your doSomething() function to use a decorated URL. See the “Decorate Utility Method” on the Google Developers pages.

Finally, you’ll want to be aware of the following:

  • If you are migrating from Classic Google Analytics to Universal, don’t be alarmed when you don’t see those __utm* parameters after the cross domain jump. Google has simplified this so that you’ll now see a single querystring parameter named ‘_ga’.
  • By using the linker param via autoLink or the other methods that Google provides, you’ll solve another issue that is created when a user shares the link with the cross-domain parameter with a friend. The friend can show up as the same user as the original user which causes interesting issues in data quality. Google fixes this by placing a hashed timestamp in the _ga parameter that expires after 2 minutes.

Now sit back and reminisce with a smile about the times when you had to worry about creating a JavaScript or jQuery script to capture anchor links leading to the domains and how there was always that one link or two that would fail to work. Cheers to all of those Google Analytics Implementation specialists who share the pain of the old way of doing things and are jumping for joy at the beauty of the new method. Thanks Google!

If you have questions or comments, we encourage you to post below. If you’d like even more details on cross domain tracking, the Google Analytics team does a great job in documenting all of the capabilities of Cross Domain Tracking.

 


Share this Post

  • Yaser Arshad

    great post.. looking forward to more of your posts

  • amme john

    Its really amazing Post. Thanks

  • Miguel Moreink

    Olaf, I’ve been trying to set up cross domain tracking for my website, which uses a booking engine on a different domain.

    It’s all set up via Google Tag Manager, and it seems to be working fine, since I can track the presence of the user on both domains, via my Google Analytics account.

    However, and I check it by following my dummy-visit through GA’s Real-Time, once the user jumps from the first to the second domain, the info on the Source/Medium is lost (eg. from ‘google/organic’ to ‘(direct) / (not-set)’).

    How can I keep all the info intact, cross-domain? Is this a common problem?

    Thanks!

  • Jon Ward

    Did you ever figure this out? I’m having the same issue.

  • Victoria Percival

    Thanks Olaf – does the same code need to be added to both the main and target sites? Also, will this code track a form submission (e.g. main site sends user to target site, they then complete a form) – will the main site receive this information?

  • Hi Olaf –

    What’s your take on using separate properties/accounts for each domain of a cross domain project, vs using a shared id across the domains, vs doing both in a rollup?

  • Best way to track the conversion source, want some more post like this. Looking forward to read more.

  • jacksoggetto

    I get to understand that you need to to put the example code in the main website (apyment website where I have the secure tracking). But on the other website (that one that sends the clients to the secure website) what shall I do?
    The main question want to be:
    is te UA-XXXXXXXX-X the same for both websites?

  • romeobagga

    thanks for post, i have successfully done the setup.

    but how i can check the traffic to each domain ? i mean how many visits to a particular domain

  • Utpal

    i have tow template for indexing . i,default and ii,fb

    default is indexing everytime but i want to index fb template when user come from facebook. Have any way for this .

  • Stefania

    Hi, I set up the cross domain but I have a problem, GA doesn’t link the visit on the site1 with the site on the site2. Actually the user arrives to the site1 by facebook ads and makes a lead generation, and then, by a dem, arrives to site2 and makes the conversion.
    I can see the lead generation and the conversion but GA doesn’t link the two sessions so I can’t see the first touch point of the final conversion.
    What could I do? Implementing something ID user track?
    Thanks,
    Stefania Vichi

 

Digital Analytics Blog

We're here to help with tips and insight on the following topics:

Subscribe to RSS


Optimize your website and marketing campaigns

Get a constant flow of Google Analytics help and digital marketing tips, case studies and more from Google Certified Partner Blast Analytics & Marketing.




Connect with Blast Analytics & Marketing