0

I would like to ask if there's a way to set the query parameters as the cookie of a certain url?

Currently i'm having trouble with the varnish and nginx cause it was stripping the utm params which causes an issue with the GA. I can't remove the code that strip utm params since it would flood the varnish cache. So I was thinking of getting the utm params and set it as cookie from the nginx config

Any help would be appreciated

Thank you so much

1 Answers1

0

You can easily remove Google marketing URL parameters from URL that Varnish fetches from backend, like described here:

if (req.url ~ "(\?|&)(gclid|utm_[a-z]+)=") {
    set req.url = regsuball(req.url, "(gclid|utm_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
    # remove trailing question mark and ampersand from URL
    set req.url = regsub(req.url, "[?|&]+$", "");
}

This must be implemented in the vcl_recv routine of Varnish configuration. In this way, the URL that you see stays intact in the browser (which is important for Google Analytics), but Varnish will request and cache based on normalized URL without those parameters (for backend, e.g. PHP those parameters can be discarded).

Danila Vershinin
  • 5,286
  • 5
  • 17
  • 21