Cardinal Path’s response to COVID-19 Cardinal Path is sharing all we know to help marketers during COVID-19.  Learn more.

Installing Google Analytics on a site that uses multiple sub-domains requires some custom configuration to the tracking code.

For example, if you are installing GA on a site that has the following structure:

Main site: www.mydomain.com
Store: store.mydomain.com
Blog: blog.mydomain.com

If you install the default code that Google provides, you will not get accurate metrics. This is because, by default Google sets a first party cookie that is specifically for the domain that you're on. Metrics that can be affected include:

Visitors
Visits
Referrers -you'll get your own sub-domains being recorded as referrers.

The above site uses sub-domains for different areas of the site, so every time someone moves from www.mydomain.com to store.mydomain.com a new cookie will be set and the user will be counted as a new visitor.

Google has a way around this, you just need to tell it to set the cookie on the root domain. In this case: mydomain.com

For example, the default code that Google provides is something like the following.

If you are using urchin.js, the default code is as follows:

]]>

If you are using ga.js, the default code is as follows:

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”); document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E”)); ]]>

To allow this code to track a single user across sub-domains in a single Google Analytics profile, you need to add an entry to specify the root domain.

For urchin.js, you'll update the code to something similar to below. See the addition of the _udn variable where the domain is being set.

]]>

For the ga.js code, your code would look like the following. See the addition of the pageTracker._setDomainName() function:

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”); document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E”)); ]]>

In another post, we'll talk about how to track users between different domains.

Sharing is caring!

Popular

COVID-19 Crisis Navigator​

In partnership with Dentsu, Cardinal Path helps you distill the overwhelming news and information into a bi-weekly report highlighting emerging trends and insights during the pandemic.

EXPLORE THE REPORT

Analytics Rising Logo

FREE VIRTUAL EVENT

October 14

Practical Strategies Delivered By Top Minds in Digital Marketing

Register for #AnalyticsRising and get a Starbucks Gift Card when you share the news.

Message Sent

Thank you.

Click here to download access the tool.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Success!
Your message was received.

Thank you.

Message Sent

Thank you for registering.

Thank you for submitting the form.

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Thank you for your submission.

Message Sent

Thank you for registering.

Thank you for registering.​

Paid media spend by Government websites increased a whopping 139% YoY in 2020.

2020 Online Behavior Live Dashboard

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

2020 Online Behavior Live Dashboard

Message Sent

Thank you for registering.

Thank you for submitting the form.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Thank you for registering.

Cardinal Path is continuing with its series of free training. Next we are conducting training on Google Data Studio. Check it out here.
Cardinal Path hosted a live session to connect with you and answer all your questions on Google Analytics.
Get all the expertise and none of the consultancy fees in this not-to-be-missed, rapid-fire virtual event.

Message Sent

Success! Thank you
for reaching out.