Click ID & UTM Capture Script Generator (Capture GCLID in Forms)

Generate one small script that saves gclid, gbraid, wbraid, fbclid (as fbc), msclkid, ttclid, li_fat_id and UTM tags when a visitor lands, and fills the hidden fields of your lead forms — with consent handling and install steps.

Runs in your browser. Nothing is uploaded.For GoogleFor MetaFor MicrosoftFor TikTokFor LinkedIn

Click ID & UTM Capture Script Generator

1 Choose what to capture

Google Ads
Meta, Microsoft, TikTok, LinkedIn
UTM tags and visit

A cookie also works across subdomains and can be read by your server.

Google accepts a GCLID up to 90 days after the click.

When a visitor clicks a second ad

One per line, if your CRM uses other field names. Letters, digits, _ and - only.

2 Your script, fields and test link

Fill in the settings above — your result appears here instantly.

Next step Once leads turn into sales, upload the captured GCLIDs to Google Ads as offline conversions.

Build the offline conversion file

Rules last checked: against the official pages:

How to capture GCLID and UTMs in your lead forms

To capture GCLID values for offline conversions, Google asks for two things in its GCLID setup guide: a hidden field in every lead form, and a script on every page that stores the click ID and fills that field. Google's sample only handles gclid. This generator writes one script for every ad platform's click ID plus your UTM tags, with consent handling built in.

  1. Tick what to keep. gclid, gbraid and wbraid for Google Ads; fbc for Meta; msclkid, ttclid and li_fat_id for Microsoft, TikTok and LinkedIn; and the UTM tags for your own reports.
  2. Pick your site and form tool. You get the hidden fields in that tool's format.
  3. Choose how to handle consent. The script can wait for Google consent mode, or for your own banner, before it saves anything.
  4. Copy the script and add the fields. Follow the install steps shown under the code.
  5. Test it. Open the test link, submit your form and check that the lead shows every test value.
Capture gclid script generator showing the script, hidden fields and test link

What the script does on your site

  • Reads the click IDs on landing. Like Google's sample, it ignores a gclid whose gclsrc doesn't contain aw.
  • Builds fbc for Meta. An fbclid becomes fb.1.<time in ms>.<fbclid>, the format Meta's Conversions API expects. Nothing is lowercased.
  • Keeps them for later pages, per platform. A new Google click replaces only the Google IDs, and a later newsletter visit replaces only the UTM tags — a saved gclid stays until it expires.
  • Fills every matching field by name, ID or CSS class, including forms in pop-ups and JavaScript-built forms.

Install it and use the data

WordPress forms

  1. Gravity Forms: add a Hidden field from Standard Fields for each value and put the value's name (like gclid) in Appearance › Custom CSS Class.
  2. Contact Form 7: add [hidden gclid] tags to the form, and the matching [gclid] mail-tags to the Mail tab.
  3. WPForms: add a Hidden Field from Fancy Fields and type the name in Advanced › CSS Classes.
  4. Elementor Forms: add a field of type Hidden and set its ID on the Advanced tab.

When a lead becomes a sale, export it with its click ID and use the matching upload tool: the gclid goes into Google's Google Click ID column, the msclkid into Microsoft's Microsoft Click ID column, and fbc into the Conversions API's user_data.

Common GCLID capture problems

The hidden field stays empty

Inspect the field in your browser's developer tools. If its name, ID or CSS class doesn't match exactly — gclid, not GCLID — the script can't find it. Use the rename box if your CRM needs another name.

The gclid disappears on redirects

Google warns that the gclid must be passed through every redirect to the final landing page. Test each redirect you use.

Leads from iPhones have no gclid

Google may send gbraid or wbraid instead on some iOS traffic, which is why the script keeps them in fields of their own.

Google rejects the click ID as unreadable

The GCLID is case sensitive. If your CRM or spreadsheet changed it to lowercase or cut it short, the upload fails. Store it in a plain text field.

Frequently asked questions

How do I capture the GCLID in my lead form?

Add a hidden field named gclid to the form, then put a script on every page that reads gclid from the address bar, saves it, and writes it into that field. Google describes these steps in its GCLID offline conversions guide. The generator above writes the script and the hidden field for your form tool.

Where should I store the GCLID?

In the visitor’s browser until they fill in a form — Google’s own sample uses local storage with a 90-day expiry. After that, store it with the lead in your CRM, in a custom field of its own, as Google suggests.

Can I capture UTM parameters and other click IDs too?

Yes. The same script keeps gbraid, wbraid, fbc (from fbclid), msclkid, ttclid, li_fat_id and the UTM tags, each in its own hidden field.

How do I add a hidden GCLID field in Gravity Forms or HubSpot?

In Gravity Forms, add a Hidden field from Standard Fields and type gclid in Appearance › Custom CSS Class. In HubSpot, turn on the Hidden field switch for a gclid field; HubSpot can fill it from the query string on the page the ad opens. On other pages, test with the link above whether this script reaches the form.

Do I need cookie consent to store click IDs?

Google’s GCLID guide asks you to observe local regulations on cookie consent. In the EU and UK that usually means asking first. The script can wait for Google consent mode’s ad_storage, or for your banner to call AdClickCapture.allow(), and it can record the visitor’s choice in ad_user_data and ad_personalization fields for Google’s upload columns. This is not legal advice — check with your adviser.

How long is a GCLID valid for offline conversion uploads?

Google says it keeps the GCLID for 90 days, so you can upload a conversion up to 90 days after the click — and never later than the conversion action’s own window. That is why the script keeps values for 90 days by default.

Need help setting this up? Talk to EmproIT