What is cross-domain tracking and why do you need to implement in your Google Analytics account?

Cross-domain tracking makes it possible for Analytics to see sessions on two related sites (such as an ecommerce site and a separate shopping cart site) as a single session. This is sometimes called site linking.

Cross-domain literally means that you are able to see a user in a single Google Analytics account in his journey across multiple domains that you control (e.g. mysite.com and myshoppingcart.com).

In the standard configuration of the Google Analytics script, every time a customer loads a page on a different domain a new session is generated, even if the branding looks seamless to the user and, unfortunately, the previous session has ended and this is even if the customer is still active and generates events and page views. Until you have implemented the cross-domain setting on your website you will not be able to have an accurate customer journey.

Why? Let’s take, for example, a standard website, www.siteA.com, and it’s blog, www.blogB.com.

To track sessions, Analytics collects a client ID value in every hit. Client ID values are stored in 1st party cookies, and these cookies are only available to web pages on the same domain. When tracking sessions across multiple domains, the client ID value has to be transferred from one domain to the other. To do this, the Analytics tracking code has linking features that allow the source domain to place the client ID in the link URL, where the destination domain can access it.

Fortunately, with the release of Universal Analytics cross-domain tracking, it is easier to implement, and especially so with Google Tag Manager.

Setting up cross-domain tracking using Google Tag Manager

  1. Add (or edit your existing) a basic page tracking tag (i.e. Tag Type = Universal Analytics; Track Type = Page View).
  2. If you are using the same container for siteA.com and blogB.com, under More Settings → Fields to Set, enter the following:
    Field Name: allowLinker
    Value: true
    Cross domain using GTM
  3. Under More settings → Cross-Domain Tracking → Auto Link Domains enter “blogB.com” (without the quotes).
    If you have multiple domains, separate them by commas: blogB.com, siteC.com
    Cross domain settings in GTM
  4. Leave the ‘Use hash as delimiter’ and ‘Decorate forms’ unless you have an unusual web setup.
  5. Set the trigger to “All Pages”.
  6. Save a version of the container and publish it.
  7. If you are using a separate container for blogB.com, repeat the steps above but in the Auto Link Domains field add: siteA.com
  8. Add both domains to the Referral Exclusion List

When a user journey crosses from your first domain to your second domain, it will still appear as a new session in Google Analytics by default. If you want to be able to track a single session across multiple domains, you need to add your domains to the referral exclusion list.

Here’s an example Tag Assistant Recordings report that shows what it looks like when cross-domain tracking is not setup properly.

Setting up cross-domain tracking by directly modifying the tracking code

To set up cross-domain tracking for multiple top-level domains, you need to modify the Google Analytics tracking code on each domain. You should have basic knowledge of HTML and JavaScript or work with a developer to set up cross-domain tracking. The examples in this article use the Universal Analytics tracking code snippet (analytics.js).

Editing the tracking code for the primary domain

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});
ga(‘require’, ‘linker’);
ga(‘linker:autoLink’, [‘siteB.com’] );

Remember to replace the example tracking ID (UA-XXXXXX-Y) with your own tracking ID, and replace the example autoLink domain (siteB.com) with your own secondary domain name.

Editing the tracking code on the secondary domain

ga(‘create’, ‘UA-XXXXXXX-Y’, ‘auto’, {‘allowLinker’: true});
ga(‘require’, ‘linker’);
ga(‘linker:autoLink’, [‘siteA.com’] );

Remember to replace the example tracking ID (UA-XXXXXX-Y) with your own tracking ID, and replace the example autoLink domain (siteA.com) with your own primary domain name.

Adding the domain to page URLs using filters

By default, Google Analytics only includes the page path and page title in page reports – not the domains name. For example, you might see one page appear in the Site Content report like this:

Because the domain names aren’t listed, it might be hard to tell whether this is www.siteA.com/contactUs.html or www.blogB.com/contactUs.html.

To get the domain names to appear in your reports you need to do two things:

  1. Create a copy of your reporting view that includes data from all your domains in it
  2. Add an advanced filter to that new view. The filter will tell Google Analytics to display domain names in your reports.

Follow this example to set up a view filter that displays domain names in your reports when you have cross-domain tracking set up. For some fields, you need to select an item from the dropdown menu. For others, you need to input the characters here:

  1. Filter Type: Custom filter > Advanced
  2. Field A: Hostname Extract A: (.*)
  3. Field B: Request URI Extract: (.*)
  4. Output To: Request URI Constructor: $A1$B1
  5. Click Save to create the filter.

You can validate that filters are working as you expect using Google Tag Assistant Recordings. Tag Assistant Recordings can show you exactly how your filters change your traffic.


Get Social! Follow us on LinkedIn, Twitter, and Facebook and keep up-to-date with our Google Analytics insights.