Cookie preferences

Choose which optional cookies EndFrame may use on this site. Analytics and advertising tools load only if you allow them, and you can change your mind any time from “Cookie settings” in the footer. Whatever you choose, this tab keeps the campaign labels from the link that brought you, and they are saved with your account if you sign up. Read the Cookie Policy.

Needed for the site to work, such as remembering this choice. Always on.

Lets us load analytics tools through Google Tag Manager, including Google Analytics and Microsoft Clarity session recordings, to understand how the site is used.

Allows advertising tags to measure our ad campaigns. None run on this site today. It also keeps ad click IDs from the page address for this tab, and saves them with your account if you sign up.

Skip to main content

How to Capture UTM Parameters in Hidden Form Fields So Leads Keep Their Source

GA4 knows where your visitors came from, but your leads usually do not. This guide shows how to capture UTM parameters into hidden form fields reliably, including the persistence step most tutorials skip, and how to test it before launch.

The EndFrame Team5 min read

A new lead lands in your CRM and nobody knows where it came from. GA4 shows the campaign drove sessions, the ad platform shows clicks, but the lead record has an empty source field, so sales cannot tell a paid lead from a referral. Hidden form fields fix this by carrying the UTM values along with the submission. The concept is simple; the details are where most implementations fail. This guide covers both.

How hidden fields carry the source

A hidden field is an ordinary form input with type="hidden". The visitor never sees it, but its value is submitted with the rest of the form. If you add hidden inputs named utm_source, utm_medium, utm_campaign, utm_term and utm_content, and fill them with the values from the visitor's landing URL, every submission arrives with its campaign attached. Your form tool or CRM then maps those inputs to fields on the lead record.

The weak point is the filling. The values live in the URL of the first page the visitor saw. If the form sits on that same page and the visitor submits immediately, reading the current URL works. In real journeys, people land on a blog post, read the pricing page and fill in the demo form three clicks later, by which point the query string is long gone.

The five steps

  1. 1Create the destination fields first. In your CRM, add fields for each UTM parameter and any click IDs you want. Decide whether you are storing first-touch, last-touch or both, and name the fields so nobody has to guess.
  2. 2Add hidden inputs to the form. One per value, with names that match what your form tool maps to the CRM fields.
  3. 3Capture on arrival. On every page, run a small script that reads the query string with URLSearchParams. If any UTM parameter or click ID is present, save the values to first-party storage: sessionStorage for the current visit, localStorage or a first-party cookie if you want them to survive a return visit.
  4. 4Fill on form load. When the form renders, read the stored values and write them into the hidden inputs. If the form loads after the page, for example a form injected by a third-party script, wait for the form's ready event rather than running on page load.
  5. 5Test the whole journey. Click a tagged link in a private window, browse two other pages, submit the form and check the lead record, not just the browser.

For step three, store the landing page URL and the referrer alongside the UTMs. They cost nothing and answer a lot of questions later, especially for untagged traffic where the referrer is the only clue.

First touch, last touch, or both

The storage step forces a decision. If a visitor arrives from a paid social ad on Monday and from a newsletter on Thursday, which campaign belongs on the lead? First-touch logic writes values only if storage is empty, so the social ad stays. Last-touch logic overwrites on every tagged arrival, so the newsletter wins. Neither is wrong, but mixing them by accident is: if half your forms use one script and half use another, your lead source report compares two different things. The trade-offs are covered in first-touch vs last-touch attribution. The robust answer is two sets of fields, first and latest, so you never have to choose.

Platform notes

Form toolBuilt-in optionWatch out for
HubSpot formsHidden fields can be set from a query string using the property's internal nameWorks from the current page URL only; dynamic query strings need Marketing Hub Professional or Enterprise
Salesforce Web-to-LeadHidden inputs in the generated HTML; custom fields use their field ID as the nameGenerated forms cannot be edited in Salesforce, so changes are made in your site's HTML
Embedded third-party forms in iframesVaries; some accept URL parameters on the embedA script on your page cannot fill fields inside another domain's iframe
Your own HTML formFull control over inputs and scriptMake sure the server-side handler saves the hidden values

Iframe-based tools such as scheduling widgets and hosted survey forms are the hardest case, because the form lives on someone else's domain. Our guide to tracking embedded forms and iframes covers the options. If HubSpot is your CRM, UTM tracking in HubSpot explains what it records automatically and where hidden fields are still needed.

Common reasons the fields arrive empty

  • The script reads only the current URL, and the visitor navigated before converting.
  • A redirect between the ad and the landing page dropped the query string, so there was nothing to capture.
  • The form was rendered after the script ran, so the inputs did not exist yet when the values were written.
  • The hidden input names do not match the form tool's field mapping, so the values are submitted and then discarded.
  • A consent tool blocked the capture script until the visitor accepted, by which point they were on a different page.
  • The form tool's pre-fill for returning visitors overwrote the hidden values with older ones from the contact record.

A test plan worth ten minutes

Build a tagged test link with obviously fake values, such as utm_source=test-source and utm_campaign=hidden-field-check, so the result is easy to find. Open it in a private window, then use the browser's developer tools to confirm the values were written to storage. Navigate to a second and third page, open the form and inspect the hidden inputs: each should hold the test value. Submit with a test email address and open the resulting record in your CRM. Repeat once with an untagged visit to confirm the fields stay empty or keep the earlier first-touch values, depending on the logic you chose. Finally, run the same journey on a phone, because mobile in-app browsers are where unusual behaviour tends to appear.

Privacy and consent

UTM values describe a campaign, not a person, but storing them on the visitor's device and attaching them to a named lead is still processing personal data once the form is submitted. In the EU and UK, writing to cookies or local storage can also require consent under ePrivacy rules depending on the purpose. Configure your consent platform to cover the capture script, mention the practice in your privacy notice, and confirm the approach with your own counsel.

From hidden fields to a source on every lead

Hidden fields are the right tool when the form is the only place you need the data. Once you want the same source on the CRM record, in lead reports and in the conversion events you send back to ad platforms, a first-party tracker that captures UTMs and click IDs on arrival and attaches them to form submissions automatically does the same job without a script per form. That is how EndFrame works: it stores the campaign values against the visitor, links them to each form submission, and can forward the lead to your CRM through a webhook. Either way, the next steps are mapping the values into your CRM, covered in how to pass UTM parameters into your CRM, and reporting on them, covered in lead source tracking.

Frequently asked questions

Why are my hidden UTM fields empty when the lead comes through?

Usually because the script reads the URL only on the page with the form, and the visitor navigated away from the tagged landing page before submitting. Store the values on arrival and read them from storage when the form loads. Redirects that strip the query string are the second most common cause.

Should I store first-touch or last-touch UTMs?

Ideally both, in separate fields. First-touch shows what introduced the lead, last-touch shows what brought them back to convert. If you only have room for one set, decide deliberately and document it, because the two answer different questions.

Can hidden fields capture gclid and fbclid too?

Yes, and they should. Click IDs are what you need to send conversions back to ad platforms later. Treat them exactly like UTMs: read on arrival, store, and write into dedicated hidden fields.

Do I need cookie consent to store UTM values?

It depends on your jurisdiction and how you store them. Writing values to cookies or local storage on the visitor's device can fall under ePrivacy rules in the EU and UK. Check with your own counsel and your consent platform's configuration before deploying.

Try EndFrame

Add a server-side path for your conversions.

EndFrame collects events first-party and forwards conversions server-side to Meta, GA4, TikTok, and webhooks with event-ID deduplication — then credits each conversion to its campaign, with the visit-to-conversion path you can audit.

No credit card required

Keep reading