• Courses
    • Courses
    • Course bundles
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • About
    • About
    • Contact
  • Login
  • Courses
    • Courses
    • Course bundles
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • About
    • About
    • Contact
  • Login

October 17, 2022

Cross-domain tracking in Google Analytics 4

Updated: October 17th, 2022

If you are familiar with cross-domain tracking in UA, you probably know that most of the configuration is done either on the code level (e.g. in gtag.js) or in GTM (GA tags). Because of that, many marketers and web analysts were confused about what to do and where. Luckily, in Google Analytics 4, things have been greatly simplified.

In this guide, I will show how to configure cross-domain tracking in Google Analytics 4. First, we’ll start with the problem that cross-domain tracking solves, and then we will go to the actual configuration.

 

Table of contents

+ Show table of contents +

  • The problem of multiple domains
  • What is cross-domain tracking in Google Analytics 4?
  • How does cross-domain tracking work in Google Analytics 4?
  • Will Google Analytics track subdomains?
  • How to configure cross-domain tracking in Google Analytics 4?
  • Test the setup
  • Keep the redirects in mind
  • Frequently asked questions
  • Google Analytics 4 Cross Domain Tracking: Final words

 

Video tutorial

Prefer video content to text? Then you can watch this video tutorial on my Youtube channel.

 

Don’t need the introduction? Jump to the configuration

If you are already experienced with cross-domain tracking and you don’t need any introductions, then jump to this section where I’ll show how to configure it in Google Analytics 4.

But if you are new to this, continue reading.

 

The problem of multiple domains

This will be very simplified.

By default, Google Analytics tracks users with first-party cookies. You land on a website and GA (on behalf of your website) stores a _ga cookie (actually, it stores more but let’s focus on _ga) in the visitor’s browser (with some random identifier). When you, as a visitor, navigate from page A to page B (of your website), Google Analytics checks the values of that cookie.

Since the cookie is still present (and its value is the same), GA understands that you are the same person who just was on page A, therefore, the 2nd page view is also included in the same session and user.

And that’s great! With web analytics tools (not just GA), you can track how visitors are using your website, what are they doing, etc. Of course, cookies, as a technology, are far from being perfect and have a lot of drawbacks but let’s keep this topic for another blog post.

So where is the problem?

First-party cookies (created on behalf of your website) cannot be shared between two separate domains (due to cross-domain policy). So if you have a website where the journey of a visitor starts on domainA.com and eventually, ends on the domainB.com, Google Analytics on the domainB.com will not able to understand that this is the same visitor as on the domainA.com (even if the GA property on both domains is the same).

When the visitor navigates from domain A to domain B, Google Analytics on domain B cannot reach particular cookies of domain A, therefore, it creates new ones.

The result? Google Analytics (and other cookie-based web analytics tracking tools) will see you as two separate visitors, one on the domainA.com and one on the domainB.com.

And that’s a big problem. You will see too many users in your GA reports. Every person who visits both domainA.com and domainB.com will turn into two users.

Also, if a new user is tracked, then naturally, a new session will also start and in your traffic acquisition reports, you will your domainA.com This situation is called “self-referral”.

What should you do? Enter cross-domain tracking.

 

What is cross-domain tracking in Google Analytics 4?

It is a workaround that allows webmasters/marketers/analysts to send user’s/visitor’s identifiers from domain A to domain B and preserve the session information. That way, the visitor is being tracked as the same person across multiple websites/domains.

In order for this to work, both websites must use the same GA4 data stream (a.k.a. same measurement ID).

 

How does cross-domain tracking work in Google Analytics 4?

Here’s the process in a nutshell.

When a visitor navigates from domainA.com to domainB.com, Google Analytics 4 will pass a special parameter to domainB.com’s URL. Thanks to that parameter, the GA on domainB.com will be able to update Google Analytics 4 and will understand that it’s actually just one person navigating between two websites.

 

Will Google Analytics track subdomains?

Yes, and you DON’T need cross-domain tracking for that.

If you want to track different websites that belong to the same domain (e.g. blog.yourwebsite.com and www.yourwebsite.com), Google Analytics 4 will handle that automatically.

So if you google something like “is subdomain considered as cross domain?”, the answer in this context is NO.

 

How to configure cross-domain tracking in Google Analytics 4?

Alright, now that we got familiar with the problem (and the solution), it’s time to configure it.

Before you do this, remember one requirement: both websites (that you are going to include in cross-domain tracking) must use the SAME GA4 property installed. The code can be installed directly on the site (gtag) or via GTM. But it’s important that this happens in the same property.

