How do I configure cross-domain tracking in GA4?

Applies to: Google Analytics 4 (GA4)
Last updated: May 2025


Problem

You want to track users as they navigate across multiple domains (e.g., from example.com to checkout.examplepayments.com) without starting a new session or losing user attribution.


Solution

GA4 supports cross-domain tracking using automatic linking via the gtag.js or Google Tag Manager (GTM). You must configure it so GA4 can pass user identifiers between domains using URL parameters.


Step-by-Step Guide

Option 1: Configure via GA4 Admin (Web Stream Settings)

  1. Go to https://analytics.google.com
  2. Select your GA4 property
  3. Click Admin > Data Streams > Web
  4. Under Enhanced Measurement, click Configure tag settings
  5. Click Configure your domains under Cross-domain tracking
  6. Add all domains you want to track (e.g., example.com, examplepayments.com)
  7. Click Save

This updates the domain list that GA4 uses to automatically link sessions across sites.


Option 2: Configure via gtag.js (Manual)

In your gtag.js implementation, modify the config as follows:

<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', 'examplepayments.com']
}
});
</script>

Option 3: Configure via Google Tag Manager (GTM)

  1. Open GTM and go to your GA4 Configuration Tag
  2. Click Fields to Set and add:
    • Field Name: linker
    • Value: {domains: ['example.com','examplepayments.com']}
      (Use a Custom JavaScript variable or set it directly in code if needed)
  3. Alternatively, use the Auto Link Domains setting under tag configurations:
    • Enable “Send to multiple domains”
    • Add the domain list
  4. Save and publish your container

How It Works

GA4 appends a special query parameter (_gl=...) to URLs when users navigate across domains. This allows it to stitch sessions together across different sites without creating new users or sessions.


Notes

  • Both domains must have GA4 tracking installed and configured
  • Works only for links users click—not for redirects or iframe loads
  • Don’t add subdomains like shop.example.com unless you specifically use them with separate GA4 properties
  • Use GA4’s User Explorer or Explorations to verify that users remain unified across domains

You may also like...