Setting up cross-domain tracking using Google Tag Manager
Last Updated / Reviewed: Jan 10th, 2023
Execution Time: 15-30 minutes
Goal: To correctly implement and test cross-domain tracking in Google Analytics.
Ideal Outcome: You will be able to correctly collect all the traffic data that comes to the domains that are under your control and analyze how users interact across them.
Pre-requisites or requirements:
- To follow this SOP you will need to have installed Google Tag Manager on all your domains. If you haven’t done so already and you are using WordPress you can follow SOP 004.
- You will also need to have Google Analytics running on all your domains. if you don’t have it yet, you can follow the steps described in SOP 009.
Why this is important: Cross domain tracking makes it possible to unify what would otherwise be considered as two (or more) separate sessions that occur under two (or more) of your domains.
The specific steps on this SOP apply only to Universal Google Analytics (not Google Analytics 4). If you followed other NexLvL SOPs to create your Google Analytics account or if you set up Google Analytics before October 2020 you most likely have a Universal Analytics property.
Where this is done: In Google Tag Manager and Google Analytics.
When this is done: When you add a new domain to your business that you want to track under the same Google Analytics property.
Who does this: The person responsible for website management or analytics.
SOP Update: Google Analytics 4
💡 Note: Google has released a new version of Google Analytics in October 2020, this new version can be set as a property alongside standard version “Universal Analytics”. The “Universal Analytics” properties will likely be supported by Google for years to come. Currently, all NexLvL SOPs support Universal Analytics exclusively.
To make sure you can follow this step-by-step SOP make sure you have selected the Universal Analytics property once your Google Analytics account has been created.
- On the top left corner click on the Account Dropdown and select a view within your Universal Analytics property (Not the GA4 property):
💡 Note: You can identify your Universal Analytics property by noticing the ‘UA-’ prefix in the Property ID below its name.
Setting up Cross-domain tracking
Important:
- Some specific cases are outside of the scope of this SOP. If you’re using redirects between your domains, if your code is removing parameters from the URLs, or if you are using iframes this might not work for you.
- This SOP assumes you already have the same Google Analytics property set up in both domains.
Important #2: If you don’t have Google Tag Manager set up on your website, you will want to follow the procedure covered in SOP 004 - Add Google Tag Manager to a Wordpress Site
- Go to http://tagmanager.google.com and sign in with your account details.
- Select the container that is set up on your website.
- Note: This SOP assumes you’re using the same container in both domains. If that is not the case you will need to perform these steps twice, one time for each of the containers.
3. Click “Variables” → “New”
4. Rename the variable
5. Click “Choose a variable type to begin set-up…” → “Constant”
6. Type the domains you will want to link, separated by commas.
- Note: If you want to setup cross-domain tracking for all the domains and subdomains you only need to input your main domain. If you only want to implement cross-domain tracking between a few subdomains you should enter your subdomains instead.
Example:
- [http://asiteaboutemojis.com , anothersiteaboutemojis.com] will work for all these cases:
- User arrives at http://asiteaboutemojis.com and clicks a link to anothersiteaboutemojis.com;
- User arrives at shop.asiteaboutemojis.com and clicks a link to tools.anothersiteaboutemojis.com;
- [shop.asiteaboutemojis.com, course.anothersiteaboutemojis.com] will implement cross-domain tracking for this case:
- User arrives at shop.asiteaboutemojis.com and clicks a link to course.anothersiteaboutemojis.com;
But will not work for:
- User arrives at http://asiteaboutemojis.com and clicks a link to anothersiteaboutemojis.com;
7. Click “Save”:
8. Locate your Google Analytics settings variable, in your list of variables. It should have its type set to “Google Analytics settings”. Click that variable.
a. Note: If you can’t find this variable your setup might not be using it. If that is the case it is recommended that you start using it. You can refer back to SOP 009 to understand how you can configure your variable.
9. Click “More Settings” → “Cross Domain Tracking”:
10. In the field “Auto Link Domains” click the “+” icon and select the variable you’ve just created in Step 4 of this SOP.
11. Set the field “Decorate Forms” to “True”.
12. Still under “More Settings” → click “Fields to Set” → “+ Add Field”:
13. Add these settings:
a. Field Name: allowLinker
b. Value: true
14. Click “Save” on the top right corner:
15. If you now click on “Overview” on the sidebar, this is how your Google Tag Manager overview dashboard should look like:
16. If everything looks ok, you are now ready to hit “Submit”
17. In the “Submission Configuration” panel you will be given the chance to add a name and description to this version. After you have done so, hit “Publish”.
a. Note: Adding a name and description is optional but recommended. You should enter information here that will make it easy to know what changes are being made.
18. That’s it! You will now be taken to see the summary of the changes you’ve just made:
Adding your new domain to the referral exclusion list:
- Open your Google Analytics account settings by clicking here or clicking “Admin” in the sidebar.
- Select the correct Google Analytics Account and Property
3. Click “Tracking Info” → “Referral Exclusion List”
4. You should see your root domain on the list:
5. Click “+Add Referral Exclusion”
6. Type your new domain, eg: yournewdomain.com
7. Click “Create”, and that’s it! You should now see your other domain in the Referral Exclusion List:
Checking if cross-domain tracking is working as intended
- Open your website using Chrome and navigate to one of the pages in your first
- Click on the Google Tag Assistant Chrome extension and click “Record”:
3. Refresh your page.
4. Click any link pointing to your second domain.
- Note: Make sure the link you are clicking on opens in the same tab and not a new one, otherwise the Google Tag Assistant recording might not record you whole session.
- Note 2: You should see a “_ga” parameter being added to the URL.
5. Once the page loads click again on the Google Tag Assistant Chrome extension and click “Stop Recording” and then click “Show Full Report”:
6. Select “Google Analytics Report”:
7. Select the view that you want to test and click “Ok”:
8. Check the “Alerts” section and make sure you’re not seeing an alert regarding the Cross Domain implementation.
- Note: This is how an alert would look like If you had one:
9. Scroll down in the report until you find the “Flow” section. You should see at least 2 Page loads there:
- Click “Page load 1” → The “URL” field should be an URL belonging to your first domain.
- Click “Page load 2” → The “URL” field should be an URL belonging to your second domain.
10. That’s it, if everything looks good your property will start collecting data correctly from both domains.
Adding a Hostname filter to include your subdomain data
Note: This is an optional step and depending on your current Google Analytics setup it might impact other configurations such as custom reports and goals.
- Log In to your Google Analytics account.
- Check If you already have a filter implemented, you can do so under filters, or by heading over to Behaviour → Site Content → All pages.
- If you have the standard set up you will see the page path in the reports:
- Note: By default Google Analytics will aggregate data from all the domains and subdomains, so you should bear in mind that in fact the page “/” is not only your main domain’s homepage but also the homepage of all your domains and subdomains being tracked by the same property if their homepages are also in the root of the subdomain.
4. If you want to display the domain and subdomain information on your reports straight away, you can follow SOP 035 - Displaying subdomains in your Google Analytics Reports.
5. That’s it. By the end of the SOP you will be seeing the domain and subdomain information straight on your reports: