Remove Google Analytics cookies in Varnish
As part of our ongoing implementations of Varnish, it is useful to be able to selectively remove cookies in order to reduce duplicate caching of dynamic content.
A good example would be removing cookies set by Google Analytics. To do this, simply add the following to vcl_recv():
sub vcl_recv {
if (req.http.cookie) {
set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");
if (req.http.cookie ~ "^ *$") {
remove req.http.cookie;
}
}
}