Step #1. Go to the Admin of Google Analytics > Data Streams and select web data stream

Step #2. Go to Configure Tag Settings.

Step #3. Click Configure your domains

Step #4. Enter all domains that should be included in the cross-domain tracking setup. Then hit save.

That’s it. You DON’t need to configure the referral exclusion list for this. GA will handle that automatically. However, if for some reason, you see your own domains as traffic sources, then you can configure unwanted referrals.

Important: if you also run Universal Analytics on a site, you need to remember something. _ga cookie is shared by both GA versions. Thus your cross-domain setup in Google Analytics 4 admin should match the settings of Universal Analytics. In other words, the domains in both configurations must match.

Note: this will also affect your automatic outbound click tracking in Enhanced Measurement. Domains that you enter here will not be treated as outbound clicks anymore.

 

Test the setup

Once you have saved your changes, wait for a minute or so and then go to your first website (let’s say it’s domainA.com). On that website, you will have to find a link that will redirect the visitor to domainB.com.

Click it. Once you are redirected to the 2nd domain, check the URL. It should contain the _gl= parameter with a lot of stuff.

Then you can also enable the GA Debugger extension and go to the DebugView of Google Analytics 4. There you should find your device and once you do that, you should see that you have at least several page_view events. In some events, page_location parameter will contain the domainA.com. And in other events, it will contain the domainB.com.

That is the final result you should be looking for.

 

Keep the redirects in mind

If the URL on domainB.com does not contain _gl parameter, there might be a JavaScript redirect somewhere along the way. Try using the extension Redirect Path to identify problems.

Install the plugin, then go to domainA.com and click the link to domainB.com. Then click on the Redirect Path extension and see if the _gl parameter was there. If it was at first, but then was lost, you should talk to your developers and ask them to debug this further. The goal here is to persist that _gl parameter.

 

Frequently asked questions

Some of these questions were already covered in this blog post but I will still list them here (because not everyone carefully reads every paragraph). So here’s the TL;DR version.

 

What is cross-domain tracking in Google Analytics 4?

It is a workaround that allows webmasters/marketers/analysts to send user’s/visitor’s identifiers from domain A to domain B and preserve the session information. That way, the visitor is being tracked as the same person across multiple websites/domains.

 

Why is cross domain tracking important?

Without it, the number of your visitors would increase and be less accurate. Also the number of sessions will increase because when the visitor navigates to the second domain, a new session will be started (because GA treats this as a different user).

 

Do I need cross-domain tracking for subdomains?

No, if you are talking about the subdomains of the same domain. Google Analytics 4 (and previous versions) is capable of tracking visitors across subdomains. So, you don’t need to do any additional configuration.

 

Do I need to configure the referral exclusion list for cross-domain tracking in Google Analytics 4?

No, Google Analytics 4 handles self-referrals automatically based on the domains that you entered in the “Configure your domains” section (source). A referral exclusion list is needed for things like payment gateway domains, etc.

 

How do I test cross domain tracking?

You can verify your cross domain setup by clicking the link on the first website (that redirects you to the second website). The URL of the second website should contain the _gl= parameter. Also, you can check if the _ga cookie is the same.

Take a look at the screenshot below and perform this check on both domains. The _ga cookie’s value must be the same on both domains. Also, keep an eye on the “Domain” column of the cookie list.

 

Google Analytics 4 Cross Domain Tracking: Final words

Cross domain tracking in GA4 requires less configuration compared to Universal Analytics and the process is more straightforward. No more allowLinker or Auto Link Domains.

Just go to the admin of your GA4 property > Data streams and configure your domains in the Web Stream.

With the rise of Google Analytics 4, you can clearly see the direction that Google is taking: less of configuration in the code or GTM, more in the GA4 interface itself. But that does not mean, that GTM becomes useless. There are still many things where Google Tag Manager is absolutely necessary.

 

Julius Fedorovicius
In Google Analytics Tips
45 COMMENTS
Matthew
  • Mar 30 2021
  • Reply

Hi Julius,

Great article as always. Some interesting feedback I received from Google. I had previously set up GA4 cross domain tracking for accounts that I also have UA cross domain tracking set up on.

One thing I noticed is that referral traffic from websites A&B is still coming through despite the _gl paramter and the exclusions were set up. Talked to Google and said that this will be more common because of how users enter the website. Not sure that I agree that this is how it should work but I've seen it across two properties now. They also mentioned you have to wait up to two weeks for source/medium to be sorted out.

Have you run into any similar issues?

    Julius Fedorovicius
    • Mar 31 2021
    • Reply

    Yeah, I have noticed this, and waiting might be needed. But I don't have more specific details (yet)

