How to Set Up and Test Cross-Domain Tracking In Google Tag Manager

Oeuyown Kim, Analytics Strategist

Cross-domain tracking stitches a user’s sessions on your site together that would have otherwise been split up into different sessions by root domain. This type of tracking may be necessary on your site if users are ever able to navigate across domains within one session.

In this post, we’ll walk through how to identify the need for cross-domain tracking and how to set it up through Google Tag Manager. First, we’ll break down what Google attributes to a session by default.

How Google Analytics Determines Sessions

Google Analytics (GA) tags each user with a cookie for every domain that they visit. Then, these sessions are stitched together by looking at the cookie value and referrer data. A new session is started if there’s a new cookie or “campaign.” A campaign could be a referral domain (any root domain that’s different from the current page’s) or a new campaign parameter.

In the example below, a user would have a different GA cookie on than they do on Although they’d return to, a new session would start on P4 with as the referrer since the referrer is a new root domain. These new sessions that are artificially created are a consequence of not having cross-domain tracking set up in Google Analytics.

In this example, Session one includes a user's visit to P1,, and P2, Session 2 is comprised of a user's visit to P3,, and P4,

In some cases, a simple referral exclusion in GA would prevent sessions from being split up. A referral exclusion explicitly tells GA not to start a new session when that domain is returned as the referrer. For instance, if you don’t need to track the “other” domain (P3 in our example above), you can add it to the referral exclusion list in GA. In our example, it would essentially “skip” P3 and stitch our session together across P1, P2, and P4. If a user happened to start on and navigated to, however, the entrance to would be attributed to Direct.

By default, GA tracks the same cookie value for the same root domains—meaning and would already be stitched together. There’s no need to set up cross-domain tracking or even referral exclusions for subdomains.

When You Need Cross-Domain Tracking

Cross-domain tracking is required on your site any time you see sessions broken up across root domains. There are a few common situations that might break up sessions in GA:

Users Are Sent Through a Redirect

This has been the most common offender in my experience. A classic example is when a user submits a form and is sent through a redirect before hitting the thank you page.

In the example below, the user might start on and be sent through the Eloqua redirect without the page loading long enough for the user to notice it:


This results in all of these form-fill conversions being attributed to referral traffic from Eloqua.

Final Action/Conversion Takes Place on a Different Domain

A user might be sent to a thank you page on another domain instead of being redirected back to your website. This could result in misattribution or even a complete loss of visibility into your conversions.

A common example of this might be thank you pages through a Shopify checkout flow that live on a different domain than the main domain.

Users Can Navigate Between Multiple Domains in the Same Session

There are many instances where you might expect a user to navigate between multiple domains. You might have an international version of your website on a different root domain. Maybe there’s an affiliate company that’s linked from your site. Or maybe you house your job openings on a different platform—ergo, a different domain.

In any of these instances, if a user started on your website, visited any of these pages on a different domain, then navigated back to the main domain, it would trigger two sessions and cause misattribution in your GA reports.

How to Check Whether You Need Cross-Domain Tracking

You might already have an idea of what pages on your site could be causing tracking issues. It’s definitely worth checking if you host forms through Eloqua or have different root domains for international or affiliated sites.

As a general rule, check for possible navigation across any domain that’s not a subdomain.

Check for the following in Google Analytics:

  • Different hostnames. Add ‘Hostnames’ as a secondary dimension in the ‘All Pages’ report and look for any hostnames that don’t share the same root domain.
  • Internal referral sources. Navigate to your ‘Referrals’ report and look for any referral sources that could be internal traffic—this could be a lead capturing platform, on-site tools, or even internal platforms.
  • High % of conversions attributed to referral traffic. Referral traffic typically doesn’t account for a majority of conversions, but if it does, it’s worth checking the referral source to make sure conversions aren’t being attributed to a redirect.

If you’re still unsure after checking these reports within GA, use a tool like Google Tag Assistant to record a session across your site. Enable recording to navigate across any pages you’re wary of and submit a few test conversions.

The tool will show a warning at the top of the recording when a new session was initiated in the middle of navigation.

Setting up Cross-Domain Tracking in Google Tag Manager

You can set up cross-domain tracking in Google Analytics through the hard-coded script itself, or through Google Tag Manager (GTM). For this post, we’ll walk through how to set up cross-domain tracking through Google Tag Manager, but follow this guide if you want to configure the analytics.js script.

Google Tag Manager makes it easy to set up cross-domain tracking. Navigate to your GA tag in GTM and configure the following settings:

  • Create a new field named ‘allowLinker’ with the value set to ‘true.’
  • Add the alternate domains for cross-domain tracking under Cross Domain Tracking → Auto Link Domains.

Once you have the updates published in GTM, you’ll have to add the additional domain(s) under the Referral Exclusion list in your GA admin settings.
Additionally, I’d recommend prepending the hostname to your URLs to be able to view your reports by domain easily. Create a new filter in GA with the following settings:

For Filter Name, use Append Hostnames. For Filter Type, use the predefined "Advanced" option. Under Field A > Extract A select Hostname and enter (.*). Under Field B > Extract B select Request URI and enter (.*). Under Output To > Constructor select Request URI and enter $A1$B1

Once you’ve published these changes in GTM and GA, record another session through Google Tag Assistant across domains and with test conversions to make sure you no longer see the error.

In the case of cross-domain tracking across iframes, I’d refer to Simo’s guide to using customTask to decorate the iframe URLs and pair it with his solution to block page views (or just the first page view) from within an iframe. The iframe will have to have the ‘allowLinker’ field set to ‘true’ in its GA tag for this solution to work.

Unfortunately, there may be other situations where cross-domain tracking will not be this easy. However, in situations where the ‘allowLinker’ field is set to ‘true,’ you may still be able to hack together a solution outside of iframes by pushing the _ga cookie through a URL parameter, in a similar fashion to Simo’s solution mentioned above.

Hopefully, at the end of your testing, you’ll begin to see conversions attributed to the proper sources and be able to start understanding the interrelationships of different sections of your site.

Start call to action

See how Portent can help you own your piece of the web.

End call to action

Leave a Reply

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

Close search overlay