I had this weird issue a time ago with a simple task that consisted on getting some query string parameters from the URL, from the PHP $_GET
variable, to store them in Magento after the Customer places the Order.
What sounded like a very straightforward task got complicated because the $_GET
variable was missing some of the those parameters I needed to save.
Debugging this issue made me realise that all the missing parameters where those starting with utm
. I was literally going to this example URL...
http://example.com/test.php?utm_source=Source&utm_medium=Medium&utm_content=Content&utm_term=Term&siteId=42689&siteName=naguel.com
...to get the following incomplete output when printing the $_GET
variable:
The cause of this issue was Varnish's recommended VCL configuration for Magento that includes the following inside the sub vcl_recv {}
.
# Remove all marketing get parameters to minimize the cache objects
if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
set req.url = regsub(req.url, "[?|&]+$", "");
}
That was literally subtracting all marketing-related GET
parameters from the URL, including those starting with utm_
.
The solution is quite simple: remove the utm_[a-z]+
from the if
conditional and restart Varnish to apply the changes.
UTM parameters?
UTM stands for "Urchin Tracking Module" (who cares, right?), which are basically marketing-related parameters to track marketing campaigns, and to know how people interact with the site.
In my case I was dealing with them because of a Rakuten integration with Magento.
More information on what they are and what we can do with them can be found on "The Ultimate Guide to Using UTM Parameters" post from Neil Patel's blog.