8

I don't quite understand how Google Analytics cookies work with Varnish.

  • Do pages that contain GA cookie not get cached?
  • Do I need to remove the GA cooke in vcl_recv?
  • If I do remove them, does that stop GA tracking visitors?
Tom
  • 33,626
  • 31
  • 85
  • 109

1 Answers1

6

Cookies invalidate the cache if the Vary header is not set. For example, a client that goes to a URL with a certain login cookie will receive a different page than a client with a different cookie.

In order to cache a page that has cookies that do not affect the cache-ability of the page (for example, Google Analytics on static sites), the cookies must be stripped or the cache won't know whether two pages should be considered the same resource.

kern
  • 106
  • 2
  • 1
    Does the GA cookie actually talk to Varnish at all? because it's client side and connects to Google's Servers? Secondly: If I do strip the GA cookie, does analytics still get recorded? – Tom Aug 10 '10 at 18:20
  • 3
    Varnish doesn't do anything with the Cookie. All it does is pass it along to the backend service. The cookie is mainly there to keep client side state about browsing habits. It's safe to strip it from requests. Analytics will still be recorded. – kern Aug 10 '10 at 19:59
  • Analytics are still recorded, true. But what about recurring visitors? Does JavaScript have the ability to tell if the page is being served to a first time user or a recurring visitor? – amateur barista Mar 29 '11 at 15:39
  • 5
    @amateurbarista yes. All of the google analytics stuff is client side. Google wanted the cookies to be owned by the respective domains so they weren't third party cookies. But this also meant that all requests will have the analytics cookies in the headers. Removing them does not have any ill effects on google analytics. – Patrick James McDougle Aug 28 '12 at 18:48