How to Capture UTM Parameters in Gravity Forms (Works with WP Engine Caching)
Tracking where your form submissions come from is critical for understanding campaign performance. If you’re using Gravity Forms on a cached WordPress site (especially on hosts like WP Engine), capturing UTM parameters can be trickier than it looks.
This guide walks through a reliable, cache-safe method to capture UTM parameters in Gravity Forms that works for logged-in and logged-out visitors.
What Are UTM Parameters?
UTM parameters are query string values added to URLs to track marketing attribution. Common examples include:
utm_source=email
utm_medium=cpc
utm_campaign=summer_promo
utm_term=donations
utm_content=cta_button
When someone submits a form, storing these values allows you to see:
- which channel drove the conversion
- which campaign performed best
- which messaging worked
Why Gravity Forms UTM Tracking Fails on Cached Sites
Gravity Forms has a built-in feature called Dynamic Population, which lets you map URL parameters directly into form fields.
This works only when pages are not cached.
On platforms like WP Engine:
- Logged-out visitors are served cached HTML
- The server never re-renders the page per URL
- ?utm_* values are ignored
- Forms appear empty even though UTMs are present in the link
This leads to a confusing situation:
- ✅ Works when logged in
- ❌ Fails in incognito / logged out
To solve this properly, UTMs must be captured client-side using JavaScript.
The Correct Way to Capture UTM Parameters in Gravity Forms
The reliable solution is:
- Read UTM parameters from the browser URL
- Store them in cookies (optional but recommended)
- Inject them into Gravity Forms hidden fields using JavaScript
- Wait until Gravity Forms is fully rendered (important for AJAX forms)
- Support multiple forms if needed
This approach works:
- with WP Engine caching
- with AJAX-enabled forms
- for logged-out visitors
- across multiple pages or steps
Step-by-Step Guide to Capture UTM Parameters in Gravity Forms
Step 1: Add hidden fields to your Gravity Form
In the Gravity Forms editor, add Hidden fields for each UTM you want to capture:
- utm_source
- utm_medium
- utm_campaign
- utm_term
- utm_content
After adding each field:
- Save the form
- Inspect the page to note the generated input IDs
Gravity Forms inputs follow this format:
input_{FORM_ID}_{FIELD_ID}
Example:
input_103_41
Where:
- 103 = Form ID
- 41 = Field ID
You will need these IDs for the script.
Step 2: Use this JavaScript snippet (cache-safe)
This script:
- captures UTMs from the URL
- falls back to cookies if the user navigates
- fills Gravity Forms hidden fields
- works with cached pages
- supports multiple forms
Example script
<script>
(function () {
var forms = [
{
formId: 103,
map: {
utm_source: 41,
utm_medium: 42,
utm_campaign: 43,
utm_term: 44,
utm_content: 45
}
},
{
formId: 104,
map: {
utm_source: 49,
utm_medium: 51,
utm_campaign: 52,
utm_term: 50,
utm_content: 53
}
}
];
function getQueryParam(name) {
return new URLSearchParams(window.location.search).get(name) || '';
}
function setCookie(name, value, days) {
if (!value) return;
var d = new Date();
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = name + '=' + encodeURIComponent(value) +
'; expires=' + d.toUTCString() + '; path=/; SameSite=Lax';
}
function getCookie(name) {
var match = document.cookie.match(
new RegExp('(?:^|; )' + name.replace(/([.$?*|{}()[\]\\/+^])/g, '\\$1') + '=([^;]*)')
);
return match ? decodeURIComponent(match[1]) : '';
}
function fillForm(config) {
Object.keys(config.map).forEach(function (key) {
var value = getQueryParam(key) || getCookie('kyra_' + key);
if (!value) return;
setCookie('kyra_' + key, value, 30);
var input = document.getElementById('input_' + config.formId + '_' + config.map[key]);
if (input) input.value = value;
});
}
function waitAndFill() {
var tries = 0;
var maxTries = 60;
var timer = setInterval(function () {
tries++;
forms.forEach(function (cfg) {
var exists = Object.values(cfg.map).some(function (id) {
return document.getElementById('input_' + cfg.formId + '_' + id);
});
if (exists) fillForm(cfg);
});
if (tries >= maxTries) clearInterval(timer);
}, 200);
}
document.addEventListener('DOMContentLoaded', waitAndFill);
document.addEventListener('gform_post_render', waitAndFill);
})();
</script>
Step 3: Where to place the script
Recommended options:
- WPCode → HTML Snippet → Site Wide Footer
- Child theme footer.php
- Google Tag Manager (Custom HTML tag)
Avoid placing this inside page content if your site uses aggressive caching or optimization.
Important Notes for WP Engine Users
Always ensure your campaign links include the trailing slash if your site redirects URLs.
Correct:
/landing-page/?utm_source=google
Incorrect:
/landing-page?utm_source=google
Some redirect rules drop query parameters if the slash is missing.
How to Test Gravity Forms UTM Tracking
- Open an incognito window
- Visit the page with UTMs: ?utm_source=test&utm_medium=test
- Submit the form
- Check the Gravity Forms entry
- Confirm all UTM fields are populated
Can This Be Extended to Click IDs?
This setup can easily be extended later to capture:
gclid(Google Ads)msclkid(Microsoft Ads)fbclid(Meta)
You simply:
- Add hidden fields
- Add them to the
mapobject - No logic changes required
Final Thoughts
If you’re running Gravity Forms on a cached WordPress host, client-side UTM capture is the only reliable method.
This approach:
- avoids cache issues
- works for logged-out visitors
- supports multiple forms
- is easy to maintain and extend
If you need help implementing this on your site or adapting it to CRMs like HubSpot, Salesforce, or Dynamics, this pattern scales cleanly. If you need help with implementation, please get in touch with our expert team. Click here
At Kyra Web Studio, we’re passionate about helping businesses build a strong brand identity that drives growth and success. Our team of experts specializes in website design, ecommerce solutions, real estate design, web overhaul, responsive design, custom development, UI/UX design, paid advertising, branding, SEO, social media, content marketing, email marketing, hosting, maintenance, security, CMS implementation, backup & recovery, domain management, performance optimization, and website accessibility. Let us help you create a brand that stands out in the crowd and resonates with your target audience. Contact us today to learn more about our services and how we can help you achieve your business goals.


