Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics cookies vs subdomain for static content

I have a website on www.example.com and use Google Analytics. I've also set up static.example.com which serves all static content.

The problem is that the default behavior of GA is to issue cookies on ".example.com" but I don't want the static content traffic to be carrying the weight the GA cookies.

I tried pageTracker._setDomainName("none"); and it worked well for the cookies problem but it completely messed up the "Avg. Time on Site" report (from 5 mins average it went to 40 mins until the day I reverted the _setDomainName call).

Any idea why this is happening and how could I fix it?

like image 479
cherouvim Avatar asked Aug 16 '09 14:08

cherouvim


People also ask

Does Google Analytics work on subdomains?

GA4 also automatically handles subdomains. If you are working with a business that operates on multiple subdomains (e.g. blog.business.com, support.business.com, www.business.com, etc.), you will most likely want to track website visitors with Google Analytics across all these websites.

Do you need cross domain tracking for subdomains?

If you have the same tracking code installed on multiple domains and you want to track a single user as they visit those domains, you need cross-domain tracking. BUT if you have a single domain with multiple subdomains, you don't need cross-domain tracking, just subdomain tracking.


1 Answers

The solution is to do pageTracker._setDomainName("www.example.com") and then GA will issue the cookies to ".www.example.com". That way analytics still works fine and the cookies do not leak into the other static subdomain.

like image 93
cherouvim Avatar answered Sep 30 '22 21:09

cherouvim