A Guide To Cross-Domain Tracking in Google Analytics

A Guide To Cross-Domain Tracking in Google Analytics

Cross-domain tracking decorates destination URLs

Cross-domain tracking is often the last piece in the jigsaw to enable measurement of the complete user journey. It is essential for many websites because few sites can host every step of the user journeys such as the payment gateway or price comparison search engines. For this reason cross-domain tracking is an important element of your web analytics and conversion rate optimisation strategy.

Cross-domain tracking does not happen naturally with Google Analytics because of the way web analytics platforms keep track of users. Google Analytics uses first-party cookies to track visitors when they land on a domain but cookies can’t be shared between two different domains.

This means that if a user goes from one domain to another domain, even if they are part of the same web journey, Google will automatically allocate a new cookie and will treat them as a different user. As a result GA will duplicate users and so your traffic volume will be higher than it should be. In addition, when a user goes to another domain GA starts a new session and you will lose your traffic source as GA will allocate the original domain as the source of traffic.

When do you need cross-domain tracking?

Many websites use separate domains to deliver specific content or processes that are hosted on other websites. For example, many ecommerce sites redirect users to a secure payment gateway when making a purchase or a refund. Often this is in the form of a iFrame embedded in a page on the main website. This means the URL doesn’t change and the content in the iFrame is not visible to GTM or Google Analytics.

Other websites use embedded forms via iFrames to offer their users the ability to check the availability and book related services. For example, the car hire form below is embedded on the Manchester Airport site via an iFrame. This allows users access to an aggregator site’s search engine (i.e. part of Booking.com) which the airport would find difficult and expensive to replicate themselves.

You won’t need cross-domain tracking when users go between different sub-domains. Sub-domains are used to categorise different sections of a website, from blogs, stores and bookings. For example if we created a store on our website we might use store.conversion-uplift.co.uk as the web address. However, ‘store’ remains on the same overall domain of ‘conversion-uplift.co.uk’ and so Google Analytics will automatically track users going between sub-domains.

6 Steps to Implementing Cross-Domain Tracking:

There are six primary steps to complete for successfully cross-domain tracking. I will take you through each of these steps in detail, but they are;

  1. All domains send data to the same Google Analytics Property.
  2. The domains are added to the Referral Exclusion List of the GA Property admin settings.
  3. The target domain has the _ga=1.23456.34567.45678 linker parameter in the URL.
  4. Target domain Tags have the allowLinker field set to ‘true’.
  5. Create a cross-domain view for your Google Analytics Property
  6. Test your cross-domain tracking

1. Use the same Google Analytics property for both domains:

For cross-domain tracking to work you must send all data from both domain A and B to the same Google Analytics property. One way to achieve this is to have the same tracking code, with the identical GTM container ID (e.g. GTM-TRW66MD) on both the outbound (the main domain) and the target domain (where the additional content is hosted).

This allows you to automatically track users with the same tags for both domains and to easily send data to the same Google Analytics property. However, it’s not essential and you may prefer to use a different container for each domain. If you have different teams maintaining different domains it’s common practice to use separate containers for each domain.

2. Configure GA property’s referral exclusion list:

Go to your GA property and select the ‘Admin’ cog and select:

Property Settings > Tracking Info > Referral Exclusion List and then select ‘ADD REFERRAL EXCLUSION’ and enter the URL for domain B in to the input field and click ‘Create’.

Referral Exclusion list
Source: google analytics

3. Decorate the URL of the target page with link parameter:

When implementing cross-domain tracking you will hear a lot about ‘decorating the URL’ of the target web page. The objective of this is to ensure the GA cookie is identical on both websites. This means that Google Analytics will recognise a visitor as the same user as they navigate between the two different domains. This is achieved by domain B’s URL being decorated with the _ga linker parameter which retains data, including the value of the cookie used by GA for our domain A. However, this needs to occur when the user navigates from the outbound website (domain A).

To determine how you are going to implement the _ga linker parameter you need to consider how the user navigates from domain A to B.

  1. Do they click on a link that redirects them to domain B?
  2. Complete a form on domain A that redirects to domain B on submission?
  3. The page on domain A has a iFrame from domain B embedded on the page?
  4. Some other interaction where standard cross-domain tracking fails to work?

How To Decorate The Target URL for Cross-Domain Tracking?

How to decorate the target URL for cross-domain tracking

Auto-link domains:

Go to domain A’s GTM container and then ‘Variables’ > GA Settings Variable > More Settings > Cross Domain Tracking. Enter the domains you need to auto-link here. If users can only go from domain A to B, then just enter domain B’s domain. If users can navigate to and from each domain then you need to enter both domains, separated by a comma. Save the variable and refresh the ‘Preview’ mode in GTM.

Auto-link domains in Standard GA Settings variable
Source: google analytics

You can now check if the target domain link is decorated. Right click on the URL link you are seeking to decorate and select ‘Inspect Element’ and view the ‘Elements’ tab in the Google developer’s console. Examine the target domain link’s href attribute and it should display the _ga=1.23456.34567.45678 linker parameter in the URL.

Decorate Forms:

If you are using GTM Form Submission trigger you can decorate your form using a new tag. Go to the container for your form and create a new tag:

  • Tag type: Google Analytics – Universal Analytics
  • Track type: Decorate Form
  • Decorate Form Parameters: False
  • Google Analytics Settings: GA Settings Variable
