Cross domain tracking with Google Tag Manager is an excellent way to ensure you don’t lose Google Analytics data when users move between your different domains during the same session. This post will cover the set up steps, with relevant screenshots to make sure your implementation is a success. If any part of this post is unclear, feel free to leave a comment.
There are two methods to track cross-domain activity: Using 1. Auto Link Domains or 2. Form/Link Decorator Tags. We’re using 2 here.
The Problem Scenario
We needed to configure cross domain tracking for a hotel client and decided to use Google Tag Manager to do it with relative ease. Our problem scenario went like this:
- A user browses for a hotel room on the website at Domain A
- Selecting a hotel room on Domain A sends users to a third-party booking engine site, Domain B
- Source / Medium data in Google Analytics would be dropped once the user moved to Domain B, becoming (direct) / (none), even though Google Analytics was installed on both domains
Without source/medium data, we were unable to track our marketing efforts.
Our article hopes to explain how we solved cross-domain tracking with Google Tag Manager, with these additional factors to watch out for:
- Form submit data needs to be carried from Domain A to Domain B
- Domain B uses multiple subdomains
- Domain A and Domain B use different containers
1. Install Google Tag Manager on both domains
Google Tag Manager (GTM) makes it easy to consolidate and manage multiple tags within one “container”, without having to modify site code.
Open a container and install the code immediately after the opening <body> tag on your sites. Be sure to remove your existing GA tag, because now it will be contained within GTM.
I recommend you install Google Tag Assistant for Chrome if you haven’t already. Its great for quickly checking if website tags are firing properly.
2. In Google Analytics, add both domains to the referral exclusion list
Referral exclusions tells Google Analytics to record sessions as if they are from the same website, even though we’re using separate domains. The primary domain will be listed there by default.
Note: travelclick.com and ihotelier.com use a few different sub-domains (ie: booking.ihotelier.com and reservations.ihotelier.com). By adding the root domain we are covering any and all sub-domains. If you are targeting ONLY a specific sub-domain, include the subdomain(s) instead of the root.
Note 2: Our referral exclusion list for this property also now includes travelclick.com (their new booking engine)
3. Modify your Universal Analytics Page View Tags in Google Tag Manager
This is what needs modified on your Universal Analytics tag.
allowLinker : true
cookieDomain : auto
Auto Link Domains : podollanhotels.com,travelclick.com,ihotelier.com
Note: This tag by default will fire on ‘All Pages’. Don’t modify that unless you have specific reason to.
Note 2: We’re using two separate GTM Containers. Make sure each Page View tag in each container you’re using has the same configuration.
4. Set Up Link Decorator
Create a trigger and choose Just Links as the trigger type. Enable this tag for when the url contains Domain A and for when click target contains Domain B, Domain C, etc
Next, Add a Google Analytics tag to your GTM container. Select Track Type “Decorate Link”. Select the click trigger you just created under “Triggering”.
5. Set Up Form Decorator
If your site submits a form to another domain, we also need to decorate forms with Google Analytics cookie data.
Create a trigger that uses forms. You may have to use different settings than this depending on your form setup. I used our form’s ID to ensure only this form decorates links.
Next, Add a Google Analytics tag to your GTM container. Select Track Type “Decorate Form”. Set the trigger to the form trigger you just created under “triggering”.
6. Confirm cross domain tracking setup in real-time Analytics
We want to confirm that the information about the user session is preserved across both domains. To test this add some UTM tags to your URL to identify your session in real time analytics.
For this example I added the string “/?utm_source=x-domain_test&utm_medium=x-domain_test” to my Domain A URL
Click “x-domain_test” Medium link, then content to view the current page for that session. Continue to navigate that session to the 2nd domain and note how the session has preserved its “Medium/Source” data.
Now when your traffic converts on a 3rd party booking engine you will be able to see attribution from all traffic sources.
That’s it for cross domain tracking setup. Let us know if you have any questions below!