How to set up cross-domain tracking with Google Tag Manager

Author:

Setting up cross-domain tracking with Google Tag Manager (GTM) allows you to track user sessions that span multiple domains in Google Analytics (GA). This is crucial for websites that involve multiple domains or subdomains where users move between them during a session. Here’s a step-by-step guide on how to set up cross-domain tracking using GTM and GA:

Prerequisites

Before starting, ensure you have:

  1. Google Analytics and Google Tag Manager accounts set up.
  2. Basic familiarity with GTM and GA interfaces.
  3. Access to edit and publish changes to your website’s GTM container.
  4. Understand the domains and subdomains you need to track across.

Step-by-Step Guide to Set Up Cross-Domain Tracking

Step 1: Update Google Analytics Settings

  1. Log in to Google Analytics:
    • Go to your GA account and select the property you want to configure cross-domain tracking for.
  2. Configure Referral Exclusion List (if needed):
    • In GA, navigate to Admin (bottom-left corner).
    • Under Property, click on Tracking Info and then Referral Exclusion List.
    • Add domains that should not trigger new sessions when users move between them (e.g., payment gateways).

Step 2: Update Google Tag Manager Settings

  1. Log in to Google Tag Manager:
    • Open your GTM workspace.
  2. Create a New Variable for Domains:
    • Go to Variables and click New to create a new user-defined variable.
    • Name it something like “Cross Domain Auto Linker”.
    • Choose Variable Type as Auto Link Domains.
    • Enter the domains you want to track across (e.g., example.com, example.net).
    • Save the variable.
  3. Configure Google Analytics Settings Variable:
    • Go to Variables and click on your existing Google Analytics Settings variable.
    • Under More Settings > Fields to Set, add a new field:
      • Field Name: allowLinker
      • Value: true
    • Save the variable.
  4. Create Cross-Domain Tracking Trigger:
    • Go to Triggers and click New.
    • Name the trigger (e.g., “Cross-Domain Link Clicks”).
    • Choose Trigger Type as Just Links.
    • Configure as follows:
      • This trigger fires on: Some Link Clicks
      • Fire this trigger when an Event occurs:
        • Click URL matches RegEx ^(https?:\/\/(?:example\.com|example\.net)\/.*)$
      • Replace example\.com|example\.net with your actual domains and subdomains.
    • Save the trigger.

Step 3: Update Links with GTM Auto Linker

  1. Modify Links on Your Website:
    • For each link that should trigger cross-domain tracking, add the rel="noopener" attribute to the <a> tag or set target="_blank" if the link opens in a new tab. For example:
      html
      <a href="https://example.com/page" rel="noopener">Link Text</a>
    • Ensure that all links between domains/subdomains are updated with this attribute.

Step 4: Test and Publish

  1. Test in Preview Mode:
    • Click Preview in GTM to test your changes.
    • Navigate between domains/subdomains and verify in the Real-Time reports in GA that sessions are maintained across domains.
  2. Publish Your Changes:
    • Once testing is successful, click Submit in GTM to publish your container changes.

Verification and Troubleshooting

  • Real-Time Reports in GA: Use GA’s real-time reports to verify that sessions persist as users navigate across domains/subdomains.
  • Debugging Tools: Use browser developer tools (like Chrome DevTools) to inspect network requests and ensure the GA cookies (_ga, _gid, etc.) are being passed correctly.

Conclusion

Setting up cross-domain tracking with Google Tag Manager and Google Analytics allows you to accurately track user behavior across multiple domains or subdomains within a single session. By implementing the steps outlined above, you can ensure seamless tracking and gain comprehensive insights into user interactions across your entire web presence.