Install the capture script
When someone clicks an ad, the network adds a click ID to your landing page’s URL. A conversion that carries that ID can be matched to the exact click. The capture script saves the ID when the visitor lands, and fills it into hidden fields on your HubSpot forms. When the form is submitted, the click ID lands on the contact, where Ledion reads it at send time.
It’s free on every plan. It’s under 3 KB gzipped, has no dependencies and makes no network requests: nothing it reads reaches Ledion. The click IDs go to HubSpot with the form, like any other field.
Why the click ID matters, what HubSpot captures on its own, and how to check coverage with a HubSpot report: Capture the GCLID and other ad click IDs.
1. Add the script to your site
Paste this tag before </head> on every page of your site:
<script src="https://ledion.io/c/v1.js" async></script>Keep it as its own <script> tag, as above: not type="module", and not bundled into another script. The script reads its options from its own tag, so in any other form it doesn’t see them and runs with the defaults, without waiting for consent.
Optional attributes go on the same tag:
data-consent="wait": read and write nothing until the visitor agrees (consent).data-days="90": how many days to keep a click ID in the visitor’s browser. Anything that isn’t a positive number means 90.data-gclid="gclid": also fill a property of yours with that click ID, here a property namedgclid(your own properties).
<script src="https://ledion.io/c/v1.js" async
data-consent="wait" data-days="90"></script>Settings → Capture script in Ledion shows the tag to copy, with the attributes for your own properties already on it.
2. Add the hidden fields to your forms
The script can only fill fields the form has, so each click ID needs a contact property, added to your forms as a hidden field.
Create the properties first. Ledion doesn’t add any properties to your HubSpot account when you install it. In Ledion, open Settings → Capture script (Change settings). It lists a property for each click ID of your networks, and ticks the ones you don’t have a property for yet. Click the Create button (it says how many), then Create properties to confirm, and Ledion adds them to a property group named Ledion. Nothing else changes in your HubSpot account. Anyone who can open Ledion can create them.
Then, in HubSpot, open each form that collects leads from ads, add the properties for your networks, and mark each one hidden. Settings → Capture script lists the ones you have, by network.
| Network | Hidden fields |
|---|---|
| Google Ads | ledion_gclid, ledion_gbraid, ledion_wbraid |
| Meta | ledion_fbc, ledion_fbp |
| Microsoft Ads | ledion_msclkid |
ledion_rdt_cid, ledion_rdt_uuid |
In the form editor they’re labelled like Ledion: Google click ID (gclid). ledion_fbp and ledion_rdt_uuid are browser IDs that the Meta Pixel and the Reddit Pixel set: they’re only worth adding if that pixel is on your site.
LinkedIn is next. The script also fills ledion_li_fat_id (LinkedIn) and ledion_ttclid (TikTok) on a form that has them, but Ledion doesn’t create either today and doesn’t send to TikTok.
What you'll see: HubSpot form editor: the property Ledion: Google click ID (gclid) added to a lead form and set as a hidden field
If your forms use gibberish detection
HubSpot’s gibberish detection (Marketing Hub or Content Hub Professional and Enterprise) marks a submission as spam when it finds random characters in its text fields. HubSpot doesn’t say whether hidden fields count, and a click ID can look like random characters. A spam submission doesn’t create or update the contact until someone releases it from the spam submissions page. Single-line text properties are included by default, so for each click ID property on your forms, open it in HubSpot’s property settings, go to the Rules tab and clear Include property in Gibberish detection for form submissions.
Your own properties
Already save click IDs in a property of your own, like gclid? Ledion can read it: pick it under Settings → Click IDs (Click IDs). You don’t need Ledion’s property for that click ID.
The script can fill your property too, so it gets the click ID on every page, not only on the landing page. In Settings → Capture script, under Also fill your own properties, pick your property for the click ID, then copy the new tag. It adds an attribute like data-gclid="gclid": the click ID, then your property’s internal name. It works for gclid, gbraid, wbraid, fbc, fbp, msclkid, rdt_cid and rdt_uuid, and only for properties that are on your forms.
HubSpot’s own Google ad click id, Facebook click id and Bing click id properties are different: no form can fill them, and Ledion reads them by default. They need HubSpot’s tracking code on your landing pages. Check their counts in Settings → Click IDs: if contacts created in the last 30 days have no value there, Settings → Capture script ticks Ledion’s property for that click ID.
3. Which forms it fills
- Forms from HubSpot’s new forms editor: the script fills them when they render, whenever that is.
- Your own fields: any
<input name="ledion_gclid">(or anotherledion_name, or a property you named withdata-<click ID>) on the page, for example on a form you post to HubSpot’s Forms API yourself. - Forms with older HubSpot embed code, and forms on pages HubSpot hosts: the script tries, but run the check below before you rely on it.
When the visitor clicks a newer ad, the newer click ID replaces the older one for that network.
4. Wait for consent, if you need it
Without data-consent, the script runs on every page view as soon as it loads. With data-consent="wait", it reads and writes nothing (no cookies, no storage, no form fields) until your page calls window.ledion.consent(true).
Sites with visitors in the EEA, the UK or Switzerland usually need data-consent="wait". Whether the script runs before consent is your decision.
Call it from your consent banner’s code, on every page view where the visitor has agreed. The script doesn’t remember consent.
// When the visitor agrees to advertising cookies:
if (window.ledion) window.ledion.consent(true);
// When they say no, or take it back:
if (window.ledion) window.ledion.consent(false);consent(true)captures the click ID from the URL the page loaded with, even if your site changed the URL since, and fills the forms already on the page.consent(false)deletes what the script stored, empties the fields it filled on this page, and stops for the rest of the page view. Withoutdata-consent="wait", the next page view captures again.window.ledionexists once the script has run. Calls made before that are lost, so keep the check.
What it stores, for your cookie list: one first-party cookie, _ldn_c, and one localStorage entry, ldn_c, both kept for 90 days or your data-days. It also reads cookies that the networks’ own tags set: _fbc, _fbp, li_fat_id and _rdt_uuid.
On a HubSpot system domain like <Hub ID>.hs-sites.com (where HubSpot puts pages that don’t have your own domain), every HubSpot account shares the domain. So there the script uses _ldn_h and ldn_h instead, keeps the cookie on that one host, and skips network cookies that could belong to another HubSpot account’s site. Click IDs then come from the ad link itself.
5. Check it works
Do this once for each kind of form you use.
-
Open a page of your site with a test click ID on the URL, like
https://www.example.com/?gclid=TeSt_123(with your own domain). -
Open the browser’s console and run:
window.ledion.get()You should see the click ID and the time the script first saw it.
click_atrepeats the newest of those times, for this check only: no form field gets it.{ gclid: { value: "TeSt_123", at: 1792488600000 }, click_at: "2026-10-20T09:30:00.000Z" }With
data-consent="wait", it shows{}untilconsent(true)is called. -
Submit a test form on that page. In HubSpot, open the new contact and check that Ledion: Google click ID (gclid) has the value, and your own property too if the tag names one. If it’s empty, email santi@ledion.io with the page’s address.
-
Delete the test contact, or keep it out of workflows that send conversions. Don’t test with a made-up click ID on a record that reaches a won stage: it’s sent as a real conversion.
From then on, Ledion’s Tracking health page shows the share of new contacts from paid traffic that carry each network’s click ID. It checks new contacts once a day (Read Tracking health). Get started marks Install the capture script done once a new contact from the last 30 days has a click ID in a property the script fills.
Known limits
- Non-HubSpot forms: HubSpot’s capture of non-HubSpot forms ignores hidden fields (“The tool doesn’t collect information from any hidden fields”). It also misses forms in iframes, forms sent by JavaScript, single-page apps and forms added after the page loads. So the script can’t carry click IDs through those forms.
- Fields it can’t reach: fields inside an iframe from another domain or inside a shadow DOM, and plain inputs added more than 2 seconds after the page loads (single-page apps, pop-ups). Forms from HubSpot’s new forms editor are always reached.
- Returning visitors: when a form has HubSpot’s Pre-populate fields for returning visitors turned on, HubSpot may overwrite a hidden field’s value.
- Safari:
- In Private Browsing, and on links opened from Mail and Messages, Safari removes
gclid,fbclidandmsclkidfrom the URL.gbraid,wbraidand UTM parameters get through. In regular browsing they still pass, as of Safari 26. - Safari deletes what scripts store, cookies and localStorage, after 7 days without the visitor interacting with your site. Cookies a script sets on a page opened from an ad link last 24 hours at most. The capture script’s storage falls under both.
- So in Safari, the click ID is safest when the visitor fills in a form on the visit that came from the ad. That’s one reason Ledion also matches on email and phone.
- In Private Browsing, and on links opened from Mail and Messages, Safari removes
Something missing or wrong? Email santi@ledion.io.