A small first-party script that records where every website lead came from — first touch and last touch — and writes it into hidden fields on your form, so the source arrives in your CRM with the lead.
Built for clinics and other high-ticket service businesses that want to check ad-platform numbers against the CRM: booked patients, not form fills.
Full walkthrough (why, GTM setup with screenshots, CRM fields, weekly check): Lead source tracking: verify every lead in your CRM
- UTMs:
utm_source,utm_medium,utm_campaign,utm_term,utm_content - Click IDs:
gclid,gbraid,wbraid(Google Ads),msclkid(Microsoft Ads),fbclid(Meta) - Landing page, referrer and a UTC timestamp for each touch
- GA4 client ID (
ga_client_id) to join CRM leads with GA4
First touch is never overwritten. Last touch updates only when a visit arrives with UTMs or a click ID, so a later direct visit doesn't wipe the paid source.
- Tags → New → Custom HTML → paste
lead-source-capture.html. - Trigger: Initialization – All Pages.
- Advanced settings: tag firing priority 100, "Once per page".
- Add the hidden inputs from
hidden-fields-example.htmlto your form and map them to CRM properties. - Test: open your site with
?utm_source=test&gclid=TEST123, submit the form, check the lead in the CRM.
- The cookie is
lb_src, first-party, 90 days. Rename it or changeDAYSto match your consult cycle. - Timestamps are ISO 8601 UTC (
Z). Convert to the clinic's time zone before comparing a day of CRM leads with a day of GA4 data. - Hidden fields are filled on
DOMContentLoaded. Forms injected later by JavaScript or embedded in an iframe (many scheduling widgets) need their own hand-off. - Healthcare: the script stores marketing parameters only. Don't add form contents, names, emails or phone numbers to the cookie, and don't send patient data to ad platforms. Check consent requirements for your region.
MIT — see LICENSE.
Maintained by Lev Brovtsev — independent performance marketing consultant for clinics. I work with practice owners one-on-one.