1

I have a site, let's call it http://www.example.com with a non-universal Google analytics account.

Now we have to add new functionalities in a subdomain like https://subdomain.example.com as a micro site. On that subdomain the URL's will be something like https://subdomain.example.com?param1=foo&param2=bar

We can't change the requirements as both main site and mini-site use a different CMS/application. This is strictly a Google Analytics question.

But we need to count pageviews and events that happen in that subdomain (with URLs like https://subdomain.example.com?param1=foo&param2=bar) as belonging to the main domain. So pageviews and events in https://subdomain.example.com?param1=foo&param2=bar need to be recorded as if they happened in http://www.example.com/path/to/whatever/I/want

Fortunately we have full control on JavaScript in the main domain site and in the subdomain site too.

How can we make this work? Do we need to change tracking code both in the main domain and subdomains? Do we need to reconfigure Google Analytics?

Please note again that we do not want to create a new view for the subdomain. Both mini-site and main site should be in the same account, property and view.

1

Google has a help document for tracking multiple domains or subdomains in Google Analytics. It says that to track multiple subdomains you must use _setDomainName.

Using this function causes the Google Analytics cookies be written to the base domain. With out it, analytics cookies written by each subdomain are only visible to that subdomain and tracking between subdomains doesn't work.

Because it is changing how the cookies are written, you have to make this change on both the main site and the subdomain.

For your convenience, here is the traditional ga.js (not universal) that Google recommends for this scenario. You will have to set your tracking ID and domain name in it.

<script>
var pageTracker = _gat._getTracker('UA-12345-1');
pageTracker._setDomainName('example-petstore.com');
pageTracker._trackPageview();
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.