Grace
  • Mar 30 2021
  • Reply

Hi Julius,

I wonder what's _gaXXXXXXX parameters after _gl=xxxx? It's super long and I saw the GA4 Measurement ID is there too.

Thanks,
Grace

    Julius Fedorovicius
    • Mar 31 2021
    • Reply

    Don't know the specific reason but if it's there, it's needed for cross-domain tracking :)

PASCO
  • Apr 24 2021
  • Reply

Hello Julius,

Thank you for your article :)
What if we need the Javascript redirection between two domains ? I can't figure out how to make it work for now.
With a basic href, it work fine and add the gl parameter, as soon I go JS the gl parameter disappear.
I even tried to simulate the click on an href link thanks to $('#...').click() with no sucess.

Issue is that i use a dropdown to select the domain the user want to go, so I can't see how it can use a normal href.

Katerina
  • May 19 2021
  • Reply

Hi Julius,
We really need your help with the GA 4 set up - it seems that we are stuck.

We've decided to use GA 4 for our product analytics and faced the issue that we can't find a solution to.

The problem is that our app is used on various user instances with different web-addresses (thousands of instances with different and unknown for us names). So, to collect data from all of them into one data stream we used the following regular expression for the domain ".(\. \D{2,3})$".

At first everything worked just fine but then we got several support requests that users faced 404 errors when they tried to click links leading to other external sites.

After the investigation, we learned that it was because of an additional "_gl" parameter of GA 4.

As our regular expression for the domain ".(\. \D{2,3})$" matches all possible sites, GA 4 adds the "_gl" parameter to all the links as well and some of the sites just can't process this parameter and show blank pages with 404.

But we can't narrow down the domain expression - so we are stuck.

Please help - maybe we are missing something obvious?

Kia
  • May 21 2021
  • Reply

Hi, I have setup the Cross Domain for my websites and when I click the link to my other website, url has an extra parameters showing it is tracking by Google Analytics. Now I would like to see the report regarding the external websites which are getting tracked. Where should I see the report?

Mahmoud
  • Nov 30 2021
  • Reply

Hi Julius
Thank you for your article

how can organize multiple websites on the same domain ?
we made multiple websites (all websites is the same and just different in languages ) that are published in the same domain and separated by folder like example.com/en, example.com/fr , ...

At this moment we made some tags that have different trigger, due to the folder name in URL so we made many properties in Google Analytics for each website..

Is it good idea? or we should chose better strategy, Since I am junior in data analytics, I don't know is it suitable for analysis or I put all of websites in a one analytics proprerty

What do you recommend?

    Julius Fedorovicius
    • Dec 1 2021
    • Reply

    Without knowing the full context it is difficult to provide the best solution. It should definitely be a single GA4 property. But as for how many GTM containers should be there - that depends. Very likely that one container will be enough (but there might be some exceptions)

Aaron Hall
  • Feb 1 2022
  • Reply

Hi Julius,

I have a client that has hard coded cross domain tracking using gtag.js. They turned it off because it was sending users to a 404. It is no longer live on their site, but here is an example of the query string:
?_gl=1*1t5nmsm*_ga*MTI2NDExODAwNS4xNjI1Njg3ODg5*_ga_3M8QD3Z631*MTYyNjgwMDgyNi4xNC4xLjE2MjY4MDA4OTcuMA..&_ga=2.159936570.687073448.1626710733-1264118005.1625687889

Through trial and error we realized that the ".." was what is causing the page to be a 404. That in itself is weird because I have added this query string to other sites and that ".." doesn't take a user to a 404. So that is one issue that the client needs to figure out.

My question is whether that ".." should even be part of the query parameter. Is that string being truncated or something or is that ".." typical.

Arian
  • Feb 11 2022
  • Reply

