Skip to content

About

First- and last-touch lead source capture (UTMs + gclid/msclkid/fbclid) into hidden form fields, so every lead's source reaches your CRM. GTM-ready.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

lead-source-capture

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

What it captures

  • 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.

Install (Google Tag Manager)

  1. Tags → New → Custom HTML → paste lead-source-capture.html.
  2. Trigger: Initialization – All Pages.
  3. Advanced settings: tag firing priority 100, "Once per page".
  4. Add the hidden inputs from hidden-fields-example.html to your form and map them to CRM properties.
  5. Test: open your site with ?utm_source=test&gclid=TEST123, submit the form, check the lead in the CRM.

Notes

  • The cookie is lb_src, first-party, 90 days. Rename it or change DAYS to 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.

License

MIT — see LICENSE.


Maintained by Lev Brovtsev — independent performance marketing consultant for clinics. I work with practice owners one-on-one.

About

First- and last-touch lead source capture (UTMs + gclid/msclkid/fbclid) into hidden form fields, so every lead's source reaches your CRM. GTM-ready.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages