Cross-domain tracking makes it possible for Google Analytics to track sessions on two related sites (e.g. an ecommerce site and a separate shopping cart site) as one single session. This is also known as site linking.

In other words, with cross-domain tracking, you can see a user in a single Google Analytics account throughout their journey across multiple domains you control (e.g. mysite.com and myshoppingcart.com).

It’s a seamless shopping and checkout experience for your online shoppers, so shouldn’t you track it seamlessly?

Why you need to set up cross-domain tracking

Here’s what it looks like with a standard configuration of the Google Analytics script on your site: 

Every time a user loads a page on a different domain, a new session is generated even if the branding looks seamless to the user and the previous session has ended. 

Even if the customer is still active and continues to generate events and page views on the other domain, the sessions are still interrupted. 

Until you implement the cross domain tracking on your site, you won’t have an accurate customer journey.

For example, let’s take a standard website, www.siteA.com, and its blog, www.blogB.com.

To track sessions, Google Analytics collects a Client ID value at 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 Google 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. 

First, the source domain needs to ensure all URLs pointing to the destination domain contain the Client ID of the source domain. Second, the destination domain needs to know to check for the presence of a Client ID in the URL once a user navigates there.

If you’re using gtag.js, cross domain tracking can be done by adding a linker parameter containing the Client ID (as well as the current timestamp and browser metadata encoded within it) to URLs pointing to the destination domain. 

When a value is configured for the domains property of the linker parameter, gtag.js will check for linker parameters in the URL. If the linker parameter is found and is valid, gtag.js extracts the client ID from the parameter and stores it.

By enabling cross domain tracking with gtag.js, you have the option to add the linker parameters either automatically or manually to URLs in links and forms on the page.

Setting up cross-domain tracking by 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 also have basic HTML and JavaScript knowledge (or work with a developer) to set up cross domain tracking. The examples in this article use the Global Site Tag (gtag.js) framework.

To get started, within the source domain you’ll need to configure the Domains property of the Linker parameter in your property’s config for URLs pointing to the destination domain. 

After that, gtag.js will listen for selections on links that point to the destination domain(s), and it will automatically add the linker parameter to those links before the navigation starts.

You can also set the optional decorate_forms property of the linker parameter to true if you have forms on your site pointing to the destination domain.

For example, this code will append the linker parameter to any links on the page that point to the target domain ‘siteA.com’:

					

gtag(‘config’, ‘GA_Property_ID’, {

  ‘linker’: {

    ‘domains’: [‘siteA.com’]

  }

});

If the destination domain is not configured to automatically link domains, you can instruct the destination page to look for linker parameters by setting the accept_incoming property of the linker parameter to true on the destination property’s config:

					

gtag(‘config’, ‘GA_Property_ID’, {

  ‘linker’: {

    ‘accept_incoming’: true

  }

});

Bear in mind, there are sometimes cases where it is unclear which domain your users will see fist. 

In such cases, there is also the option to implement “bi-directional cross domain tracking”. With this config, each domain is configured to work as either the source or the destination. 

To implement bi-directional cross-domain measurement, enable auto linking on both domains and configure them both to accept linker parameters and automatically link domains.

To keep the same code snippet on every domain, you can add all possible domains you want to track in the domains property of the linker parameter.

					

gtag(‘config’, ‘GA_Property_ID’, {

  ‘linker’: {

    ‘domains’: [‘example-1.com’, ‘example-2.com’]

  }

});

Setting up cross-domain tracking with Littledata’s Shopify app

If you use Shopify or Shopify Plus and have already installed one of Littledata’s Shopify apps to fix your analytics tracking, then the cross-domain linker implementation will be even easier. We offer versions for Google Analytics and Segment, but they work in basically the same way.

When you install Littledata, the app replaces Shopify’s integration with Google Analytics with its own improved tracking script (LittledataLayer). This script contains the extraLinkerDomains property where you can add extra sites for domain linking, keeping everything very robust:

					

LittledataLayer = {
   transactionWatcherURL: 'https://transactions.littledata.io',
   referralExclusion: /(paypal|visa|MasterCard|clicksafe|arcot\.com|geschuetzteinkaufen|checkout\.shopify\.com|checkout\.rechargeapps\.com|portal\.afterpay\.com|payfort)/,
   googleSignals: true,
   anonymizeIp: true,
   productClicks: true,
   extraLinkerDomains: ["domain1.com", "domain2.com"],
   persistentUserId: true,
   googleAdsConversionIds: ['AW-12345'],
   hideBranding: false,
   ecommerce: {
      currencyCode: '{{shop.currency}}',
      impressions: []
   }
};

How to test your cross-domain tracking setup

One of the easiest ways to test if the new cross-domain tracking is set up properly, is to check if the same client ID (cid) is tracked on all available page sessions using Tag Assistant Recordings.  

Get help from Littledata enterprise

If you’re an enterprise customer, just ask your account manager to help add the secondary domains and audit your set up. This is the easiest way to do it and one of the time-saving benefits enterprise customers enjoy. 

Using filters to report on cross-domain tracking

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:

/contactUs.html

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.

In your Google Analytics reports, you should start seeing the domain names populated alongside the page path. 

Want to double check to ensure it’s working? When you sign up for a trial, you can check your full setup with our  smart analytics audit. Get started today with a 14-day free trial!

Get my smart analytics audit