Limited Offer: Get 2 Months FREE on annual plans, or get Lifetime Plan Claim Offer

Menu

Cross-Domain Tracking Setup: Prevent Traffic Loss Across Subdomains and Payment Gateways

## Introduction Cross‑domain tracking is one of the most critical yet frequently misunderstood configurations in modern web analytics. When users navigate between your main site, a checkout subdomain, or a third‑party payment gateway, standard analytics implementations break the session. The result: an influx of direct / none traffic, inflated new user counts, and lost attribution for marketing campaigns. This guide provides a practical, evergreen approach to setting up cross‑domain tracking for GA4, with special attention to Shopify and payment gateways. ## Why Cross‑Domain Tracking Matters Every analytics platform relies on first‑party cookies to identify users. By default, a cookie set on `yoursite.com` cannot be read by `checkout.yoursite.com` or `secure.paymentgateway.com`. When users cross these boundaries, their client ID is lost, and a new cookie is created. GA4 (and Universal Analytics before it) interprets this as a brand‑new session, often from a direct source. This single technical glitch can distort your entire acquisition reporting, making it impossible to measure the true performance of your ad spend or SEO efforts. ## The Underlying Mechanism: How GA4 Passes Client ID Google Analytics 4 uses a URL parameter named `_gl` to stitch sessions across domains. When a user clicks a link from a configured origin domain to a destination domain, GA4 appends a query string like `?_gl=1*abc123*_ga*def456` to the link. On the destination page, the GA4 tag reads this parameter and restores the original client ID, ensuring the session remains intact. This process must be explicitly enabled for every domain pair you want to link. ## Step‑by‑Step Configuration via Google Tag Manager ### 1. Identify Your Domain Landscape Start by listing all domains involved in the user journey: the primary site (`example.com`), any subdomains (`blog.example.com`, `shop.example.com`), the checkout domain (often a subdomain like `checkout.example.com` or a separate domain like `pay.example.com`), and third‑party processors (`stripe.com`, `paypal.com`, `shopifypayments.com`). GA4 cross‑domain tracking works best when you have control over all listed domains; for third‑party gateways, you may need a different approach (discussed later). ### 2. Configure GA4 Tag Settings in GTM - Open your Google Tag Manager container. - Locate the GA4 Configuration tag (the one that fires on all pages). - In the tag settings, find the **Fields to Set** section and click **Add Row**. - Set **Field Name** to `cookie_domain` and **Value** to `auto` (or manually specify your top‑level domain). - Next, scroll to **Cross‑Domain Tracking**. Enter all domains that should share the same session, separated by commas (e.g., `example.com, checkout.example.com, pay.example.com`). Note that subdomains of the same root domain are often treated as the same entity in modern browsers, but explicitly listing them is a safe practice. ### 3. Decorate Links Automatically In the same GA4 Configuration tag, enable **Linker** settings: - Toggle **Use tag to automatically decorate links** to `true`. - This instructs GA4 to listen for clicks on links pointing to configured domains and append the `_gl` parameter automatically. The decoration happens on the fly when the link is clicked, so no manual URL rewriting is required. ### 4. Handle Redirects and Meta‑Refresh If your checkout flow uses server‑side redirects or meta‑refresh tags, automatic link decoration may fail. In such cases, you must manually add the `_gl` parameter to the redirect URL. For example, in your server code or Shopify Liquid template, you can dynamically append the parameter when sending the user to the payment gateway. Many platforms offer a `url` parameter that you can use to pass the full referrer information. ## Shopify‑Specific Considerations Shopify’s checkout process typically operates on a separate subdomain (`checkout.shopify.com` or a custom domain like `checkout.yourstore.com`). By default, Shopify adds its own analytics scripts, and interference can occur. To integrate GA4 cross‑domain tracking: 1. **Add your GA4 measurement ID to Shopify’s admin** (Online Store > Preferences > Google Analytics) and select “Use enhanced ecommerce.” This ensures the basic GA4 tag is loaded on the checkout pages. 2. **In GTM, list your Shopify checkout domain** in the cross‑domain tracking settings of the GA4 tag. Even if Shopify loads the tag natively, you need to ensure the linker parameter is accepted. 3. **Test the handoff** from the cart page to the checkout domain. Use browser developer tools and look for the `_gl` parameter in the URL of the checkout page. If it’s missing, your configuration needs adjustment. ### Payment Gateways and External Domains Many payment providers (Stripe, PayPal, Adyen) host their payment forms on their own domains. Because you do not control these domains, you cannot place a GA4 tag there to accept the `_gl` parameter. GA4 offers a solution via **referral exclusion** and **measurement protocol**, but the most reliable approach is to keep the user on a domain you control during the entire payment process. For Shopify merchants, Shopify Payments and Shop Pay achieve this by processing payment through a transparent redirect that stays on `checkout.yourstore.com`. If you must redirect to an external domain, consider using a “return URL” that passes order information back to your thank‑you page, where you can fire a purchase event via GA4 measurement protocol. ## Testing and Verification After setup, verify the flow works correctly: - Use **Google Tag Assistant** (Legacy or Companion browser extension) to record a full journey from a landing page through checkout. - In GA4’s **DebugView**, watch for the `_gl` parameter being recognized and the session staying unified. - Check the **Client ID** in cookies before and after a domain hop; they should match. - Review the **Attribution** reports in GA4 after 24–48 hours. Direct / none traffic should drop significantly for returning users. ## Common Pitfalls and Fixes - **Referral exclusion not working**: GA4 automatically excludes domains listed in the cross‑domain tracking configuration from showing as referral traffic. If you still see referral traffic from your own subdomains, double‑check that the domains are entered exactly as they appear in the URL (e.g., `yoursite.com` without `www` if you use a non‑www canonical). - **Multiple GA4 tags**: If you have both a GTM‑deployed GA4 tag and a hard‑coded GA4 tag, they may conflict. Choose one method and remove the other. - **Ad blockers**: Some users block the `_gl` parameter. This is unavoidable, but the percentage is usually small. Ensure your core tracking still works via server‑side alternatives if data accuracy is paramount. - **Dynamic subdomains**: If you use country‑specific subdomains (us.yoursite.com, uk.yoursite.com), include them all in the domain list or use a wildcard (not officially supported but many implementations work with `yoursite.com` as the root). ## Conclusion Cross‑domain tracking is not optional for any e‑commerce business that values accurate data. A properly configured setup prevents session fragmentation, ensures marketing attribution remains intact, and gives you a true picture of your customer journey. By following the steps above, you can eliminate the “direct / none” traffic spike that plagues so many analytics dashboards, turning fragmented data into a cohesive narrative—domain boundaries notwithstanding.
Last updated: Feb 27 2026
AI Assistant
Hi! 👋 You are viewing Cross-Domain Tracking Setup: Prevent Traffic Loss Across Subdomains and Payment Gateways. Need any help with this topic?