Hello Julius, I have a question.
Pretend we have a ton of Landing Pages... hundreds, maybe even up to a 1000.
Pretend those websites are DomainA1.com, DomainA2.com, DomainA3.com, ..etc.., DomainA1000.com.
All of those LandingPages then link into 1 website (DomainB.com) where they can become a referral and reach our Goal there.
I don't want to manually add 1001 websites to the 'Configure Your Domain' setting. Our Marketing Team adds new LandingPages each week and would be a hassle to maintain and I.T. devs double-check their work.
Is there a way to handle that situation? like pretend only added DomainB.com to that area without the need for the DomainA####.com or setup the GTM tag on the DomainA####.com domains so dynamically it will add it into that 'Configure your Domain'?

    Arian
    • Feb 13 2022
    • Reply

    "Enter all domains that should be included in the cross-domain tracking setup. Then hit save.". Im curious as it relates to my question above. Does it really have to be all domains... What if you can only go from DomainA# to DomainB and not vice-versa?

    The Universal Analytics tutorial you have implies this "If it’s only possible for the visitor to navigate one-way (e.g. from domainA.com to domainB.com), then domainB.com should be entered in that field). If it is possible for a visitor to move both ways, back and forth), then enter both domains in that field."

    So Im hoping I can use the more updated GA4 vs UniversalAnalytics and only need to add DomainB then.

    Note: in my scenario... there is a utm campaign (like FB ad) that goes to DomainA#.com which then goes to DomainB.com. Just thought id mention that as really there are 3 domains involved. FB->DomainA#->DomainB

pramit shah
  • Mar 29 2022
  • Reply

Hi,

I have done both website's cross-domain Linking in GA4. And Works perfectly. But I need both domain's traffics Separate. So Please suggest to me possible ways, to Get different Reports from both domains.

Keyvan
  • Mar 31 2022
  • Reply

You mention that for CDT both domains need to be under the same data stream but later you say they should be under the same propert (as in they can be in different data streams) Which one is true? can we setup CDT between multiple datastreams within the same propert?

    Julius Fedorovicius
    • Mar 31 2022
    • Reply

    The latest recommendation from google is to use the same data stream

      Keyvan
      • Mar 31 2022
      • Reply

      Ok thank you. Do you have any tips on how to (separately) visualize data from different domains under the same data stream?(something to have in mind when setting up the config tag for the target domains in gtm maybe?)

        Julius Fedorovicius
        • Mar 31 2022
        • Reply

        Use comparisons and segments. More specific steps are available in my GA4 course https://www.analyticsmania.com/courses/google-analytics-4-course/

          Keyvan
          • Mar 31 2022

          Will do! thank you! You are doing god's work :)

Grace
  • Apr 1 2022
  • Reply

I have GA4 properties for subdomain sites (site1.example.com and site2.expample.com are tracked in two properties). I also have a GA4 property tracking both subdomain sites. My question is when user navigates from site1 to site2, will it be considered as referral or direct in site2 GA4 property?

As we have a lot subdomains for different products, we have to set up property per subdomain but still would like to see the interaction between them.

Thanks.

Matej
  • Apr 21 2022
  • Reply

Hi Julius.

Thanks for another perfect article.
Just to be crystal clear. In cross domain tracking do domain-A and domain-B have the same GTM code installed?

Thanks in advance for answer.

    Julius Fedorovicius
    • Apr 21 2022
    • Reply

    Containers don't matter

NEBUSO
  • Apr 26 2022
  • Reply

What about Google Search Console integration?
It's still 1:1.

Jhun
  • May 3 2022
  • Reply

I'm migrationg from UA to GA4 and one issue I need to fix is the cross-domain tracking. With this article, I need not to worry about it anymore. :D Very helpful guide.

Also, on another topic, would you also create an article in the coming weeks about filtering subdirectories or is it really not availablein GA4 (like a blog in the same domain /blog?) Do you think it's advisable to have a separate measurement ID for this situation? Thank you, Julius!

    Julius Fedorovicius
    • May 6 2022
    • Reply

    No plans for a public guide. But I talk a lot about this in my GA4 course https://www.analyticsmania.com/courses/google-analytics-4-course/

Long
  • May 23 2022
  • Reply

Hi Julius.

I have a question. We have a website with 2 subdomains. For example sub1.mywebsite.com and sub2.mywebsite.com. So in he Pages and Screens report of GA4, would they appear as the same Page path?

    Julius Fedorovicius
    • May 25 2022
    • Reply

    Yes

Oguz Erol
  • Jun 2 2022
  • Reply

after implementing cross domain tracking by GA4 interface, should i still use GTM interface? I mean this setting: "Enable linking across domains", "auto link domains", "A.com, B.com" Should i do this setting on gtm interface to make for example something on google ads work? Or is it useless after configuring cross domain from GA4 interface?

    Julius Fedorovicius
    • Jun 3 2022
    • Reply

    GA4 configuration is enough for most cases. But if you are also using the Google Ads remarketing tags in GTM, conversion linker is also needed.

    I have already replied to this comment on my Youtube channel. Please don't send the same message through multiple channels, it's very difficult to keep the conversation.

Jessica
  • Aug 25 2022
  • Reply

Hi Julius,

