Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
    
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 '10 at 13:57
4  
Google's speed test gives you a ++ if you are serving static content from a cookieless domain. Google gives, google takes. –  Thomas Sep 6 '10 at 14:32
1  
Interesting.... –  John Conde Sep 6 '10 at 15:17
    
@thomas +1 for seeing the reason this question was asked. –  Talvi Watia Sep 6 '10 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. –  Lèse majesté Sep 9 '10 at 10:32
show 3 more comments

4 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanks, I was afraid of that. I will be using a dedicated domain.net for my static content. –  Magnus Sep 10 '10 at 18:41
    
You don't need another domain. donaldthe just suggested a valid method. –  machineaddict Nov 28 '13 at 15:47
add comment

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.

share|improve this answer
    
Thanks! This variable showed me the light. The current code is _gaq.push(['_setDomainName', 'yoursub.domain.com']);, put it after the _gaq.push(['_setAccount', 'UA-12345-1']); directive in the js code. See also developers.google.com/analytics/devguides/collection/gajs/… –  ArendE Feb 7 at 23:30
add comment

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.

share|improve this answer
    
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. –  machineaddict Nov 28 '13 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. –  DisgruntledGoat Nov 28 '13 at 17:54
add comment

The correct(est) answer is _gaq.push(['_setDomainName', 'none']); (http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setDomainName).

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.

share|improve this answer
add comment

Your Answer

 
discard

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.