Table of Contents
TogglePrerequisites
Before you begin, ensure you have:
- Access to Google Analytics: You should have administrator access to the Google Analytics account where you want to set up cross-domain tracking.
- Edit Access to Website Code: Ability to edit the Google Analytics tracking code (or use Google Tag Manager) on all domains/subdomains you want to track.
Step-by-Step Guide to Set Up Cross-Domain Tracking
1. Update Google Analytics Tracking Code
- Determine Domains/Subdomains:
- Identify all domains and subdomains that you want to track as part of a single user journey.
- Modify Tracking Code:
- Locate your Google Analytics tracking code snippet (usually found in the
<head>
section of your website’s HTML).
- Locate your Google Analytics tracking code snippet (usually found in the
- Add
allowLinker
Parameter:- Add the
allowLinker
parameter to the tracking code on all pages of all domains/subdomains. - This parameter allows cookies to be shared across domains/subdomains.
Example for Universal Analytics (gtag.js):
html<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXX-Y"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());gtag('config', 'UA-XXXXX-Y', {
</script>
'linker': {
'domains': ['example.com', 'subdomain.example.com']
}
});
- Replace
UA-XXXXX-Y
with your Google Analytics property ID. - Replace
example.com
andsubdomain.example.com
with your actual domains/subdomains.
Example for Classic Analytics (ga.js):
html<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-Y']);
_gaq.push(['_setDomainName', 'example.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);(function() {
</script>
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
- Replace
UA-XXXXX-Y
with your Google Analytics property ID. - Replace
example.com
with your primary domain.
- Add the
2. Set Up Referral Exclusions (if needed)
- Navigate to Admin Settings in Google Analytics:
- Click on the Admin cogwheel icon (bottom left).
- Select Property Settings:
- Under the Property column, click on “Property Settings.”
- Exclude Referrals:
- Add domains/subdomains to the “Referral Exclusion List” if you want sessions from these domains/subdomains to be treated as part of the same user journey.
- This prevents new sessions from being created when users move between specified domains/subdomains.
3. Test and Verify
- Verify Implementation:
- Use Google Analytics Real-Time reports or Tag Assistant (Chrome extension) to verify that sessions are tracked correctly across domains/subdomains.
- Ensure that session continuity is maintained as users navigate between different domains/subdomains.
4. Monitor and Adjust (if needed)
- Review Reports:
- Monitor Google Analytics reports (e.g., Audience, Acquisition, Behavior) to ensure cross-domain tracking is functioning as expected.
- Check for any discrepancies or issues in session data across domains/subdomains.
- Troubleshoot:
- If there are issues, review the implementation steps, check for correct parameter usage (
allowLinker
), and ensure cookies are being shared correctly. - Adjust tracking code or settings as necessary based on testing and monitoring results.
- If there are issues, review the implementation steps, check for correct parameter usage (
Additional Tips
- Use Google Tag Manager: If you prefer using Google Tag Manager, configure cross-domain tracking using GTM by setting up Cross-Domain Tracking variables and tags.
- Multiple Subdomains: For multiple subdomains, ensure each subdomain’s tracking code includes the
allowLinker
parameter with the parent domain/subdomain listed in thedomains
array. - Data Sampling: Depending on your Google Analytics account type, cross-domain tracking may lead to data sampling if traffic volumes are high. Monitor sampling levels in reports.
By following these steps and ensuring correct implementation of cross-domain tracking in Google Analytics, you can accurately track user behavior across multiple domains and subdomains, gaining comprehensive insights into user journeys and interactions across your digital properties.