Search code examples
seoanalyticsmagento2varnishvarnish-vcl

SEO and stripping UTM parameters with Varnish


Recently I had a problem where a client of mine sent out an email with MailChimp containing UTM (Google) and MC (Mailchimp) parameters in the URL.

Since the link was pointing to a Magento 2 site with Varnish running, I had to come up with a fix for that, otherwise Varnish would create a lot of different entries for the "unique" URL's.

Now, by using this adjusted snippet in the Varnish .vcl, I was able to strip these parameters:

if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|mc_[a-z]+|utm_[a-z]+)=") {
    set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|mc_[a-z]+|utm_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
    set req.url = regsub(req.url, "[?|&]+$", "");
}

And this works pretty good, it strips the URL.

BUT, I can't seem to find a correct explanation if this in any way will affect SEO, or Analytics tracking - I tried Googling it as much as I could, but cannot find a clear explanation.

Anyone here with a solution and / or explanation?


Solution

  • This will not affect SEO in any way. Those links are typically added by Google itself (Analytics, Adwords) or email marketing campaigns which use the same. The search engines will not see those links so there's no impact on SEO whatsoever.

    The parameters mentioned are used by Javascript libraries and never by the PHP scripts, so what you did for better cacheability is correct. Browser's Javascript engines will still see them because they have access to full URL. The PHP backend (Magento) does not need them.