Sub topic 14
Cross-domain measurement basics
This chapter covers what happens when a visit spans more than one domain, such as a marketing site and a separate checkout site. It explains how GA4 keeps the visit in one session, how to configure that, and how to find the usual failures. It assumes you can already create a web data stream, find its measurement ID, and install the tag on a page. It also assumes you know the Realtime report and DebugView from earlier chapters.
Why the problem exists
GA4 identifies a browser with a first-party cookie. The _ga cookie holds a client ID, and a _ga_<container-id> cookie holds session data. Browsers scope cookies to the domain that set them. A cookie written on www.example.com is invisible to checkout.example.net.
Without any extra setup, a visitor who moves from the first site to the second looks like this:
- The second site finds no cookie, so it creates a new client ID. GA4 counts a new user.
- The second site starts a new session.
- The traffic source for that new session is the first site. GA4 records a referral from
www.example.com, and the original source (such as a Google ad) is lost.
The result is inflated user counts, broken funnels, and conversions credited to your own domain instead of the channel that earned them. Cross-domain measurement fixes this by passing the identifiers from one site to the other.
When you need it and when you don't
Cross-domain measurement applies only to different registered domains that you want to treat as one site.
| Situation | Cross-domain setup needed? |
|---|---|
| `example.com` and `blog.example.com` | No. The cookie is set on the parent domain, so subdomains share it. |
| `example.com` and `example-shop.net` | Yes. |
| `example.com` and a third-party payment page you want to track through | Yes, and the third party must also run your tag. |
| Two sites that you want reported separately | No. Use separate streams or properties instead. |
The second case has a hard requirement. Both domains must send data to the same web data stream, using the same measurement ID. If each domain has its own stream, linking them cannot merge the sessions.
How GA4 links the sessions
When a visitor clicks a link to a configured domain, the GA4 tag adds a _gl parameter to the destination URL. The parameter holds an encoded copy of the client ID and session information. The tag on the destination site reads _gl, writes its own cookies from the values, and continues the same session.
The tag does this in two places:
- When a visitor clicks an
<a>link whose destination matches a configured domain. - When a visitor submits a form whose action matches a configured domain.
The _gl value is short-lived, valid for roughly two minutes. It is a handoff token. It is not a permanent identifier, and a copied or bookmarked link will not carry the session forward after that window.
Configuring cross-domain measurement in the interface
The simplest route works for any installation method, because GA4 stores the setting on the stream.
- Open Admin, then Data collection and modification, then Data streams.
- Select the web stream.
- Under Google tag, choose Configure tag settings.
- Choose Configure your domains.
- Add one or more conditions. Each condition has a match type and a value. Typical match types are Contains, Begins with, Ends with, Equals, and Matches regex.
- Save.
Add every domain in the journey, including the one you are currently on. For two sites you would add conditions that match example.com and example-shop.net. Prefer Contains with the bare domain name unless you have a reason to be stricter. An overly strict Equals match on www.example.com will silently miss links to example.com.
Changes made here can take a short time to reach the tag on your pages. Allow some time before you conclude the setting did not work.
Configuring it in code
If you install with gtag.js, you can set the linker in the config call. Put this on both sites. Both pages use the same measurement ID.
<!-- Google tag (gtag.js) on every page of both domains -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX', {
'linker': {
'domains': ['example.com', 'example-shop.net'],
'accept_incoming': true
}
});
</script>The domains list names the sites whose links should be decorated. The accept_incoming option makes the page accept an incoming _gl even when the visitor arrived from a domain not in the list. Without it, the tag typically accepts _gl only if the domain is configured as a destination.
In Google Tag Manager, you set the same list in the Google tag's configuration settings, in the field for domains to link. The tag settings in the interface and the settings in code or GTM can both exist. Keep them consistent so you do not debug two sources of truth.
What the linker cannot decorate
The tag can only add _gl when it sees a click or a form submission. These patterns commonly break the handoff:
- Redirects. A link goes to a short-link or login service, which redirects to the destination. The redirect often drops the query string, so
_glnever arrives. Configure the redirecting service to preserve query parameters. - Links created after load. If a script builds the link after the tag attached its click handler, or changes
window.locationdirectly, nothing decorates it. Use real<a>elements where possible. - Iframes. A page embedded in an iframe on another domain is a separate browsing context. The parent's cookies are not shared with it.
- Cross-origin
fetchor JavaScript navigation. These do not trigger link decoration. - POST forms and server-side flows. Behavior varies. Test the exact form, and confirm the destination URL carries
_gl. - Destinations without your tag. If the second domain does not run the tag with the same measurement ID, the parameter is ignored.
Stop the self-referrals
Even a working setup can show your own domains as traffic sources. This happens for flows where the session carry-over fails, and for third-party services such as payment gateways that return the visitor to your site. To prevent a payment provider from replacing the real source, add it to the unwanted referrals list.
- Return to Configure tag settings on the web stream.
- Choose List unwanted referrals.
- Add conditions for the domains that should not be treated as referral sources.
Traffic from a listed domain is treated as direct, and it does not start a new attributed session on its own. Use this for payment processors and for sign-in pages hosted by another provider. Do not use it to hide a broken cross-domain setup. If your own domains appear as referrals, fix the linking first.
Verifying the setup
Test with a real browser session instead of assuming the configuration worked.
- Open the first site in a fresh browser window. A private window is good for this.
- Click a link to the second domain.
- Inspect the address bar. The URL should contain
_gl=followed by an encoded string. - In your browser's developer tools, open the cookie view for each site. Compare the value of the
_gacookie. The numeric client ID portion should match across the two domains. - Turn on debug mode, as you did earlier with
debug_mode, and watch DebugView. Events from both sites should appear under one device, and the second site should not fire a newsession_start. - After a day or two, check Acquisition reports. Your own domains should not be leading referral sources.
If _gl is missing, the domain list does not match the destination, or the link was never decorated. If _gl is present but the client ID differs after landing, check that the destination page loads the tag with the same measurement ID and that no consent setting blocks storage there.
Consent and privacy interaction
Cross-domain linking depends on analytics storage. If a visitor has denied analytics consent on the first site, no client ID exists to pass along. The destination site then starts its own identity once consent is given there. Apply your consent configuration on every domain in the journey, so a decision made on one site is respected consistently on the others. The privacy and consent chapter covers the settings in detail.
Common mistakes
- Creating a second stream for the second domain and expecting linking to merge them.
- Listing only the destination domain. List every domain in the journey.
- Forgetting to install the tag on the second domain's checkout or confirmation pages.
- Testing only in an already-open browser that holds old cookies from before the setup.
- Treating subdomains as needing cross-domain setup, which adds noise without benefit.
Exercise
Your shop at shop.example.com links to a payment page at pay.example-gateway.com, which sends buyers back to shop.example.com after payment. Reports show many sessions in which the purchase is credited to a referral from pay.example-gateway.com. Name the two settings you would configure on the web stream, and the one requirement for the gateway domain.
Show answer
First, add example-gateway.com (and the shop's own domain) under "Configure your domains" so links are decorated with _gl and the session continues. Second, add example-gateway.com to "List unwanted referrals" so the return trip is not credited as a referral. The requirement is that the gateway's pages must run the GA4 tag with the same measurement ID, as one stream receives data from both domains. If the gateway is a third party that will not install your tag, linking cannot work there, and the unwanted referrals list is the only available protection.
Exercise
A visitor clicks a link from example.com to example-shop.net. The URL on arrival has no _gl parameter. List three causes you would check.
Show answer
Check whether example-shop.net is included in the configured domains (or whether the match type is too strict). Check whether the link goes through a redirect that drops the query string. Check whether the link is a real <a> element on a page where the tag is installed, instead of a JavaScript navigation or an element created after the tag attached its handlers. An iframe or a form with an unsupported method are further causes.