Preparation Cross Domain Tracking in a Google Analytics 4 It is well documented.
In this article, I want to address these acute cases. They are:
- How to prevent
_gaUpdating the cross-domain tracking cookie from tampering with pre-existing customer identifiers on the site.
- How to configure cross-domain tracking manually If the automatic system is not working or if you want more control over your deployment.
Simmer . Newsletter
Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava right in your inbox!
Tip 128: Set up cross-domain tracking in Google Analytics 4
If you remember, cross-domain tracking means that for websites Aggregation for the same data flow in Google Analytics 4, client and session identifiers are preserved when a user moves from one domain to another.
If the domains subdomains From the same main field, you don’t do You must configure cross-domain tracking, as cookies will be written in Google Analytics 4 on the main domain by default. This way it is available to all subdomains by default.
Adds cross-domain tracking URL parameter For all outbound links from one configured domain to another configured domain.
This URL parameter is a hash of the relevant identifiers, and the domain receiving traffic will be able to take these identifiers and save them as new first-party cookies on the domain. This way the identifiers persist from one domain to another.
How to set up cross-domain tracking
While this is explained quite clearly in the official documentation, I will revisit the steps here.
Make sure that all domains you want to include in cross-domain tracking You have a dataset configured on the same Measure ID (G-XXXXXXX). This is imperative. Cross-domain tracking only works if all domains collect data to the same data stream.
In the data flow settings in Google Analytics 4, click More labeling settings.
In the overlay that appears, tap Configure your domains.
For example, to configure both simoahava.com And gtmtools.com For cross-domain traffic, I would like to populate the list as follows:
To test this, go to one of the domains that collects to your data stream. Then click on a link that points to some of the domains you’ve added to the list above.
If all goes as planned, you should see a new URL parameter with
_gl followed by a set of hashes. Each hash is preceded by a cookie name. In the above example, we have the following hashes:
*_gcl_aw*Google Ads Click ID.
*_ga*: Google Analytics client ID.
*_ga_XXXXXXXXX*: Google Analytics 4 session cookie.
*_fplc*: A cross-domain cookie for server-managed client identifiers when using server-side Google Tag Manager.
If you are don’t do look at it
_gl parameter in the URL, it means that you either misconfigured the domain name(s) in your cross-domain tracking settings (check back!) or something is messing with the autolink decoration and you need to use a manual approach instead (read!).
The last thing to test is to compare the cookies set on the source domain to those set on the target domain. Assuming you’ve got all the same technologies running on the target domain, you should see cookies with values matching between the domain that sent the traffic and the domain that the traffic landed on.
For example, if you have Google Analytics 4 configuration Setup on the target domain, and aggregation to the same data stream as GA4 that is set up on the source domain, both
_ga_XXXXXXXXXX It should contain identical values across the two domains.
If you’re serving a server-side Google Tag Manager container from the same account that’s served in the source domain (and you’re aggregating to the same metric ID), you should see
FPLC A cookie with matching values between the two domains.
And if you’ve got the Google Ads conversion flag running on your target domain, you should see a file
_gcl_aw The set of cookies with the same click ID that is set on the source domain.
All this testing serves a purpose: traffic sent from the source domain and traffic sent from the target domain should have the same identifiers across related results.
If you see differences, there is an implementation error somewhere.
How to calculate multi-property or multi-platform settings
Cross-domain tracking replaces the Google Analytics cookie(s) on the target domain with values from those on the source domain. This is necessary to align the concept of “user” and “session” across the two domains.
However, what if you already have these cookies configured on the target domain, perhaps even with an extensive history of data collected using identifiers? so sad! These values will be scraped by those in the source domain.
for this reason, If you have other trackers on the target domain as wellyou want to avoid Cross-domain tracking of overwriting identifiers, you need to Protect These other trackers name spacing their cookies.
This differs from Universal Analytics, where the recommended practice was to rename Roll up cookie So that any pre-existing cookies are left as is.
Unfortunately, with Google Analytics 4, the link is across domains It only works with the default cookie name.
Of course, this means that if you want to implement cross-domain tracking, you will lose the local GA history anyway, unless you implement some complex shenanigan to copy the cookie value from
_ga to me
_local_ga First before the cross-domain linker has time to do its work.
Yes, this is so embarrassing And it’s really an obstacle to setting up automated cross-domain tracking if you want to keep history on the target site!
If you don’t mind starting from scratch with non-multi-domain Google Analytics 4 properties, you can set it
cookie_prefix domain for some values. After that, all tags that use this configuration will have
_ga A cookie is preceded by whatever you have added to this field.
This is what it looks like once the cookies are set:
How to manually configure cross-domain tracking
if Cross-domain tracking doesn’t work automaticallyIf you want more control Above the cookies that are overwritten, or if you don’t trust any automated configurations and want a more manual touch of setting things up, you can always set up cross-domain tracking manually.
Unfortunately, it is really embarrassing. For some reason, there is no built-in API in
gtag.js Or the Google Tag Manager that will allow us to create the link parameter (the parameter with the extension
_gl) manually. Instead, even according to the official documentation, you will need to create the query string manually, add cookie values as URL parameters to outbound links, and then get them from the URL on the target site.
It’s not complicated. Absolutely. requires a crazy The amount of manual work of site management.
Here’s the process you’ll need to do:
- On the source site(s), write an event listener that listens for all link clicks (or related interactions) that target the domains you want to pass identifiers to.
- When such an event occurs, prevent the default (redirect) action of the event in the listener’s callback.
- Drag the values of the first-party cookies you want to pass to the target page, and append them to the URL of the original link as query parameters.
- at least, Add the current timestamp to the URL as well (more on this below). If possible, write simple Browser fingerprint Moreover.
- Load the target URL with the URL parameters in place.
- On the target page, check if the timestamp in the URL is older than 1 minute (for example) and, optionally, that the browser fingerprint matches the current browser.
- Before there is time to fire any tags, run a script that pulls the values from the URL and writes them to first party cookies on the target URL.
In (6) we are trying to prevent a scenario in which a user shares a URL in social media (or similar), after which anyone who follows the link will be considered the same user as the person who shared the link.
As an option for (7), if you’re only interested in Google Analytics 4 tracking (client-side), you can also load the URL parameter values directly into your GA4 config with something like:
gtag('config', 'G-12345', // Namespace roll-up trackers cookie_prefix: 'roll-up', // Pull in the Client ID from the URL client_id: (new URLSearchParams(document.location.search)).get('client_id'), // Pull in the Session ID from the URL session_id: (new URLSearchParams(document.location.search)).get('session_id') );
This is just a file very simple Example. He. She suck You have to do all this work manually. Google Analytics 4 will really Need an API to grab the link parameter. I hope to be able to happily update this article soon with details on how to manually create the link parameter.
While it would be great for cross-domain tracking to work without having to run code on the site, it would also be great if there was a manual option viable as well.
The biggest cross-domain tracking issues in Google Analytics 4 are:
- There is no viable method Protect Cookies overwrite the target domain.
- There is no viable method manually Create a link parameter.
Both scenarios, ironically, require a significant amount of manual work to solve. Since there is no way to create the link parameter programmatically, this manual work is almost always going to be substandard.
gtag.js Automatically generated library.
Cross-domain tracking is an essential part of any web analytics platform. I’m glad Google Analytics 4 did its best to demystify this by switching the setup to GA4 UI.
The next step is to include sufficient means to set it up (or configure it) manually as well.
Let me know in the comments if you have questions about setting up cross-domain tracking in Google Analytics 4! I realize I haven’t included a full example of how to do cross-banding by hand, but I stand by the chance that we have the means to create the link parameter manually.