Skip to content

CRM AttributionPublished 11 min read

CRM Lead Source Attribution in HubSpot and GoHighLevel

How to capture gclid, fbclid and UTMs on landing, keep them through the visit, and get them onto every contact in HubSpot or GoHighLevel.

Muhammad Qitmeer, founder of Augere Labs
Muhammad Qitmeer
Co-founder and CEO, Augere Labs
Share

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

ParameterComes fromUsed for
gclidGoogle Ads auto-taggingOffline conversion imports to Google Ads, campaign lookup
gbraid, wbraidGoogle Ads on some iOS traffic, in place of gclidOffline imports where gclid is absent
fbclidMeta ad and organic clicksBuilding the fbc value for Conversions API events from the CRM
utm_source, utm_medium, utm_campaign, utm_content, utm_termYour tagged linksHuman-readable source reporting in the CRM
Landing page URL and referrerThe browserDebugging 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.

  1. 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".
  2. 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.
  3. 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.
  4. 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.

  1. In the sub-account settings, create custom fields (single-line text) for gclid, gbraid, wbraid, fbclid and the UTMs you want stored explicitly.
  2. 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.
  3. 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.
  4. 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.

ModelAnswersUse for
First-touchWhat 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.

  1. 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.
  2. For each, land on the page, navigate to a second page, then submit the form. Navigation is the part that catches broken persistence.
  3. Open the contact in HubSpot or GoHighLevel and confirm every field has the expected value.
  4. Repeat on mobile, on any embedded or iframe form, on the calendar, and with consent declined, to confirm nothing is stored without consent.
  5. Submit again from a different tagged URL with the same email and confirm first-touch did not change.
  6. 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.

Just one quick fix, not a whole account? Our founder takes small fixed-price jobs on Fiverr: Google Ads conversion tracking fix

Frequently asked questions

Does HubSpot store the gclid automatically?

HubSpot records its own source properties, and its Google Ads integration tracks ad interactions, but you should still create a gclid contact property and fill it through a hidden field if you plan to run offline conversion imports.

Can GoHighLevel capture UTM parameters?

Yes. GoHighLevel records attribution data from its native forms, funnels and calendars, and hidden custom fields can be filled from URL query parameters. Test embedded forms carefully, because iframes cannot see the parent page URL.

Should I use cookies or localStorage to keep UTMs?

Either works on a single domain. Use a cookie set on the root domain if forms or funnels live on a different subdomain, since localStorage is not shared across origins.

Should the CRM store first-touch or last-touch source?

Both. First-touch shows what introduced the lead, and latest-touch shows what brought them back to convert and is usually the click ID to use for offline imports.

What are gbraid and wbraid?

They are Google Ads click identifiers used on some iOS traffic in place of gclid. Capture them the same way so those leads can still be matched in offline imports.

Muhammad Qitmeer

Written by

Muhammad Qitmeer, founder of Augere Labs

Augere Labs is the white-label tracking partner behind marketing agencies. If a client account has numbers you don't trust, I'm happy to look at it with you and tell you straight what's wrong.

Connect on LinkedIn