Tracking multiple websites with Google Analytics is easy. Just add the same tracking code snippet to your websites' pages (or use GTM) and you can see data for two websites in your GA reports - check the Hostname dimension if you don't believe it!
This can be useful if, let's say your website's shop hostname is www.mybusiness.com, and you redirect your customers to checkout.mybusinessshop.com to complete their purchase. Placing Google Analytics code on both domains will send the data covering the whole customer experience on your digital properties. That's what we want, right? However, you will quickly discover that all your transactions have the same session source which is www.mybusiness.com / referral. This makes perfect sense as people only visit your checkout domain using the links on your original domain. But this hides the real traffic source! How can you quantify your marketing efforts per acquisition channel?
Google Analytics Cross-Domain Tracking comes to the rescue. You need to tell Google Analytics that the customer experience on these two hostnames needs to be consolidated into a single Session and treated accordingly.
Cross-Domain Tracking setup checklist
- Make sure your cookieDomain field is set to auto. If you are not sure - just set it to auto and let GA handle it (see Cross-Domain Tracking for subdomains section below).
If you do know what this is for - then I am sure you are using it the right way!
- Make sure you are using the autolinker plugin. This Google Analytics plugin provided by Google adds a few characters to the link to make sure Google Analytics "recognises" and consolidates sessions between websites
- The plugin needs to be explicitly told which domain names to use, for example:
- GTM configuration follows similar logic
- Make sure you list all the hostnames in the Google Analytics Property settings: Referral Exclusion List
- That's it!
Google Analytics Cross-Domain Tracking for subdomains
If you would like to consolidate customer experience on two subdomains, for example: www.mybusiness.com and shop.mybusiness.com, the good news is that it is done automatically for you! You just need to use the recommended Google Analytics code snippet which sets the cookieDomain field to auto. If you have modified the GA code snippet or are using GTM to tag your website, please make sure you manually set the cookieDomain field to auto.
A little bit more technical spice
Above, I have briefly explained what Google Analytics Cross-Domain Tracking is and how to use it. The implementation is pretty straightforward and widely covered on the Internet. In most cases, you would use the autolinker plugin to work its magic. The core of the Cross-domain Tracking is a parameter and its value added to the destination URL (query string). The parameter may look like this:
_ga=1.199239214.1624002396.1440697407. Once the user reaches the second domain, GA code on the page will read the parameter, "recognise" the user and consolidate the session. If the link domain (hostname) matches the pattern specified in the plugin configuration, the autolinker plugin automatically adds this parameter.
A little trick here is that hostname matching is done using the substring, so specifying the mybusiness.com would match both www.mybusiness.com and shop.mybusiness.com. Which is convenient - less typing.
Excluding hostnames from cross-domain tracking
Recently, I had a client with lots of subdomains and requirements, mature enough to implement the Cross-Domain Tracking for all of them except for a few. Data still had to be sent to the same GA property, but user experience on these subdomains was not be consolidated and left as separate sessions. There were 50+subdomains and an obvious solutionwasto list them all explicitly (remembering that autolinker plugin matches hostname by substring) and NOT listing hostnames which need to be excluded on every page. However this solution had lots of drawbacks. Another option was to implement manual linkage or in terms of the Cross-Domain Tracking to decorate links (generate and append _ga parameter to the link URL). The hacker inside me insisted on injecting my code (installing a hook) into the autolinker plugin with a custom hostname matching logic.
But before doing so, I did a little digging, actually read the documentation and paid proper attention. Guess what? I discovered that the autolinker plugin actually expects Regular Expressions and not just a string as a parameter!
All that was left was to create a negative match Regular Expression to tell Google Analytics Cross Domain Tracking NOT to track specific hostname. Consider the Regular Expression below:
This will match mymegabusiness.com.au, checkout.mybusinessshop.com.au and any subdomain of the mybusiness.com except for ignore.mybusiness.com.au
So the resulting Google Analytics autolinker plugin configuration looked like this:
ga('linker:autoLink', [/^(?!ignore\.)(.*)mybusiness\.com\.au|(mymegabusiness\.com\.au)|(checkout\.mybusinessshop\.com\.au)/gi, 'destination.com.au');
Works like a charm. Lesson learned - now I pay more attention to the documentation!
Need help with your Google Analytics? Talk to us.
Pick up the phone, Live Chat, or email us if you would like us to share our Google Analytics skills, case studies, and knowledge to achieve your business goals and targets.
Internetrix combines digital consulting with winning website design, smart website development and strong digital analytics and digital marketing skills to drive revenue or cut costs for our clients. We deliver web-based consulting, development and performance projects to customers across the Asia Pacific ranging from small business sole traders to ASX listed businesses and all levels of Australian government.