Skip to main content
Free tools

Free UTM hidden field generator

Capture UTM parameters, click IDs, and referrer into hidden form fields, so every submission tells you which campaign sent it. Plain HTML and JavaScript, no dependencies, no signup required.

Fields to capture

Keep the values

When to use this: use this if visitors browse a few pages before reaching your form. The values survive navigation and are forgotten when the tab closes.

Generated code

<!-- Place the hidden fields inside your <form> -->
<input type="hidden" name="utm_source">
<input type="hidden" name="utm_medium">
<input type="hidden" name="utm_campaign">
<input type="hidden" name="utm_term">
<input type="hidden" name="utm_content">

<!-- Place the script before </body> -->
<script>
  (function () {
    var current = {};
    var query = new URLSearchParams(window.location.search);
    ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"].forEach(function (name) {
      var value = query.get(name);
      if (value) current[name] = value;
    });
    var data = current;
    try {
      var stored = JSON.parse(sessionStorage.getItem("form_attribution"));
      var hasCampaign = Object.keys(current).some(function (name) { return name !== "referrer" && name !== "landing_page"; });
      if (Object.keys(current).length > 0 && (!stored || hasCampaign)) {
        stored = { saved: Date.now(), values: current };
        sessionStorage.setItem("form_attribution", JSON.stringify(stored));
      }
      if (stored) data = stored.values;
    } catch (error) {}
    Object.keys(data).forEach(function (name) {
      var inputs = document.querySelectorAll('input[type="hidden"][name="' + name + '"]');
      for (var i = 0; i < inputs.length; i++) inputs[i].value = data[name];
    });
  })();
</script>

How it works

From landing page to submission.

Analytics tools see your UTM parameters; your form does not. Three small steps close that gap without a tag manager or a tracking script.

Read the URL

When a visitor lands from an ad or newsletter, the script reads utm_source, utm_medium, and the other tags straight from the address bar. Referrer and landing page come from the browser, so untagged visits still tell you something.

Persist the visit

The tags vanish when the visitor clicks to another page, so the script stores them: in sessionStorage for the tab, or in localStorage for 30 days. Last touch credits the newest campaign, first touch the one that started the relationship.

Fill the hidden fields

On the form's page, the script fills each hidden input by name. The visitor sees nothing, and the submission lands in your inbox or spreadsheet carrying utm_source, utm_campaign, and the rest.

How to use it

Capture UTM parameters in three steps.

Without hidden fields, a lead that came from your best campaign looks identical to one that wandered in. This generator writes the markup and the capture script for you.

  1. 01

    Pick the fields

    utm_source, medium, and campaign cover most reporting. Add gclid or fbclid if you run paid ads, and referrer for untagged visits.

  2. 02

    Choose persistence

    Page only reads the URL at load. Session keeps values while the visitor browses. Last touch credits the newest campaign, first touch the original one.

  3. 03

    Paste the snippet

    Hidden inputs go inside your form, the script goes before the closing body tag. Every submission now names its campaign.

Building the form itself too? The free HTML form generator writes accessible markup these hidden fields drop straight into, and a backend like Form Plume receives the attribution values with every submission.

FAQ

Questions before you
track a single click.

UTM parameters are tags added to a URL, like utm_source=newsletter or utm_campaign=spring_sale, that identify where a visitor came from. Analytics tools read them automatically, but your form does not: unless you capture them into fields, a submission arrives with no trace of the campaign that produced it.

One line. Zero backend.

The form backend you don’t have to build.

Free foreverNo credit cardSet up in under a minute