Skip to content

Instantly share code, notes, and snippets.

Created November 13, 2020 11:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vyskoczilova/39bb03b76680a9f4f0661834e4b201e8 to your computer and use it in GitHub Desktop.
Parse UTM codes to Contact Form 7 by javascript
* Solving a trouble with WP Engine which is caching website without URL parameters and re-attaches them back once the request is compiled.
* If you need to add UTM values to any form (not only CF7) you can use this JS snippet on the form page.
* Author: Karolína Vyskočilová (
* Author website:
* Date created: 2020-11-13
* Read more about WP Engine's cache:
(function() {
var urlParams = new URLSearchParams(;
var paramNames = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content'];
for ( var i = 0, length = paramNames.length; i < length; i ++ ) {
if ( urlParams.get(paramNames[i])) {
document.querySelector('.wpcf7-hidden[name="'+paramNames[i]+'"]').value = urlParams.get(paramNames[i]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment