Why UTM Parameters Do Not Work on WP Engine

Nathan Schmidt, Senior UI Developer

Article Categories: #Code, #Front-end Engineering, #Back-end Engineering

Posted on

WP Engine does not load UTM parameters on the server, so any server-side languages reading UTM parameters will return null.

I recently ran into a problem where UTM (Urchin Tracking Module) parameters were not changing the content on a WP Engine site. My first thought was that the entire page was being cached, but after clearing the site cache, the URL parameters were still not working. After a bit more research I found that WP Engine does not load UTM parameters on the server, but after the page loads. So any server-side languages reading UTM parameters will return null.

Updating content using UTM parameters

We built custom functionality on a site that would change the header phone number if there was a UTM parameter name that matched in the WordPress admin. This allows the site administrator to set a list of phone numbers matching a custom UTM parameter for marketing campaigns. Once someone viewed the campaign page with the custom UTM parameter, the phone number would be saved for that user's session and they would see that custom phone number for all subsequent pages.

# Example of utm_ parameters in a url
https://fakesite.com?utm_phone=social&utm_source=facebook

The solution we built worked perfectly and passed all our QA and code review. But, when we deployed it to production, it acted like the custom UTM parameter was not even there. I did some research and found that WP Engine strips the UTM parameters from the URL when loading the page on the server and then adds them back in after the page has loaded. This is why the campaign phone numbers returned nothing, as I had built that functionality in PHP/Twig.

Backend languages cannot access the UTM parameters

WP Engine recommends three options to solve this problem. They range from switching to a different language to updating server settings.

Build in JS

WP Engine recommends not using server-side languages to check the URL parameter and instead using JS to check the UTM and update the site content accordingly. If you have not built your functionality yet, this is the way to go. But if all of your functionality is set up in backend languages like PHP, it may be a big lift to change it all over to JS.

Don’t use UTM in the URL

The other solution is not to use utm_ to start your URL parameters. This is really easy to change, but before you update everything, think about where the URLs are coming from. If you are working with a marketing software product like HubSpot, removing all the utm_ may not be a solution as a lot of marketing software auto-generates the URLs for you and gives you the final URL to use for your campaign. It just depends on your situation.

Disable caching

The last solution is to disable WP Engine from caching the utm_ so that those UTM URL parameters are available when the server-side languages load the page. If you don’t have a huge amount of site traffic going to those campaign pages, disabling the cache for those pages is not a big problem. If you are expecting a large amount of traffic to those pages, excluding these URL parameters from the server cache could very easily cause performance issues on the site. It is conditional on how many users are viewing those pages.

Implemented solution

WP Engine has a support page about this topic which helped me understand how and why they only load UTM parameters on the front end and not the backend - Cache and UTM/gclid Variables. After reading all the options that WP Engine gave, the best solution for the site we built was to disable the caching for URLs that had parameters that started with utm_. I went with this solution as there was not a huge amount of traffic to those campaign pages. If I had known that WP Engine does not load the page on the server with UTM parameters, I would have built the entire phone number swapping for campaigns using JS.

Final thoughts

If you run into similar problems on your site hosted on WP Engine, you have three options:

  • Build the functionality in JS

  • Don’t use utm_ to start your URL parameters

  • Disable the server cache for pages that have utm_ in the URLs

Building custom web software is not perfect and often requires weighing the pros and cons of various options. Hopefully, this article helps you find a solution that works for you.

Nathan Schmidt

Nathan is a Senior UI Developer in Colorado. He loves applying creative thinking to web development and bringing interactive components to life.

More articles by Nathan

Related Articles