Cross-domain measurement makes it possible for Analytics to see sessions on two related sites (such as an e-commerce site and a separate shopping cart site) as a single session. This is sometimes called site linking.
To set up cross-domain measurement, you'll need to be comfortable editing HTML and JavaScript, or have help from an experienced web developer.
To measure sessions, Analytics collects a Client-ID value in every hit. Client-ID values are stored in cookies. Cookies are stored on a per-domain basis, and websites on one domain cannot access cookies set for another domain. When you measure sessions across multiple domains, the Client-ID value has to be transferred from one domain to the other. To do this, the Analytics code has linking features that allow the source domain to place the Client-ID in the URL parameters of a link, where the destination domain can access it.
Set up cross-domain measurement by modifying analytics.js
To set up cross-domain measurement for multiple top-level domains, you need to modify the Analytics code on each domain. You should have a basic knowledge of HTML and JavaScript or work with a developer to set up cross-domain measurement. The examples in this article use the Universal Analytics snippet (analytics.js).
- Set up a property in your Analytics account.
For cross-domain measurement, set up one property in your Analytics account. Use the same snippet and ID from that property for all of your domains. You need to edit the snippet for cross-domain measurement to work. If you haven’t already included the snippet on all your webpages, you might want to copy and paste it into a text editor before continuing with the instructions here. This way, you only have to make the changes once before including the modified snippet on all your webpages.
2. Edit the code for the primary domain
Find the create line in the snippet. For a website called example-1.com, it looks like this:
ga('create', 'UA-XXXXXXX-Y', 'example-1.com');
Make the following changes to the snippet (the changes you need to make are in bold red text):
ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['example-2.com']);
Remember to replace the example Google Analytics ID (UA-XXXXXX-Y) with your own ID, and replace the example secondary domain (example-2.com) with your own secondary domain name.
The snippet must contain these changes every place it appears on your primary domain.
For three or more domains
Follow the example above, but add the other domains to the autoLink plugin. Even the additional comma here is important:
ga('linker:autoLink', ['example-2.com', 'example-3.com' ] );
3. Edit the code on the secondary domain.
Find the create line in the snippet. Make the following changes to the snippet (the changes you need to make are in bold red text):
ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['example-1.com'] );
Remember to replace the example Google Analytics ID (UA-XXXXXX-Y) with your own ID, and replace the example primary domain (example-1.com) with your own primary domain name.
The snippet must contain these changes every place it appears on your secondary domain.
For three or more domains
Follow the example above, but add the other domains to the autoLink plugin. Even the additional comma here is important:
ga('linker:autoLink', ['example-1.com', 'example-3.com'] );
To learn more regarding this topic, please visit the official help guide:
https://support.google.com/analytics/answer/1034342?hl=en
If you use Google Tag Manager, follow the instructions here:
https://support.google.com/tagmanager/answer/6164469?visit_id=637032080419091919-1906179095&rd=1
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article