Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

My Google Analytics website profile is for www.domain.com, and my only report is set up for www.domain.com. Requests to domain.com redirect permanently to www.domain.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 domain.com instead of www.domain.com.

This is unfortunate, as I’ve got cdn.domain.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.domain.com instead of domain.com?

share|improve this question
up vote 4 down vote accepted

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.domain.com']);

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

That fixed the cookies for me.

share|improve this answer
Thanks for this. – stevelove Feb 4 '11 at 5:36
@stevelove: you’re most welcome! – Paul D. Waite Aug 16 '11 at 21:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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