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.
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 atapp.company.comordashboard.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.
Related Tools
Explore other free tools to build, test, and optimize your links and QR codes.
Barcode (1D)
Generate, preview, and download 1D barcodes (Code128, EAN-13, UPC, etc.) instantly in your browser.
Smart App Deep Link
Generate smart routing scripts that detect the user OS and redirect to native mobile apps falling back to web URLs.
HTML Link
Generate clean, perfectly formatted HTML anchor tags with custom rel, target, class, and ID attributes.
Open Graph Meta Tag
Generate the perfect Open Graph and Twitter Card HTML meta tags for social media link sharing optimization.
Amazon Affiliate Link Builder
Clean up messy Amazon URLs and generate perfect Associate links using your affiliate tag.
Link Expirator & Countdown Snippet
Generate a Javascript snippet to automatically expire a link and redirect traffic after a specific date and time.