To capture the GCLID for offline conversions, read the gclid parameter from the landing page URL, store it in local storage or a first-party cookie with a 90-day expiry, write it into a hidden field on every lead form, and save that field on the lead record in your CRM exactly as received. Google publishes a script that does the first three steps. Google now also asks you to capture gbraid, wbraid, the gad_* parameters and an encoded "session attributes" string next to it, because those still attribute a lead when the GCLID is missing.
What the GCLID is and how to check auto-tagging is on is in Google Ads Auto-Tagging. This post is the capture itself.
What does Google's own capture script do?
Google's GCLID setup guide gives a suggested script. Read line by line, it does five things:
- Reads
gclidfrom the URL query string. - Checks the
gclsrcparameter. Ifgclsrcis present and does not containaw, the click ID is ignored. - Saves the GCLID to
localStoragewith an expiry 90 days from now. - On every page load, looks for the form fields you list (by element ID) and fills the stored GCLID in if it has not expired.
- Runs on the
loadevent.
Google's instructions around it:
- Add a hidden input to every lead form, for example
<input type="hidden" id="gclid_field" name="gclid_field">. - Add the script to every page, not just landing pages, ideally in the site template immediately before
</body>. - In Google Tag Manager, the same script can run as a Custom HTML tag on All Pages, if every form uses the same field name.
- Have the CRM store the GCLID in its own custom field on the lead.
- The GCLID is case sensitive. A CRM or spreadsheet that changes case breaks the upload.
- Observe local cookie consent rules.
Google's default script leaves three gaps
The script leaves three gaps.
It overwrites on every new ad click. When a new gclid arrives, the script replaces the stored one, so it keeps no record of how the customer found you the first time. On a multi-location appliance repair site I added that record separately: a Tag Manager tag writes a first-touch cookie on the first visit (UTM source or referrer domain, plus the GCLID) with a 90-day life, only if the cookie does not exist yet, and ignores internal page views. That cookie answers "which channel found this customer". The GCLID stored by Google's script is the one you send with the conversion.
Forms that are not in the page. The script fills fields it can find by ID in the same document. A booking widget or form builder loaded in an iframe is a different document. Google's enhanced conversions checklist suggests postMessage() to pass data between an iframe and the parent page, and the same idea applies here. Otherwise use the form tool's own hidden-field or URL-prefill feature.
Phone calls. A click on a phone number never touches a form. The GCLID for a call has to be captured by call tracking or replaced by a call conversion import keyed by caller number and time. That route is in Google Forwarding Numbers and Call Conversions.
Which other parameters should you capture next to the GCLID?
| Parameter | Why Google wants it | Source |
|---|---|---|
gbraid, wbraid |
iOS click identifiers. The Google Ads API documentation says wbraid is present when a user clicks an ad in an iOS app and lands on your webpage, and gbraid when a user clicks an ad on the web and is sent to your iOS app. Google says to add them to uploads whenever available |
EC for leads configuration |
gad_source, gad_campaignid |
Google says that with offline import you need to capture them from all landing pages and send them with conversions, "particularly important when individual identifiers like gclid and user-provided data are not available" | About gad_* parameters |
| Session attributes | An encoded string built in the browser from the gad_* values, session start time, landing page URL, referrer and user agent |
About session_attributes |
On precedence: the Google Ads API documentation says that when several identifiers are present, Google uses gclid, then wbraid, then gbraid, and that if it has to fall back to wbraid or gbraid, user-provided data on that row is ignored. So capture all of them and send all of them. Do not replace one with another.
How do you capture session attributes?
Google's session_attributes page gives a second script and a second hidden field (session_attributes_field). The script runs only when the landing URL has a gad_* parameter, gclid or gbraid. It collects the gad_* values, session_start_time_usec (microseconds), the full landing URL, document.referrer and navigator.userAgent, base64-encodes them, saves the string in localStorage and fills the hidden field.
Details from the same page that matter when you build it:
- Four sub-fields are required:
gad_source,gad_campaignid,session_start_time_usecandlanding_page_user_agent. The landing URL and referrer are optional. What the gad_* parameters hold, and where redirects lose them, is in what is gad_campaignid. - Never send a partial or placeholder landing URL. Google says incorrect values are "detrimental to modeling" and it is better to leave the field out.
- Plan for about 5 KB of storage in the CRM field. If that is too much, drop the landing URL and referrer.
Where you can send it matters more than how you capture it. The same page says that from February 2, 2026 the Google Ads API no longer accepts new adopters of session attributes or IP address data in conversion imports, and that all new users must use the Data Manager API. The Data Manager API guide accepts the encoded string in adIdentifiers.sessionAttributes. Covered in Google Ads Data Manager API for Offline Conversions.
The CRM needs fields to store what you capture
The capture is useless if the CRM has nowhere to keep it. On the appliance repair account, the job record in the field service software had a lead source field and nothing for a URL, UTM or click ID. The fix there was a lead log on the website side: every form submission is written to a file with the time, the phone number normalized to its last 10 digits, the page URL and the first-touch cookie, so a lead can be joined to the job later by phone even when a dispatcher creates the job by hand.
The minimum per lead:
| Field | Note |
|---|---|
gclid |
Exactly as received. Case sensitive |
gbraid, wbraid |
Keep the columns even when they are empty |
session_attributes |
Text, about 5 KB |
| Lead created time with time zone | The conversion cannot be earlier than the click, and Google says to check the time zone when it is |
| Phone in E.164 and email | The second key for enhanced conversions for leads |
| First-touch source | For your own reporting, not for the upload |
How do you test the capture end to end?
- Open a landing page with a test parameter, for example
?gclid=TEST123&gad_source=1&gad_campaignid=111. Google's gad_* page gives a similar manual test forgad_source: the parameter must still be in the address bar and the page must load, and the parameter is case sensitive. - Click to a different page with a form and check in DevTools that the hidden fields hold the values.
- Submit the form and confirm the CRM lead shows the same GCLID, character for character.
- Close the browser, come back to the site without the parameter, submit again, and confirm the stored GCLID was reused.
- After every change to the form or the tags, repeat with one real test lead. On a cleaning company's site, one small form change made the form service hold every submission for activation, and for about 15 minutes no lead was delivered, until the change was rolled back the same evening.
Do not upload the test GCLID to Google Ads. It does not belong to any ad click. How to test an upload safely is in How to Test a Conversion Upload Without Breaking Bidding.
Put the GCLID script and a hidden field on every page and form
Put Google's GCLID script, or your own equivalent, on every page, with a hidden field on every form. Add the session attributes script and field next to it, and capture gbraid, wbraid and the gad_* values too. Give the CRM a field for each and keep a separate first-touch record for your own reporting. Then run the five-step test above, and repeat it after every form change.
This is part of Google Ads conversion tracking, and joining leads to jobs in the CRM is call tracking and lead attribution. Fixed prices are on pricing, and the free written diagnostic is a good first step.
Related: