Setting up cross-domain tracking with Google Tag Manager (GTM) is essential for tracking users as they navigate between different domains (e.g., from your main website to a payment or third-party domain). This allows you to maintain a consistent view of user interactions and ensure accurate reporting in Google Analytics. Here’s a step-by-step guide on how to configure cross-domain tracking using GTM.
Step 1: Prepare Your Domains
- Identify Your Domains: Determine the domains that need to share tracking data. For example, if you have a main website (e.g.,
example.com
) and a checkout domain (e.g.,checkout.example.com
), both need to be included in the tracking setup. - Use Same Google Analytics Property: Ensure that both domains are set up under the same Google Analytics property to consolidate data effectively.
Step 2: Set Up Google Tag Manager
- Log in to Google Tag Manager: Access your GTM account and select the container for your website.
- Create a New Variable for the Auto Link Domains:
- In the left sidebar, click on Variables.
- Under User-Defined Variables, click on New.
- Choose Variable Configuration and select Auto Link Domains.
- In the Domains field, enter the domains you want to track (e.g.,
checkout.example.com, example.com
), separated by commas. - Name this variable (e.g., “Auto Link Domains”) and click Save.
Step 3: Configure Google Analytics Settings Variable
- Create or Edit Google Analytics Settings Variable:
- Go to Variables in the left sidebar.
- Under User-Defined Variables, click on New (or edit an existing Google Analytics Settings variable if you have one).
- Choose Variable Configuration and select Google Analytics Settings.
- Fill in Tracking ID and Enable Cross-Domain Tracking:
- Enter your Google Analytics Tracking ID (e.g.,
UA-XXXXXX-Y
). - Enable Cross Domain Tracking by checking the box.
- In the Auto Link Domains field, reference the variable you created earlier (e.g.,
{{Auto Link Domains}}
). - Enable Allow Linker: Check this option to allow Google Analytics to append the linker parameter to the URLs.
- Enter your Google Analytics Tracking ID (e.g.,
- Save the Variable: Click Save to save your settings.
Step 4: Set Up Tags for Page Views
- Create or Edit the Google Analytics Page View Tag:
- Go to Tags in the left sidebar and either create a new tag or edit your existing Google Analytics Page View tag.
- Configure the Tag:
- Click on Tag Configuration and select Google Analytics: Universal Analytics (or GA4 Configuration if you’re using Google Analytics 4).
- Set the Track Type to Page View.
- In the Google Analytics Settings field, select the settings variable you configured earlier.
- Set Triggering:
- Click on Triggering and select your main page view trigger (typically All Pages).
- Save the Tag: Click Save to save your changes.
Step 5: Configure Linker on Payment Domain
- Add the Linker Parameter on Payment Domain:
- If you have a separate payment or checkout domain, ensure that the Google Tag Manager setup on that domain also includes a Google Analytics tag configured similarly to maintain cross-domain tracking.
- Create a Tag for the Payment Domain:
- Follow the same steps to create a Google Analytics tag for the payment domain as you did for the main site.
- Ensure you set the Auto Link Domains variable to include your main domain.
Step 6: Update Links Between Domains
To ensure that the linker parameters are added to links that navigate between your main site and payment site, you will need to modify the links as follows:
- Update Links on the Main Domain:
- Ensure all links that lead to the payment domain include the linker parameter. This is typically done automatically by Google Analytics when configured correctly with the linker setup.
- Check Link Formatting:
- Make sure links to your checkout or payment domain are correctly formatted as
https://checkout.example.com
. The linker parameters will be added dynamically.
- Make sure links to your checkout or payment domain are correctly formatted as
Step 7: Test Your Setup
- Use Preview Mode in GTM:
- Click the Preview button in Google Tag Manager to enter debug mode.
- Navigate Between Domains:
- Visit your main website and click on links that lead to the payment domain.
- Check the GTM debug panel to ensure that the page view tags fire correctly and that linker parameters are appended to the URLs.
- Verify Google Analytics Real-Time Reports:
- Open Google Analytics in another tab and navigate to the Real-Time reports.
- Confirm that the sessions are tracked across both domains correctly.
Step 8: Publish Your Changes
- Submit Your Changes:
- If everything is functioning correctly in the preview mode, click on the Submit button in GTM to publish your changes.
- Add a Version Name:
- Provide a version name and description to document the changes made.
Additional Considerations
- Cookie Domain Configuration: If you have specific cookie configurations for your domains, ensure that they are set up to allow cross-domain tracking.
- Test on Different Browsers: Always test your cross-domain tracking across different browsers to ensure it works as expected.
- Consider Enhanced E-commerce: If applicable, consider implementing Enhanced E-commerce tracking for more detailed insights.
Conclusion
Setting up cross-domain tracking with Google Tag Manager is crucial for understanding user journeys across different domains. By following these steps, you can ensure that user interactions are tracked seamlessly, providing valuable insights into your website’s performance and user behavior. Regular testing and monitoring will help maintain accurate tracking and data integrity across your domains.