Table of Contents
A common confusion is between cross-domain tracking and tracking cross-subdomain tracking.
The analytics.js library uses a unique client ID to determine whether a user is new or returning. A user is considered returning visitor if a hit with a matching client ID has already been sent to the same property.
The client ID is stored in the browser’s cookies by default, which pages on the same domain can only access.
To share a client ID across domains, you can append it as a query parameter to URLs that point from the current domain (the source domain) to the destination domain that you want to track. The shared ClientID allows multiple domains to share a cookie and track the unique user across different domains.
Here is a link that allows you to look into this in more detail. Cross-domain tracking via Google.
Now for tracking subdomains, I recommend executing this through Gooogle Tag Manager.
Set-Cookie Domain to ‘auto.’ This is a default setting for Universal Analytics, but if you’re using Google Tag Manager, you have to set it within GTM explicitly. This setup allows the hits from different subdomains to share one cookie.
Go to your Google Analytics Admin panel and set up your domain under the referral exclusion list.
When Google Analytics sees a new referrer different from a source and medium, it will start a new session with the latest traffic source info. The Referral Exclusion List prevents this and will let the original session continue.
To track subdomains within the same profile as the primary domain, you must add an extra line to every page with the tracking code. Assuming your primary domain is “.your-site.com,” the following is the line you will need to add:
pageTracker._setDomainName(“.your-site.com”);For example, it will look like this…
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
As a result, Google Analytics will throw the following results for each of these URLs.
- www.your-site.com/default.html –> /default.html
- shop.your-site.com/info.html –> /info.html
If you want to distinguish between your subdomains, you’ll need to create an “Advanced Filter” for your profile.
Filter Type: Custom filter > Advanced
Field A: Hostname
Extract A: (.*)
Field B: Request URI
Extract B: (.*)
Output To: Request URI
Now, the results for the above examples will look like:
- www.your-site.com/default.html –> www.your-site.com/default.html
- shop.your-site.com/info.html –> shop.your-site.com/info.html
Thank you so much for taking the time to read my content. If you've liked what I've had to say please subscribe!
Join the newsletter to receive the latest updates in your inbox.