To attribute leads in HubSpot or GoHighLevel, capture the click IDs (gclid, gbraid, wbraid, fbclid) and UTM parameters when a visitor lands, store them in a first-party cookie or localStorage so they survive page changes, write them into hidden fields on every form, and map those fields to contact properties in the CRM. Do that consistently and every lead arrives with the campaign that produced it, which is what you need for source reporting and for sending qualified leads and sales back to Google Ads and Meta.
Most agencies discover the gap when a client asks which campaigns produced their best customers and the CRM says "Direct" or "Website" for half of them. Platform reports say how many leads each campaign drove. Only the CRM knows which of those leads became revenue. Connecting the two is the job of this setup.
What to capture
| Parameter | Comes from | Used for |
gclid | Google Ads auto-tagging | Offline conversion imports to Google Ads, campaign lookup |
gbraid, wbraid | Google Ads on some iOS traffic, in place of gclid | Offline imports where gclid is absent |
fbclid | Meta ad and organic clicks | Building the fbc value for Conversions API events from the CRM |
utm_source, utm_medium, utm_campaign, utm_content, utm_term | Your tagged links | Human-readable source reporting in the CRM |
| Landing page URL and referrer | The browser | Debugging and organic or referral leads with no UTMs |
Capture all of them even if the client only runs one platform today. Adding a field later means every earlier lead has a blank.
Step 1: Capture parameters on landing
Parameters only exist in the URL of the first page. As soon as the visitor clicks to another page, they are gone. So a script needs to read them on arrival and store them. You can run this as a Custom HTML tag in GTM on all pages, or in the site code.
(function () {
var keys = ["gclid","gbraid","wbraid","fbclid","utm_source","utm_medium",
"utm_campaign","utm_content","utm_term"];
var params = new URLSearchParams(window.location.search);
var found = {};
keys.forEach(function (k) { if (params.get(k)) found[k] = params.get(k); });
if (Object.keys(found).length === 0) return;
found.landing_page = window.location.href.split("?")[0];
found.captured_at = new Date().toISOString();
try {
if (!localStorage.getItem("ft_attr")) {
localStorage.setItem("ft_attr", JSON.stringify(found));
}
localStorage.setItem("lt_attr", JSON.stringify(found));
} catch (e) {}
})();
This stores a first-touch record once and overwrites a latest-touch record on every tagged visit. Adjust to taste, but keep three rules:
- Only overwrite on a tagged visit. A later untagged visit should not wipe the paid click that brought the person in.
- Respect consent. Storing click identifiers is storage for advertising purposes in many jurisdictions. Fire the tag only when the relevant consent is granted, using the same consent setup as your ad tags.
- Set an expiry. localStorage does not expire on its own. Add a timestamp check, or use a first-party cookie with an expiry that matches the longest attribution window you care about. Google Ads offline imports require the click to be within the conversion action's click-through window, so a long-dead gclid is of limited use.
Cookies versus localStorage: cookies can be read by the server and across subdomains if set on the root domain; localStorage is per origin, so www.client.com and book.client.com do not share it. If forms live on a different subdomain, use a cookie on the root domain.
Step 2: Add hidden fields to every form
Each form needs hidden fields that the stored values are written into before submission. Name them to match the CRM properties so mapping is obvious.
function fillAttr() {
var lt = JSON.parse(localStorage.getItem("lt_attr") || "{}");
var ft = JSON.parse(localStorage.getItem("ft_attr") || "{}");
document.querySelectorAll("form").forEach(function (form) {
Object.keys(lt).forEach(function (k) {
var input = form.querySelector('input[name="' + k + '"]');
if (input && !input.value) input.value = lt[k];
});
var fs = form.querySelector('input[name="first_utm_source"]');
if (fs && ft.utm_source) fs.value = ft.utm_source;
});
}
Run it after forms render, not just on page load. Many form builders inject forms late, and popups render only when opened. A small delay plus a retry, or a callback the form tool provides, avoids empty fields.
Step 3: Map to HubSpot contact properties
HubSpot already records its own source data through its tracking code: the Original Source and Latest Source properties and their drill-down fields. Those are useful but they are HubSpot's interpretation, and they do not store the raw click IDs you need for offline imports. Add your own properties alongside them.
- In HubSpot settings, create contact properties (single-line text) for
gclid, gbraid, wbraid, fbclid, each UTM, landing page, and first-touch source and campaign. Group them in a property group such as "Ad attribution".
- HubSpot forms: add the properties as hidden fields in the form editor. HubSpot can prefill hidden fields from query parameters with the same name, which covers the landing page, but you still need the stored values for visitors who navigate before converting. Write them in with the form's on-ready callback.
- Non-HubSpot forms (WordPress form plugins, Webflow, custom): if they are captured through HubSpot's non-HubSpot forms feature or sent through an integration, check that the hidden field names map to the right properties. Test it; automatic mapping is not guaranteed.
- Decide property update behavior. If a contact converts twice, a workflow can copy first-touch values only when empty, and let latest-touch values update.
If the client connects Google Ads in HubSpot, HubSpot can also track ad interactions natively. That does not replace storing the raw gclid on the contact if you plan to use offline imports from another tool.
Step 4: Map to GoHighLevel custom fields
GoHighLevel records attribution data on contacts from its own forms, surveys, funnels and calendars, including UTM values and the session source, typically split into first and latest attribution. Check what is actually captured in the specific sub-account before relying on it, because embed method and page setup affect it.
- In the sub-account settings, create custom fields (single-line text) for
gclid, gbraid, wbraid, fbclid and the UTMs you want stored explicitly.
- In each GoHighLevel form or survey, add those custom fields as hidden fields. Hidden fields can be populated from URL query parameters, so match the query key names exactly.
- For forms embedded on an external site through an iframe, the form cannot see the parent page's URL or storage. Pass the stored values into the iframe URL as query parameters when you build the embed, or use the native attribution data GoHighLevel records and verify it against test leads.
- Build a smart list or report filtered on these fields so the team can see source at a glance.
Embedded forms and calendars
Embeds are where attribution breaks most often.
- Iframes run on a different origin. They cannot read the parent page's cookies, localStorage or URL. You must pass values in through the iframe source URL.
- Calendars (Calendly, GoHighLevel calendars, HubSpot meetings) often create or update the contact themselves. Check whether they accept UTM parameters on the booking link and pass them to the CRM. Many do for UTMs but not for arbitrary parameters like gclid.
- Multi-step funnels on a separate domain lose localStorage entirely. Use cross-domain linking that carries parameters, or a cookie on a shared root domain.
- Chat widgets that create contacts rarely carry any source data. Treat chat leads as a known gap or pass values in via the widget's API if it has one.
First-touch vs latest-touch
Store both. They answer different questions.
| Model | Answers | Use for |
| First-touch | What introduced this person? | Evaluating prospecting and awareness campaigns |
| Latest-touch (before conversion) | What brought them back to convert? | Matching platform reporting, offline imports (the latest gclid is usually the one to send) |
For offline conversion imports to Google Ads, send the click ID from the click that preceded the conversion, which is normally the latest-touch gclid. Our guide on offline conversion imports from a CRM covers the upload side.
Duplicate contacts
When a returning lead submits again, both CRMs typically deduplicate on email and update the existing contact. That is good for data hygiene, and a risk for attribution: the second submission's hidden fields can overwrite the first. Decide deliberately.
- Keep first-touch fields write-once (a workflow that only sets them when empty).
- Let latest-touch fields update, and log each conversion as a separate activity, form submission or opportunity so the history is kept.
- Watch for duplicates created by phone-only leads, calendar bookings with a different email, or integrations that match on phone in one tool and email in another.
Building a source report
Once fields are populated, build a simple report in the CRM: leads, qualified leads and won deals grouped by utm_source, utm_medium and utm_campaign, with a separate count of leads that have a gclid or fbclid but no UTMs. That last group tells you whether auto-tagged Google traffic needs a campaign lookup, or whether your UTM coverage has gaps. Consistent UTM values make this report usable; see our UTM naming convention for agencies.
Readiness for offline conversion imports
The point of storing click IDs is to send outcomes back to the ad platforms. Before you build imports, check:
- The share of paid leads with a gclid, gbraid or wbraid stored. If many paid leads are blank, fix capture first.
- CRM stages that mean something: qualified, opportunity, won, with timestamps.
- A value for each stage, even an estimate. See assigning conversion values to leads.
- Email and phone stored in a consistent format, for enhanced conversions for leads and Meta match quality.
For Meta, the equivalent is sending CRM outcomes as Conversions API events. Meta matches those mainly on hashed email and phone, plus the fbc value rebuilt from the stored fbclid and its capture time. That is another reason to store the capture timestamp alongside the click ID, not just the ID itself. Our guide to Meta event match quality covers which parameters matter most.
Testing with tagged URLs
Test every form with a URL per channel, then check the contact record.
- Build test URLs: one with
?gclid=TEST_GCLID_123&utm_source=google&utm_medium=cpc&utm_campaign=test, one with fbclid and Meta UTMs, one with email UTMs, and one with nothing.
- For each, land on the page, navigate to a second page, then submit the form. Navigation is the part that catches broken persistence.
- Open the contact in HubSpot or GoHighLevel and confirm every field has the expected value.
- Repeat on mobile, on any embedded or iframe form, on the calendar, and with consent declined, to confirm nothing is stored without consent.
- Submit again from a different tagged URL with the same email and confirm first-touch did not change.
- Delete or tag the test contacts so they do not pollute reports.
Common mistakes
- Reading parameters only on the form page, so anyone who browsed first arrives blank.
- Hidden fields added to the main form but not the popup, footer or landing page variants.
- Field names that differ by one character from the query parameter, so prefill silently fails.
- Mixed-case UTM values that split one campaign into several rows.
- Trusting the CRM's native source fields without ever testing them.
- Storing click IDs without consent.
Getting the CRM side done
Our CRM lead attribution service sets up capture, hidden fields and property mapping in HubSpot or GoHighLevel, and tests it with tagged URLs per channel, all in the client's own accounts under your agency's name.