Mobile app version of vmapp.org
Login or Join
Odierno851

: Tracking subdomains in the same profile as the main domain 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

@Odierno851

Posted in: #GoogleAnalytics

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

Now we have to add new functionalities in a subdomain like subdomain.example.com as a micro site. On that subdomain the URL's will be something like 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 subdomain.example.com?param1=foo&param2=bar) as belonging to the main domain. So pageviews and events in subdomain.example.com?param1=foo&param2=bar need to be recorded as if they happened in 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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Odierno851

1 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

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>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme