Problems trying to create a cookieless domain due to Adsense
Asked Answered
M

2

10

Following the advice on google's pagespeed addon, I moved my static content (images, css, javascript files) to a subdomain of my site on which there should be no cookies, thus saving some space in the request headers for each request for these files. However, on looking at the results I find that cookies are still being created for this sub domain. I have google adsense on my site and it is writing cookies to the root domain *.example.com rather than only to www.example.com

Is there any way to force adsense to write cookies only to the exact domain used for displaying the adds and not to the root domain?

Mediterranean answered 16/6, 2011 at 4:7 Comment(0)
N
6

There appears to be no way to force adsense to create cookies for only a specific subdomain. The generally used solution is to simply serve your content from an entirely different domain. SO uses sstatic.net, Yahoo uses yimg.com, Youtube uses ytimg.com.

I'd recommend just getting a new domain name. It's only $10 a year or so (depending on your TLD). The ROI of that is, what, 10 minutes developer time?

Newman answered 7/7, 2011 at 7:34 Comment(1)
I second this advice. It sounds like more of a kludge than it really is, and that second domain can server static content for any web project you do. It also has the added benefit putting your code and your content on separate FTP sites with their own credentials which can be useful if a client is involved.Agreeable
N
1

There can be a proxy script -- a landing page -- where all the traffic for *.example.com lands and then request is dispatched to the intended subdomain. Alternatively, you can place that script in the each subdomains' root folder to redirect the adsense cookie to wwww.yourdomain.com. In Linux environment, it can be handled using .htaccess file, like:

# place this in your subdomain's root
RewriteEngine on
RewriteCond %{HTTP_COOKIE} ^.*SOME_ID=(\d+).*$ [QSA]
RewriteRule .* ../cache/$1 [QSA,L]

Where SOME_ID is a recurring name in each generated adsense cookie. <= This is to identify/ensure that the cookie under consideration is the adsense cookie.

Naos answered 8/7, 2011 at 6:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.