Link Code Generator Logo
Link Code Generator

Free GA4 Cross-Domain Tracking Code Generator

Generate Google Analytics 4 cross-domain tracking snippets to maintain user sessions across multiple domains. Paste the code and you're done.

Important GA4 Update: Google Analytics 4 highly recommends setting up cross-domain tracking via the Admin Data Streams UI rather than hardcoding it in standard deployments. However, if you are working within a complex custom CMS, using hardcoded gtag.js linkers is still supported and effective.

Found in your Google Analytics Admin panel under Data Streams.

Do not include `https://` or trailing slashes.

Enter your Analytics ID and the two distinct domains to generate the cross-domain tracking script.

Why GA4 Breaks Across Domains by Default

Google Analytics 4 identifies individual users by a cookie (_ga) stored on a specific domain. By default, this cookie only works on the domain that set it - it cannot be read by any other domain. This means when a visitor clicks from your main website (yourstore.com) to a separate checkout domain (checkout.yourstore.com or payment-processor.com), GA4 treats them as a brand new, anonymous visitor.

The impact: your funnel data is broken. You cannot see that a visitor who started on your homepage completed a purchase in your checkout. Your attribution data - paid ads, email campaigns, organic search - all appear to have zero conversions because the purchase happens on a different domain.

How GA4 Cross-Domain Linking Fixes This

GA4's cross-domain linker works by adding the user's client ID to the destination URL as a _gl= query parameter when they click a link crossing domains. The destination domain reads this parameter, recognizes the existing session, and continues tracking - no new session is started.

For this to work, both domains must have a GA4 tag installed, and both tags must list each other in the linker domains configuration. This tool generates the correctly configured gtag.js snippet for both domains.

Common Use Cases

  • E-commerce with External Checkout: Main marketing site on one domain, Shopify or custom checkout on another.
  • SaaS with Separate App Domain: Marketing site at company.com, web app at app.company.com or dashboard.company.com.
  • Microsite Campaigns: A campaign landing page hosted on a separate domain that feeds conversions to your main analytics dashboard.
  • Partner Referral Tracking: Tracking users who arrive from a partner portal on a different domain to your conversion destination.

Frequently Asked Questions

Does this work with subdomains?

Not exactly the same. Subdomains (like shop.yoursite.com and blog.yoursite.com) still share the same apex domain cookie, so GA4 handles them automatically without cross-domain linking. Cross-domain linking is only necessary when crossing between completely different TLD registrations (e.g. yoursite.com to yourcheckout.io).

Can I configure this in the GA4 UI instead?

Yes, GA4 Admin lets you add cross-domain domains under Property Settings → Data Streams → Your stream → Configure tag settings → Configure your domains. However, generating the snippet directly in the gtag.js code (as this tool does) ensures the configuration is always applied, even if the Google Tag Manager setup changes or a developer overwrites the stream settings.

Does cross-domain tracking violate GDPR or CCPA?

Cross-domain tracking does not inherently violate privacy regulations - it simply preserves session continuity for users who have already consented to analytics tracking. However, your privacy policy must disclose tracking across domains you operate. Ensure your cookie consent banner applies to all linked domains before implementing.

Developer tools delivered free

Deep link guides, Open Graph tips, and new dev tools - straight to your inbox.