Reputation: 1422
this is the default GA code:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXX-1', 'auto');
ga('send', 'pageview')
I changed the "create" part of code into this:
ga('create', 'UA-xxx-1', 'auto', {'cookieDomain': '.website.com'});
Can you please confirm that now GA should set its cookies just on the www.website.com and not on subdomains like static.website.com? If not, what am I doing wrong?
Thanks for the help.
Upvotes: 0
Views: 166
Reputation: 8907
To set the cookie so that sub domains are tracked as referrals, you need to remove the 'auto' parameter as the third parameter in the create
function is reserved for the cookie domain (and also applying shorthand):
ga('create', 'UA-xxxxx-1', 'www.website.com');
You can read more here https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings
If what you want to do is to track only traffic on the www subdomain (ie. you don't want to see traffic from static.example.com), you need to set up an Include filter that tracks only on www.
Upvotes: 1