I’m using Google Analytics on a site — let’s call it www.example.com.

My Google Analytics website profile is forwww.example.com, and my only report is set up for www.example.com. Requests to example.com redirect permanently to www.example.com.

I’ve got the regular Analytics JavaScript on my index page for the domain. For some reason, it seems to be setting its cookies for example.com instead of www.example.com.

This is unfortunate, as I’ve got cdn.example.com set up as a CDN using Amazon Cloudfront, so I’d rather not have useless cookies (Analytics seems to set four cookies) cluttering up those requests.

How can I make Analytics set cookies for www.example.com instead of example.com?


As far as I can tell, the way to achieve this is to add the following line to your Analytics JavaScript, with the other _gaq.push calls:

_gaq.push(['_setDomainName', 'www.example.com']);

(See http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#siteLinkingConsiderations)

That fixed the cookies for me.

  • @stevelove: you’re most welcome! Aug 16 '11 at 21:24

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.