To capture the GCLID in a website form, add a hidden field to the form, read the gclid value from the landing page URL, save it in the browser, and write it into the field when the form loads.
The saving step is the one people skip. If a visitor lands on one page and fills in the form on another, the URL no longer contains the click ID, so a script that only reads the current URL leaves the field empty. Google’s offline conversion guide recommends running the script on every page for this reason.
Google’s sample only handles the gclid. The version below also captures gbraid, wbraid, and the UTM values from the same click.
Step 1: add the hidden fields
Add a hidden field to every form for each value you want to keep:
<input type="hidden" name="gclid" />
<input type="hidden" name="gbraid" />
<input type="hidden" name="wbraid" />
<input type="hidden" name="utm_campaign" />
<input type="hidden" name="utm_term" />
<input type="hidden" name="landing_page_url" />
Keep the three click IDs in separate fields. They’re different identifiers, and each has its own field when you upload a conversion to Google Ads:
| ID | When it appears |
|---|---|
gclid | Most ad clicks with auto-tagging turned on |
gbraid | A web ad click that leads to an iOS app |
wbraid | An in-app iOS ad click that leads to a web page |
Google’s upload documentation has the current definitions. You can’t predict which one a click will carry, so capture all three.
If your form plugin generates its own field names, such as input_5, give the field or its wrapper a CSS class named gclid instead. The script below looks for both.
Step 2: add the script
Add this before the closing </body> tag on every page, or as a Custom HTML tag in Google Tag Manager that fires on all pages:
<script>
(function () {
var CLICK_IDS = ['gclid', 'gbraid', 'wbraid'];
var FIELDS = CLICK_IDS.concat(['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']);
var KEY = 'google_ads_click';
var MAX_AGE = 90 * 24 * 60 * 60 * 1000; // 90 days
function readSaved() {
try {
var saved = JSON.parse(localStorage.getItem(KEY));
return saved && Date.now() - saved.savedAt < MAX_AGE ? saved : null;
} catch (e) {
return null;
}
}
function capture() {
var params = new URLSearchParams(location.search);
var gclsrc = params.get('gclsrc');
var hasClickId = CLICK_IDS.some(function (id) { return params.get(id); });
if (!hasClickId || (gclsrc && gclsrc.indexOf('aw') === -1)) return readSaved();
var click = { savedAt: Date.now(), landing_page_url: location.origin + location.pathname };
FIELDS.forEach(function (field) {
if (params.get(field)) click[field] = params.get(field);
});
try {
localStorage.setItem(KEY, JSON.stringify(click));
} catch (e) {}
return click;
}
function fillForms(click) {
Object.keys(click).forEach(function (field) {
if (field === 'savedAt') return;
var selector = 'input[name="' + field + '"], input.' + field + ', .' + field + ' input';
document.querySelectorAll(selector).forEach(function (input) {
input.value = click[field];
});
});
}
var click = capture();
if (!click) return;
fillForms(click);
new MutationObserver(function () { fillForms(click); })
.observe(document.documentElement, { childList: true, subtree: true });
})();
</script>
The script is built around a few decisions:
- A new ad click replaces the old one. IDs from different clicks never mix on one lead.
- A visit with only UTMs changes nothing. A later newsletter click won’t overwrite the ad click.
- Saved clicks expire after 90 days, the same lifetime Google’s sample uses.
- The
gclsrccheck comes from Google’s sample, which skips the value whengclsrcis present withoutaw. - Forms added after page load get filled too, which covers most popups and AJAX forms.
This stores data in the visitor’s browser, so run it under the same consent rules as your other marketing tags. Google’s guide also tells you to follow local cookie consent rules.
Step 3: make sure the values leave the form
A hidden field only helps if its value reaches the next system. Check each handoff:
- Form plugin: confirm the hidden fields are included in the submission data and notifications.
- Zapier or Make: map each new field in the action step. Existing automations won’t include them automatically.
- CRM: add custom fields, and make them long enough not to cut off a long click ID. Google notes that the GCLID is case sensitive, so don’t let any step change its case.
Why the GCLID field is empty
If the setup looks right but values are missing, these are the usual causes:
| Symptom | Likely cause | Fix |
|---|---|---|
| Missing for every paid lead | Auto-tagging is off | Turn on auto-tagging in the Google Ads account settings |
| Missing on the landing page | A redirect dropped the parameters | Fix redirects so the query string survives, including http to https and www rules |
| Works on the landing page, missing on the form page | The value isn’t being saved | Run the script on every page, not only on landing pages |
| Field never fills, no error | The form is in an iframe from another domain | Your page script can’t reach it. Use the form vendor’s hidden field feature and pass the values in the embed URL |
| Lost when the form is on another domain | Browser storage is separate for each domain | Pass the values in the link to the form domain, and run the script there too |
| Value is filled but not submitted | A React or Vue form ignores direct value changes | Read google_ads_click from localStorage when the form submits and add it to the payload |
| The same ID appears on different leads | The value was written into cached HTML | Fill it in the browser, as this script does, not on the server |
| Missing for some visitors only | Privacy tools, ad blockers, or declined consent | Expected. Send email and phone so enhanced conversions can help |
Test it before you trust it
- Open a landing page in a private window with a test value, such as
?gclid=TEST_click_id_0123456789. - Click through to a different page on the site, then open the form.
- Check the hidden field in your browser’s developer tools.
- Submit the form and confirm the value arrives at the final destination, with its case intact.
- Repeat the test with
?wbraid=in place of?gclid=.
This proves your form plumbing works. A made-up ID will still fail if you upload it to Google Ads, so test the upload with a real ad click.
Once the script is live, track the share of paid form leads with a click ID each week. It won’t reach 100%, but a sudden drop usually means a site change broke something, such as a new redirect or a rebuilt form.
When the click ID is missing anyway
Some clicks will never give you an ID. Enhanced conversions for leads give Google a second way to match, using the hashed email or phone from the form. Google still recommends including GCLIDs whenever you can, so use the two together. Consider making email or phone a required field if your form allows it.
Sending click IDs to LeadUp
If you use LeadUp’s form lead scoring, include these same fields in your webhook’s JSON body:
{
"name": "Jordan Reyes",
"email": "jordan@example.com",
"phone": "602-555-0142",
"message": "I was rear-ended in Tempe last week...",
"gclid": "Cj0KCQjw...",
"utm_campaign": "Car Accident - Search",
"utm_term": "car accident lawyer phoenix",
"landing_page_url": "https://example.com/car-accident-lawyer"
}
LeadUp reads gclid, gbraid, and wbraid for conversion uploads, and uses the UTM and page fields to show lead quality by campaign, landing page, and search term. It treats click IDs shorter than 15 characters as missing, so use a longer value when you test.
Once the IDs are arriving, the next question is what to do with them. Start with how to keep spam out of your Google Ads conversions.
