How cookies affect Varnish caching?

amateur barista picture amateur barista · Mar 29, 2011 · Viewed 7.6k times · Source

How does Varnish caching affect third-party cookies set by Omniture and first-party cookies set by Google Analytics?

So far I've seen opposing opinions, some people say that because the tracking stats are created by JavaScript (which is true), that stripping these Cookies from the request won't affect GA or Omniture.

However here they are saying that these softwares set various cookies to track recurring visitors, and so stripping these cookies from the request would essentially count every user as a new visitor.

I don't want my users to count every time as a new visitor. I am not sure either that these JavaScript embeds have the ability to calculate if the page is being served to a first time or recurring visitor. Any links to offical GA or Omniture documentation is deeply appreciated.

Answer

Nic Cottrell picture Nic Cottrell · Feb 12, 2012

There's a good example here: https://www.varnish-cache.org/trac/wiki/VCLExampleRemovingSomeCookies

Basically you want to remove all GA cookies before Varnish sends the request to the backend with:

sub vcl_recv {
  if (req.http.Cookie) {
    set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__utm.=[^;]+;? *", "\1"); # removes all cookies named __utm? (utma, utmb...) - tracking thing

    if (req.http.Cookie == "") {
        remove req.http.Cookie;
    }
  }
}

If no other cookies are left, Varnish will automatically cache and deliver pages to your visitors.