
Quick answer: There are three ways to track UTM parameters in Gravity Forms. If visitors land directly on your form page, use the built-in method: add a Hidden field for each parameter, enable Allow field to be populated dynamically, and set the Parameter Name to utm_source, utm_medium, and so on. Gravity Forms fills the fields from the URL automatically. No code needed.
If visitors land on one page and submit the form on another, the UTM parameters fall off the URL in between, and the built-in method captures nothing. For that, add the JavaScript snippet described in Method 2 to hold the values across pages. The same setup also captures Google Ads click IDs (gclid, gbraid, wbraid).
If you want the source of leads no matter where they come from, like organic search, AI assistants, and referrals from other sites, or you want the first visit and the last visit on the same entry, Method 3 covers it.
Which method do you need?
| Your situation | Use this |
|---|---|
| Visitors land directly on the form page and stay there (the UTM-tagged URL is the form page) | Method 1: built-in Dynamic Population. Stop there. |
| Visitors land on a blog post or landing page first, then navigate to the form on another URL | Method 1 plus Method 2 (the snippet) |
| You run ads and the landing page is not the form page | Method 1 plus Method 2 |
| Your pages are cached by WP Rocket or a similar plugin | Method 2 or Method 3. Both read the URL in the browser, so caching can’t blank them. See the caching note under Method 1. |
| You want the source of every lead, including organic, direct, AI assistants, and referrals that never had a UTM | Method 3 |
| You need lead attribution across multiple sessions, or first touch and last touch on the same entry | Method 3 |
The built-in method is the base layer for all of these. Set it up first.
Method 1: Built-in Dynamic Population (no code)
This is all you need when the UTM-tagged URL is the same page the form lives on. Gravity Forms reads the query string and populates matching hidden fields on load.
Step 1 – Add a Hidden field for each parameter
In the Gravity Forms editor, add a Hidden field for every value you want to capture: UTM Source, UTM Medium, UTM Campaign, UTM Content, UTM Term, and (if you run Google Ads) GCLID, GBRAID, and WBRAID. Give each a clear internal label.
Step 2 – Enable dynamic population
Open each field’s Advanced tab, check Allow field to be populated dynamically, and set the Parameter Name to the exact key from the URL:
| Hidden field | Parameter Name |
|---|---|
| UTM Source | utm_source |
| UTM Medium | utm_medium |
| UTM Campaign | utm_campaign |
| UTM Content | utm_content |
| UTM Term | utm_term |
| GCLID | gclid |
| GBRAID | gbraid |
| WBRAID | wbraid |
Step 3 – Send tagged traffic
Point campaigns at a URL like:
https://yoursite.com/contact/?utm_source=google&utm_medium=cpc&utm_campaign=summer_saleWhen the form loads, each hidden field fills with its matching value and stores it on the entry. Every submission now carries source data attached to the lead, not just an anonymous session in Google Analytics.
Keep the values consistent from the first campaign. A simple UTM naming system stops “Facebook,” “facebook,” and “fb” from turning into three different sources in your entries. And remember that Google Ads auto-tagging adds a gclid, not UTMs, so a paid click lands with a click ID and blank UTM fields unless you add UTMs to the final URL yourself.
The first limitation: this only works if the UTM parameters are still in the URL at the moment the form loads. The instant a visitor clicks an internal link, the parameters fall off the address bar. If your form lives on a different page from your landing page, Method 1 alone captures nothing. That’s what Method 2 fixes.
The second limitation: page caching. The Gravity Forms documentation is blunt about it: dynamic population “uses PHP” and “can’t be used in cached pages.” WP Rocket makes it worse. Its default list of ignored query strings includes utm_source, utm_medium, utm_campaign, utm_term, utm_content, gclid, fbclid, and msclkid, so a tagged URL gets the standard cached copy of the page, rendered with no parameters at all. If your form page is cached, Method 1 fails even when the visitor lands right on it. Methods 2 and 3 read the URL in the browser and don’t have this problem.
Method 2: Capture UTMs across pages in a session (JavaScript snippet)
This snippet captures UTM parameters and Google Ads click IDs the moment a visitor arrives on any page, holds them for the rest of the browser session, and writes them into your hidden fields when the form loads. Even if the visitor browsed five pages first, the data is still there.
// Replace 'myclass' and 'myitem' with your own handle.
(function () {
var fieldMap = {
'utm_source': '.myclass-utm-source input',
'utm_medium': '.myclass-utm-medium input',
'utm_campaign': '.myclass-utm-campaign input',
'utm_content': '.myclass-utm-content input',
'utm_term': '.myclass-utm-term input',
'gclid': '.myclass-gclid input',
'gbraid': '.myclass-gbraid input',
'wbraid': '.myclass-wbraid input'
};
// Capture any tracked params in the current URL (runs on every page).
var params = new URLSearchParams(window.location.search);
Object.keys(fieldMap).forEach(function (key) {
var value = params.get(key);
if (value) sessionStorage.setItem('myitem_' + key, value);
});
// Populate matching hidden fields from storage.
function populate() {
Object.keys(fieldMap).forEach(function (key) {
var stored = sessionStorage.getItem('myitem_' + key);
if (!stored) return;
document.querySelectorAll(fieldMap[key]).forEach(function (input) {
if (!input.value) input.value = stored;
});
});
}
// Runs as soon as the DOM is ready.
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', populate);
} else {
populate();
}
// Runs again after Gravity Forms loads a form with AJAX
if (window.jQuery) {
jQuery(document).on('gform_post_render', populate);
}
})();Step 1 – Add the script site-wide
It must run on every page, not just the form page. In WordPress, any of these work:
- Add it to your theme’s
functions.phpviawp_headorwp_enqueue_scripts - Paste it into a code-snippets plugin like WPCode or Code Snippets, enabled site-wide
- Add it to Google Tag Manager as a Custom HTML tag firing on all pages (the
readyStateguard above is what makes the GTM path reliable)
One caching caveat here too. If WP Rocket’s Load JavaScript deferred or Delay JavaScript execution is on, or it combines files, the snippet can run before jQuery exists and the gform_post_render re-run never binds. Exclude the snippet from those options, or load it through Tag Manager. Nearly every “my fields are blank” support ticket we get for our plugin traces back to those same WP Rocket settings, and this snippet is exposed to them too.
Step 2 – Confirm your hidden fields exist
Use the same Hidden fields from Method 1. Keep Allow field to be populated dynamically enabled. That way direct-landing visits are still captured natively, and the snippet only fills in the cross-page ones.
Step 3 – Add a CSS class to each field
On each hidden field’s Appearance tab, add a CSS Class so the script can find it:
| Hidden field | CSS Class |
|---|---|
| UTM Source | myclass-utm-source |
| UTM Medium | myclass-utm-medium |
| UTM Campaign | myclass-utm-campaign |
| UTM Content | myclass-utm-content |
| UTM Term | myclass-utm-term |
| GCLID | myclass-gclid |
| GBRAID | myclass-gbraid |
| WBRAID | myclass-wbraid |
Step 4 – Test the cross-page flow
- Visit any page with test parameters:
yoursite.com/blog/some-post/?utm_source=test&utm_campaign=snippet_test - Click an internal link to the page with your form, do not refresh
- Fill out and submit the form
- Open the entry in your Gravity Forms dashboard. UTM Source and UTM Campaign should read
testandsnippet_test
If the fields are empty, open dev tools and confirm each hidden field’s container has the right CSS class applied.
How the snippet works
On every page load it reads the URL. If any tracked parameter is present, it saves each one to sessionStorage under your custom key (myitem_utm_source, etc.). That’s what carries the data across pages. Once captured on the landing page, it stays available for the whole browser session.
When the form exists on-page, it populates the hidden fields by CSS class, but only if a field is still empty. So it never overwrites a value Gravity Forms already captured. The readyState check runs the populate step immediately if the page has already loaded (the GTM case), and the gform_post_render hook re-runs it for forms that load with AJAX.
Why sessionStorage and not localStorage? It clears when the browser session ends, which gives you clean last-touch-per-session data. You won’t accidentally stamp a brand-new conversion with a UTM from a campaign the visitor clicked weeks ago. If you do want values to persist across sessions, swap sessionStorage for localStorage. Read the limits below first, though, because real multi-session attribution needs more than a storage swap.
What this snippet does NOT do
The snippet does not capture the full story, here’s what you need to know:
❌ First-touch across multiple sessions. When the session ends, sessionStorage clears. A visitor who clicks your ad today and converts three weeks later from a bookmark has no first-touch data left.
❌ Landing page URLs. It captures parameters, not the first-page or conversion-page URL. That’s useful attribution context it doesn’t grab.
❌ Referrer fallback. A visitor arriving from organic search or a partner link with no UTMs leaves nothing to capture. You’d need to extend the script to fall back to document.referrer.
❌ Cross-device tracking. Storage is per-browser, per-device. Mobile today and desktop tomorrow are two unconnected sessions.
❌ Visitors who block storage APIs. Some privacy tools disable sessionStorage; those visitors submit with no captured data.
For single-session campaigns where you control the landing page and the funnel is short, this snippet is enough. For everything else, Method 3.
Method 3: Track every source with first and last touch attribution
UTMs only exist on links you tagged. They don’t carry across pages on their own, and even when they are captured they only tell part of the story: you can see which tagged links got clicked, but not which medium is bringing in the leads, so they can’t tell you where the next dollar of marketing spend should go. Organic search, AI assistants, referrals from other sites, and direct visits all arrive with no UTM at all.
Our Referral Tracking for Gravity Forms plugin, listed in the Gravity Forms add-on directory, fills that gap. It reads the referrer and the URL on every visit, labels the source (Google Organic, Facebook Ads, ChatGPT Organic, Mailchimp, and so on), and stores it in a cookie for your attribution window, 7 days by default and up to 365. Setup is shorter than Method 1.
Step 1 – Install and activate the plugin
Upload the plugin, activate it, and enter your license key when prompted.
Step 2 – Turn on tracking
Go to Forms → Settings → Referral Tracking and check Enable by Default to track every form, or turn it on per form under Form Settings → Form Options. The plugin adds its own hidden fields at render time, so there is nothing to build by hand and nothing to forget when you add a form later.
Step 3 – Turn on last-touch attribution
On the same settings page, enable last-touch attribution. First touch records the visit that first brought someone to your site and holds it for the whole attribution window. Last touch records the most recent arrival with a real source, in a parallel set of fields. If you send click IDs to Google Ads or a CRM, this setting matters: a returning visitor’s gclid is stored in the last-touch Click ID field, so leave last touch off and that gclid is never recorded. Check Don’t let direct visits replace last touch as well, so a visitor coming back from a bookmark keeps the source that last brought them in instead of recording “Direct.”
Step 4 – Check an entry
Submit a test form from a private window. Logged-in administrators get session-only storage, so your test data doesn’t stick around for a week. The entry now shows Source, Referrer, all six UTM parameters including utm_id, the Click ID, and the full query string, with a second set for last touch. Every value has a merge tag, so {pb_ref_source} and {pb_ref_utm_campaign} drop straight into notifications, and the entry list can show them as columns.
Why two touches matter. Say a prospect asks ChatGPT for a recommendation and clicks through to your site. ChatGPT appends utm_source=chatgpt.com to links it cites, so that visit arrives tagged. They look around and leave. Four days later a retargeting ad brings the same person back with a gclid in the URL, and this time they fill out the form. A single UTM field keeps one of those visits, and the snippet keeps the most recent. With both touches on the entry, ChatGPT gets credit for finding them and Google Ads gets credit for closing them. We wrote up how to choose between the two models in first-touch vs last-touch attribution for Gravity Forms.
What you get beyond Methods 1 and 2:
- First-touch and last-touch sources across sessions, for an attribution window of 1 to 365 days
- A source label on every entry regardless of UTMs (Google Organic, Bing, Facebook Ads, ChatGPT, Perplexity, Mailchimp, and more)
- The referrer URL, plus click IDs from Google, Microsoft, Meta, LinkedIn, TikTok, and the major email platforms
- Works with every form on your site without per-form setup
- Writes into Gravity Forms entry fields, with merge tags and mirror fields for clean CRM mapping
- A Reports tab, an optional weekly email digest, and an optional GA4 event on form confirmation
Caching note: if WP Rocket or LiteSpeed defers, delays, or combines scripts and your Source field reads “Unknown,” turn on Protect Scripts from Optimization under the plugin’s Advanced settings and clear your cache. That is the fix for nearly every blank-field ticket we get.
Get Referral Tracking for Gravity Forms
Using WPForms instead? There’s a Referral Tracking for WPForms plugin with the same functionality.
FAQ
Does Gravity Forms capture UTM parameters automatically?
Not by default. You add a Hidden field for each parameter and enable Allow field to be populated dynamically with the matching parameter name. After that, Gravity Forms fills the fields from the URL on its own, but only when the parameters are present on the page where the form loads.
How do I pass UTM parameters into a Gravity Form?
Add hidden fields, turn on dynamic population (Method 1 above), and send traffic to URLs with UTM tags like ?utm_source=google&utm_medium=cpc. The values land on the entry when the form is submitted.
Why aren’t my UTM parameters being captured?
Two causes cover nearly every case. First, the visitor landed on a different page than the form. The parameters drop off the URL as soon as they click an internal link, so there’s nothing left for Gravity Forms to read by the time the form loads. The JavaScript snippet (Method 2) fixes this. Second, page caching. Dynamic population runs in PHP, and WP Rocket serves the cached copy of a page for URLs carrying utm_source, gclid, and similar parameters by default, so the hidden fields render empty. Method 2 or Method 3 reads the URL in the browser instead.
Do I need a plugin to capture UTMs in Gravity Forms?
No. Native dynamic population needs no code, and the snippet handles cross-page capture for free. A plugin earns its keep once you need the source of untagged traffic, first touch and last touch on the same entry, or attribution across sessions.
Can Gravity Forms track UTM parameters across multiple pages?
Not on its own. Dynamic population only reads the URL of the page the form is on. To carry UTMs from a landing page to a form on another page, use the JavaScript snippet in Method 2, which stores them in sessionStorage, or a plugin that stores them in a cookie (Method 3).
What’s the difference between first-touch and last-touch attribution?
First touch is the source that brought a visitor to your site the first time within your attribution window. Last touch is the source of their most recent visit before they submitted. A visitor who found you through ChatGPT and came back through a retargeting ad has ChatGPT as first touch and Google Ads as last touch. Methods 1 and 2 record one value; Method 3 records both.
Can Gravity Forms capture Google Ads click IDs (gclid, gbraid, wbraid)?
Yes, the same way it captures UTMs. Add a hidden field for each, set the parameter name to gclid, gbraid, or wbraid, and they’re picked up natively on direct visits and by the snippet across pages.
What’s the difference between tracking UTMs in Google Analytics and in Gravity Forms?
Analytics gives you aggregate session reports, like “47 visits from a LinkedIn campaign.” Capturing UTMs in Gravity Forms ties the source data to the individual lead, so you can see which specific submission came from which campaign.