11

I have my web site at example.com, and i have also setup a sub domain for serving static content at static.example.com.
On my web pages I'm using Google Analytics, so it will attach its cookies to all page request, even on static.example.com.

I went into the GA settings and added a filter to exclude static.example.com, but I still see cookies (with the __utma.. name) on all web requests to my static domain.

How can i prohibit GA to use cookies on my sub domain?

8
  • Why do you not want the cookies to be there? Does it matter as long as the content isn't being tracked?
    – John Conde
    Sep 6, 2010 at 13:57
  • 7
    Google's speed test gives you a ++ if you are serving static content from a cookieless domain. Google gives, google takes.
    – Thomas
    Sep 6, 2010 at 14:32
  • 1
    Interesting....
    – John Conde
    Sep 6, 2010 at 15:17
  • @thomas +1 for seeing the reason this question was asked. Sep 6, 2010 at 22:29
  • Why does it matter what Google's speed test gives you? Isn't that just a performance testing tool for webmasters? Unless you want to delude yourself with a non-existent performance improvement, there's no point in removing cookies just to game a speed test that is only meant for you. Sep 9, 2010 at 10:32

4 Answers 4

6

Like this (with the new GA code)

_gaq.push(
    ['_setAccount', 'UA-xxxxx-x'],
    ['_setDomainName', 'www.example.com'],
    ['_trackPageview']
);

It still won't block other 3rd party apps you may be using from setting cookies to your static subdomain but at least you are getting rid of the GA cookies which are quite large.

1
5

You can not do this. Any cookie issue for domain example.com is valid for all subdomains of example.com.

If you wish to have static.example.com be a cookie free domain, you should serve up the main site at www.example.com (you can provide a 301 redirect from example.com to www.example.com).

As static.example.com is not a subdomain of www.example.com (rather a sibling), it will not share its cookies.

This doesn't really have anything to do with Google Analytics, this is simply how the WWW works. Even if you could tell GA to not send the cookies to static.example.com that wouldn't help your other users who would not have access to this information.

2
  • Thanks, I was afraid of that. I will be using a dedicated domain.net for my static content.
    – Magnus
    Sep 10, 2010 at 18:41
  • You don't need another domain. donaldthe just suggested a valid method. Nov 28, 2013 at 15:47
2

Like Kris said, any cookies set on example.com will be available on static.example.com and other subdomains. If you want to keep the site without the www. then I'd suggest using a different domain name (for example, Stack Overflow uses http://sstatic.net).

If you have multiple domains already, for example yourbusiness.net redirecting to yourbusiness.com then you can simply use the .net one to host all the static content.

2
  • StackOverflow uses sstatic.net because it delivers the static content to multiple websites. On a single website there is no need in getting a new domain. I'm using the same setup (with subdomain) and never had problems with cookies. They are not sent to subdomains. Nov 28, 2013 at 15:50
  • @machineaddict not true: developer.yahoo.com/performance/rules.html#cookie_free you probably set cookies on the www subdomain and not the root domain. Nov 28, 2013 at 17:54
2

The correct(est) answer is

_gaq.push(['_setDomainName', 'none']);  

Reference.

In my tests, explicitly setting a domain WITHOUT a sub-domain (e.g. example.com instead of www.example.com) still resulting in cookies being sent to sub.example.com. Setting the domain name to 'none' solved this.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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