Decorate Form tag
Source: google analytics

Now add a trigger that fires on the form submission. If you already are tracking the form submission you can use the same trigger. Otherwise create a new trigger which needs to be configured to only fire for forms where the user will be taken to the target domain. In the example below I chose to fire the trigger on ‘Some Forms’ and specified the exact Form ID for the form to avoid other forms also triggering the tag.

Form submission trigger
Source: google analytics

iFrame Tracking:

When a user is served an iFrame they don’t click on a link to go to another domain and so there is no link to decorate. An iFrame is an HTML element that is served to the user when a page loads. However, the content within the iFrame is hosted on another website and so cross-domain tracking is required to measure user interactions within the iFrame. Payment gateways are probably the most common use of iFrames.

I could write a whole blog just on tracking users in iFrames as there are a number of recommended approaches. Instead I recommend you check out Simo’s updated blog post on tracking cross-domain iFrames which provides a detailed explanation of his approach to measuring user interactions with iFrames.

Get a Developer’s help:

If you find none of the above work or you have some other kind of cross-domain activity that doesn’t involve a user interaction, it is probably time to get a developer involved in the process. Ask your developer to configure the target URL with the _ga linker parameter. You can find some suggested instructions for this in Julius Fedorovicius’s blog on the Analyticsmania.com website.

4. Target domain Tags have the allowLinker field enabled on domain B:

Now that you have decorated the URL for the target domain you need to configure Google Analytics to recognise the parameter and update the GA cookie on the target domain. Provided you have GTM on domain B you can implement this by going to the GTM container for domain A and select > Variables > Standard GA Settings > More Settings > Fields to Set and input:

  • Field Name: allowLinker
  • Value: true
allowLinker in Standard GA Settings
Source: google analytics

If you don’t have GTM on domain B and you instead use hard coded gtag.js you will need to seek the help of a developer to add a command ‘linker’:{‘accept_incoming’:true}}); to domain B.

5. Create cross-domain view:

To ensure you can clearly distinguish visitors on different domains in your analytics reports you should create a new view in your Google Analytics property. Go to your normal reporting view and then; > Admin > View Settings > Copy view and give it an appropriate name – e.g. ‘Cross Domain Tracking’.

You should then go the Filters > ADD FILTER > Create new Filter. We need to append the domain name to the request URL so that there will be no confusion about which domain any page is on. You can do this by;

  • Filter Type: Advanced
  • Field A -> Extract A:
  • Hostname: (.*)
  • Field B -> Extract B:
  • Request URL: (.*)
  • Output To -> Constructor
  • Request URL: $A1$B1
  • Field A Required – Tick
  • Override Output Field – Tick

Then save the filter and check the view later to see if the domain has been appended to the page path. It’s wise to create a test view for cross-domain tracking so that you can experiment first before you implement changes to your reporting view.

6. Test your cross-domain tracking:

Due to the complexity of websites you can never guarantee that everything works first time with something like cross-domain tracking. As mentioned earlier the goal here is to ensure the URL of the target domain contains the _ga parameter with the identical value to the one on domain A.

Use Chrome’s Developer tools or use the Chrome Extension, Edit this cookie, to find the last four digits of the cookie. You can then go through the user journey to domain B and check that the cookie value is identical to what you see on domain A.

Edit this cookie Chrome extension

If the _ga parameter is not present you may have to seek the help of a developer. However, if it is present then we can go to through test journeys to check our tags fire by going into the ‘Preview’ debug mode of GTM. Configure to send data to a test GA Property so that you can also check the Realtime console in GA.

You should also check that the referral exclusion list is set up correctly by going to the ‘Traffic Sources’ tab and see if the traffic source is displayed as Direct. If you have virtual page views set up on domain B then the source should be whatever you have set it to.


Implementing cross-domain tracking for Google Analytics enables analysts to track the whole user journey without breaks due to payment gateways or iFrames. This provides much needed clarity on critical steps in the user experience.

Don’t let the potential complexity get in the way of implementing cross-domain tracking. You will inevitably learn from the process and are likely gain useful insights by closing the circle of the user journey. Follow our checklist below for cross-domain tracking.

Cross-domain tracking checklist

Make sure you send data from both domain A and domain B to the same Google Analytics property. You don’t have to use the same GTM container for both domains, but make sure the data goes to the same property.

Add the relevant domains to the referral exclusion list in Google Analytics.

Ensure the target domain has the correct _ga linker parameter in the URL. If users navigate to domain B via a click on a link you should set the auto-link decoration of URLs in the Standard GA Settings variable.

In your Standard GA Settings variable in GTM set the allow Linker in ‘Field to Set’ as true.

Now create a cross-domain tracking view GA and add a filter to append the domain name to the request URL.

Finally, test and test until you are happy that everything is working as expected. If you do have problems it is probably time to bring in a friendly developer to help you. Good luck and let me know how you get on.

Featured image by Mike Bird on Pexels

More reading

Setting Up Enhanced Ecommerce with Google Tag Manager

How To Track a shared Payment Gateway with GTM


Leave a Reply

Your email address will not be published. Required fields are marked *