Will setting up cross domain tracking this way also work in reverse? Meaning if i set up a webstream for example.com and set up cross domain tracking with conditions for example.com and example2.com will the cross domain tracking still work if a user begins their journey on example2.com and then lands on example.com and vice versa. Thanks for your help!

    Julius Fedorovicius
    • Sep 19 2022
    • Reply

    Enter both domains in the settings and this will work

Hosein
  • Sep 18 2022
  • Reply

Hi Julius.
I think cross domain tracking in ga4 also working when two domains have two data streams but in one property.
I mean it does not need one data stream and one measurement ID.
do you approve that?

    Julius Fedorovicius
    • Sep 22 2022
    • Reply

    Technically, yes. But Google's recommendation is to use same stream. My guess is that separate streams might cause issues with sessions because every web stream sets some unique cookies

Juli
  • Oct 23 2022
  • Reply

Hello,

If I have domain.com and domain.com/blog(with separate admin panel), should I insert the same GA4 property tracking code in both of them?

    Julius Fedorovicius
    • Oct 23 2022
    • Reply

    Yes

Juli
  • Oct 23 2022
  • Reply

Sorry, just clarifying :)

-- So I need only 1 *data stream for both domain.com and domain.com/blog.
And insert the same *data stream tracking code in both of them.

And setting up with GTM,

-- Should I create 1 GTM container and 1 GA4 configuration tag (with the data stream Measurement ID)?

-- Aaand, I need to insert this 1 GTM container's tracking code in both of my websites separately (domain.com and domain.com/blog)?

Ron
  • Nov 6 2022
  • Reply

Would this be why CPAs are off, and the conversion isn't reporting correctly anymore for Google Ads?

MWatson
  • Nov 17 2022
  • Reply

Is there a way for us to have the parameter captured on the page, outside of the URL so it isn't visible to users?

    Julius Fedorovicius
    • Nov 17 2022
    • Reply

    No robust way

sunny
  • Nov 19 2022
  • Reply

Hey By any chance can someone explain me about setting up cross Domain Redirects , I am promoting my e-book , so i have a youtube channel which tells about how to make animated videos , what i want is , i will be running search ads and promote my youtube video , but before landing to youtube video , i want the user to come on my site and then go to youtube.com and when the user clicks on ad , he should be seeing youtube.com as the final url?
Can anyone help me out with this ??
And also Is cross Domain Tracking and cross domain redirects same thing or a different

Lee
  • Nov 24 2022
  • Reply

Hey Julian, I have this setup, and seeing a different prefix to each _ga value? See below

Domain 1

GA1.1.1600752974.1666012358

Domain 2

GA1.3.1600752974.1666012358

Have you come across this?

Itai
  • Dec 4 2022
  • Reply

Hi Julius
Thank you for this article

Is there a limit of how many domains can be entered under the "configure you domains" section?
Will it support hundreds of domains?

Thanks!

Luan Batalha
  • Dec 8 2022
  • Reply

Hi Julius!
I'm setting up the cross-domain measurement in GA4 as follows:
- Begins with "example.com.br"
- Begins with "sub.example.com"

However, Google is adding the _gl parameter when I go from "sub.example.com.br" to "example.com.br", even though both are part of the same domain.
Why this is happening and how to resolve it?

Mark Rosser
  • Dec 15 2022
  • Reply

Hi Julius, great article.

I have a question around this "Before you do this, remember one requirement: both websites (that you are going to include in cross-domain tracking) must use the SAME GA4 property installed. The code can be installed directly on the site (gtag) or via GTM. But it’s important that this happens in the same property."

I have the same GTM code installed on both sites. What is the next step to get the cross-domain tracking working in GA4? Set up specific tags in GTM for the 2 domains? At the moment the debug tool in GA4 is picking up my domain 1 page view and then tracking is lost.

Ieva
  • Dec 27 2022
  • Reply

I tried setting everything up. But I noticed that the first domain shows up in the acquisition. The domains are set up there where it's written, and the gl parameter sets everything up correctly, but when I check the cookie values - they differ. What could if they do?
An example on where the issue persists is on this page - when clicking on "Apply now", it opens the other domain, which is also set up:
https://careers.evolution.com/job/743999786073134/

Carlos Hartley
  • Jan 10 2023
  • Reply

GA4 debugview conversions are showing from sub domain but not in realtime, should I add the mx.website.com, br.website.com, fr.website.com to data stream? thanks

Leave a comment Cancel reply

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

 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • Cannot See the Google Tag Manager Option in Google Ads Conversion?
  • Google Ads Conversion Tracking with Google Tag Manager
  • Google Tag Manager Tutorial + Video & Free E-Book for Beginners
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings