Skip to content
English
  • There are no suggestions because the search field is empty.

How to Set up cross-domain tracking with GTM

Goal
To correctly implement and test cross-domain tracking in Google Analytics 4.
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.
Prerequisites 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 (web version).
  • 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 (web version).
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 ClickMinded 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
Google Analytics 4
When is this 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.

Setting up Cross-domain tracking

  1. Go to your GA4 account and sign in with your account details.

  2. On the left navigation menu, click ‘Admin’ on your bottom left.

  1. Next, click ‘Data Streams’.

  1. Click ‘Add Stream’, select ‘Website’ and enter your domain after.

Important: You should ensure that all the websites you want to enable cross-domain tracking are connected or shared within the same data stream. This means that all of these websites should use the same measurement ID and tracking code, typically provided by Google Analytics 4 (GA) for tracking purposes.


So, whether you have two, three, four, five, or even ten websites, they should all be configured to use the same measurement ID and tracking code. This way, you can effectively implement cross-domain tracking and collect consistent data across all these websites within a single data stream.


RECENT UPDATE: YOU DO NOT NEED CROSS-DOMAIN TRACKING FOR SUBDOMAINS OF THE SAME DOMAIN


If you are dealing with subdomains like:


  • www.example.com

  • blog.example.com

  • support.example.com


Then you DO NOT need to implement cross-domain tracking because all of them belong to the same example.com domain


However, you WILL HAVE to implement cross-domain tracking if you’re working with separate domains, e.g.:


  • www.mainwebsite.com

  • blog.example.com

  • support.someotherdomain.com


  1. Once you have added a stream, click on it and scroll down to ‘Google Tag’ and click ‘Google tag settings’.

  2. Next, click ‘Configure your domains’.

  1. Click ‘Add condition’ and enter your domain. You can add multiple match types based on the drop-down menu. Add each domain you want to include in the cross-domain measurement:

  1. Remember to hit ‘Save’ on your top right corner and that’s it!

Adding your new domain to the referral exclusion list:

Validate if the source domain should be included in the referral exclusion list in Google Analytics 4 settings so that Google considers it as direct traffic. If your source domain is not added, then Google records this traffic as having originated from source/referral.


  1. Open your Google Analytics 4 account settings by clicking here or clicking 'Admin' in the sidebar.

  2. Select the correct Google Analytics 4 Account and Property

  1. Click 'Tracking Info' → 'Referral Exclusion List'

  1. You should see your root domain on the list:

  1. Click '+Add Referral Exclusion'

  2. Type your new domain:

  1. Click 'Create', and that’s it! You should now see your other domain in the Referral Exclusion List:

 

Check if cross-domain tracking is working as intended

The final result should look like this:

After saving, give it a minute or so before visiting your initial website, which we'll call domainA.com. Within domainA.com, locate a link that directs visitors to domainB.com.

Click on this link. Once you're redirected to the second domain, inspect the URL. You should observe the presence of the _gl= parameter along with a significant amount of information.

  1. Go to your GA4 account and sign in with your account details.

  2. On the left navigation menu, click ‘Admin’ on your bottom left.

  1. Under ‘Property’, click on ‘Tracking Info’ followed by ‘Tracking Code’.

  1. By selecting the tracking code, it will reveal your tracking or property ID in the console.

  2. Add Google Tag Assistant Chrome Extension to your browser.

  3. Refresh your page and click on the tag assistant extension and check the property ID.

  1. Follow the same steps for the destination domain and check if the property ID is the same.


  1. 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 your whole session.

  2. Note 2: You should see a '_ga' parameter being added to the URL.


  1. Alternatively, once the page loads click again on the Google Tag Assistant Chrome extension and click 'Stop Recording' and then click 'Show Full Report':

  1. Select 'Google Analytics 4 Report':

  1. Select the view that you want to test and click 'Ok':

  1. Check the 'Alerts' section and make sure you’re not seeing an alert regarding the Cross Domain implementation.


  1. Note: This is how an alert would look like If you had one:


  1. Scroll down in the report until you find the 'Flow' section. You should see at least 2 Page loads there:

    1. Click 'Page load 1' → The 'URL' field should be an URL belonging to your first domain.

    2. Click 'Page load 2' → The 'URL' field should be an URL belonging to your second domain.


  1. You can also validate the same using the 'Inspector' tool. Simply right click on the page and select 'inspector'. In the network console, filter for collect in the header you would see the property ID shown as below.

  2. That’s it, if everything looks good your property will start collecting data correctly from both domains.