Dev.to WebDev ๐Ÿ›  Dev ๐Ÿ‘ 0 ๐Ÿ“– 10 min read

One lead event for calls, quote forms, and text-back replies: GA4 lead tracking for local service sites

How to send every real lead on a plumber, roofer, or HVAC site to GA4 as a single generate_lead event, with the code, the consent caveats, and the build-time mistake that quietly removes your tag. Most local service web

One lead event for calls, quote forms, and text-back replies: GA4 lead tracking for local service sites

How to send every real lead on a plumber, roofer, or HVAC site to GA4 as a single generate_lead event, with the code, the consent caveats, and the build-time mistake that quietly removes your tag.

Most local service websites have three ways a lead shows up: someone taps the phone number, someone sends a quote request, or someone who called and got no answer replies to an automatic text. In GA4 those usually end up as three unrelated things, or not at all. The phone tap is never measured, the form fires form_submit even when validation fails, and the text reply lives only in a phone app.

I'm Colton Wehr, founder of Kinexis Digital. We build website plans for trade businesses in the US, and lead tracking is the part of a build owners ask about least and complain about most. This post is the pattern I use: one recommended event, generate_lead, fired from three places, with a method parameter that tells you which path it came from. It's written for developers and technical marketers, so there is code.

Why one event beats three

GA4 lets you mark events as key events (Google renamed "conversions" to "key events" in 2024). It's tempting to mark click_to_call, form_submit, quote_request, and sms_reply all as key events. Don't. With several key events:

  • Reports and any Google Ads import count every one of them, so one person who taps the number and then fills the form becomes two "conversions."
  • Each event gets its own parameters and naming, so comparing call leads with form leads takes an exploration instead of a filter.
  • Someone eventually stars a vanity event like scroll or file_download, and your conversion rate stops meaning anything.

generate_lead is one of Google's recommended events, so GA4 already understands it. Send it from every path, add a method parameter, and mark only generate_lead as a key event. Then you can answer "what share of our leads are calls?" with one breakdown.

Median search-ad conversion rate by home-services category, from LocaliQ's 2025 benchmarks. Plumbing 7.63%, heating 7.48%, AC 6.56%, electrical 9.08%, roofing 3.70%.
Median search-ad conversion rates by trade, LocaliQ 2025 home services benchmarks (3,211 US campaigns, April 2024 to March 2025). Every one of these rates is leads divided by clicks. If your lead count is wrong, the rate is wrong too.

That chart is the reason this matters. LocaliQ's 2025 benchmarks put the median search-ad conversion rate at 7.63% for plumbing and 3.70% for roofing and gutters (source). If your setup double-counts a call plus a form, you look better than the benchmark when you aren't. If it misses phone taps, you look worse. Either way, you end up making budget decisions on bad data.

The event contract

Write the contract down before you write any code. This is mine:

Parameter Type Values Why
method string call, form, sms_reply Which path the lead came from
page_type string home, service, industry, blog, contact Which page templates produce leads
link_position string header, hero, sticky, footer, body Calls only: which phone link was tapped
form_id string quote, preview, contact Forms only
value / currency number / string optional Only if you have a real average job value. Don't make one up

Register method, page_type, link_position, and form_id as event-scoped dimensions under Admin รขโ€ โ€™ Custom definitions, or they won't appear in standard reports. Never send names, emails, phone numbers, or the message text. Google's analytics terms prohibit sending personally identifiable information, and a quote request is full of it.

Path 1: taps on the phone number

A tap on a tel: link shows intent. It doesn't prove a conversation happened. GA4 can't tell whether the call connected, lasted 30 seconds, or went to voicemail. Track the tap anyway, because it's the only signal a static site gets, and label it honestly in reports as "call tap."

Use one delegated listener, not an onclick on every link. Trade sites tend to put the number in the header, the hero, a sticky bar, and the footer. On our own site, a crawl of all 78 English sitemap URLs on November 24 found tel: links on every page, four on most.

// lead-tracking.js: load after gtag is configured
function sendLead(params) {
  if (typeof window.gtag !== 'function') return; // tag not loaded (consent denied or missing ID)
  window.gtag('event', 'generate_lead', params);
}

document.addEventListener('click', (e) => {
  const link = e.target.closest('a[href^="tel:"]');
  if (!link) return;

  // De-duplicate: one call lead per page view
  if (sessionStorage.getItem('kx_call_lead_' + location.pathname)) return;
  sessionStorage.setItem('kx_call_lead_' + location.pathname, '1');

  sendLead({
    method: 'call',
    page_type: document.body.dataset.pageType || 'other',
    link_position: link.dataset.position || 'body',
  });
});

Put the position in the markup (<a href="tel:+13075550100" data-position="sticky">) so the tracking code never has to work out the layout. The de-duplication matters on mobile. People tap, change their mind, go back, and tap again.

If you need to count calls that actually connected and lasted, that's call-tracking territory. You need a forwarding number from a call-tracking provider, and their webhook tells you about completed calls. You then send those server-side with path 3 below. For what it's worth, the 60-day lead guarantee on our Lead System and Plus plans counts a call as a tracked lead only if it runs 30 seconds or more, because a tap alone isn't a lead.

Path 2: quote forms, counted only when the server accepts them

GA4's enhanced measurement includes "form interactions," which fire form_start and form_submit automatically. On JavaScript-handled forms it's unreliable. It can count a submit attempt that your validation or your spam filter then rejects, and it knows nothing about whether your server actually stored the lead. Turn it off in the web stream settings and fire the event yourself, after the server responds with success.

const form = document.querySelector('form[data-form-id="quote"]');

form?.addEventListener('submit', async (e) => {
  e.preventDefault();
  const res = await fetch('/api/quote', {
    method: 'POST',
    body: new FormData(form),
  });

  if (res.ok) {
    sendLead({ method: 'form', form_id: 'quote', page_type: document.body.dataset.pageType || 'other' });
    form.replaceWith(Object.assign(document.createElement('p'), { textContent: 'Thanks, we got it. Expect a call or text soon.' }));
  } else {
    // show the error; no event, because there is no lead
  }
});

The form itself matters as much as the tag. A short quote form gets finished, and one with twelve fields gets abandoned. We wrote up the field-by-field version in how to build a contractor quote form people actually finish.

Screenshot of the Kinexis Digital contact page: a Tell Us About Your Business form with four checkbox options, seven fields and a Send My Message button, next to a card with the phone number, email and a Book a call button.
The quote form on kinexisdigital.com/contact (desktop, captured with Playwright on November 24, 2026). Two lead paths on one screen: the form and the phone number. The form's success state, not the button click, is what should fire generate_lead.

Path 3: text-back replies and other server-side leads

Missed-call text-back sends an automatic text when a call goes unanswered. When the caller replies, that's a lead, but it happens on a phone network, not in a browser. To get it into GA4 you send it from your server with the Measurement Protocol.

// server-only: e.g. a Next.js route handler receiving your SMS provider's webhook
export async function POST(req) {
  const { from, body } = await req.json();      // never forward these to GA4
  const clientId = await lookupClientId(from) ?? `sms.${Date.now()}`;

  await fetch(
    `https://www.google-analytics.com/mp/collect?measurement_id=${process.env.GA_MEASUREMENT_ID}&api_secret=${process.env.GA_MP_API_SECRET}`,
    {
      method: 'POST',
      body: JSON.stringify({
        client_id: clientId,
        events: [{ name: 'generate_lead', params: { method: 'sms_reply', page_type: 'offline' } }],
      }),
    }
  );
  return new Response('ok');
}

Three things to know before you rely on this:

  1. Attribution is weak. Unless you can tie the reply back to a client_id captured on the site (for example, stored when the visitor tapped the number), GA4 sees a brand-new user with no traffic source. You'll count the lead but won't know where it came from. Keep your CRM or lead log as the source of truth for attribution.
  2. The API secret is a secret. The measurement ID (G-รขโ‚ฌยฆ) ships in the browser and is public. The Measurement Protocol api_secret must live only in server-side environment variables. Never put it in a NEXT_PUBLIC_ variable, a client bundle, or a committed .env file.
  3. Carrier approval comes first. Business texting in the US runs through 10DLC registration, and carriers can take time to approve it, or refuse. Don't ship the tracking before the texting actually works.

If you want to estimate what unanswered calls might be worth before you build any of this, our missed-call calculator lets you plug in your own numbers. It doesn't assume any for you.

Diagram: tel: link taps and accepted quote forms send generate_lead from the browser, text-back replies send it from the server via Measurement Protocol, and GA4 marks generate_lead as the only key event.
Illustrative architecture: three lead paths, one event, one key event. Browser paths use gtag and server paths use the Measurement Protocol.

Consent: what GA4 won't see

If your site respects consent (and in many places it has to), then when a visitor rejects analytics the tag either doesn't load or, with Consent Mode, sends only cookieless pings. Our own banner says it plainly: analytics and ads load only if you allow them.

So GA4 will undercount leads, by design. The fix isn't to fire before consent. Keep a first-party lead log (form submissions in your database, call records from your phone provider) and treat GA4 as a sample for traffic source and page analysis. When the two disagree, the lead log wins.

Marking the key event, and unmarking everything else

In GA4: Admin รขโ€ โ€™ Data display รขโ€ โ€™ Events. Find generate_lead (it appears after the first one is received) and mark it as a key event. Then go through the list and unmark anything else: form_submit, click, anything a plugin or a previous agency added. If you import into Google Ads, import generate_lead only.

Then test each path:

  • Open the site with ?debug_mode=true handled in your config, or use Tag Assistant, and watch Admin รขโ€ โ€™ DebugView.
  • Tap each phone link position once. You should see one generate_lead with method=call per page view, not one per tap.
  • Submit the form with a deliberately invalid field. There should be no event. Then submit it properly and check for exactly one.
  • Send a test reply to your text-back number and confirm the Measurement Protocol hit in DebugView (validate payloads first against the /debug/mp/collect endpoint).

The build-time trap: a missing measurement ID ships no tag

This one cost us a release. In Next.js, any NEXT_PUBLIC_ environment variable is inlined into the JavaScript at build time. If your GA component reads process.env.NEXT_PUBLIC_GA_ID and the variable isn't set in the environment that runs the build, the build still succeeds, the site still deploys, and it ships with no GA tag at all. Nothing errors. Your lead count just goes to zero and looks like a bad week.

Two guards that cost almost nothing:

// next.config.js: fail the production build if the measurement ID is missing or malformed
const id = process.env.NEXT_PUBLIC_GA_ID;
if (process.env.NODE_ENV === 'production' && !/^G-[A-Z0-9]{6,}$/.test(id || '')) {
  throw new Error('NEXT_PUBLIC_GA_ID missing or invalid at build time');
}

Then add a post-deploy check that fetches the homepage and asserts the measurement ID appears in the HTML. Ten lines in CI save you weeks of empty reports.

A checklist you can copy

  • [ ] generate_lead is the only key event. Everything else is unmarked.
  • [ ] Enhanced measurement "form interactions" is off. Forms fire only after the server returns 2xx.
  • [ ] One delegated tel: listener, positions in data- attributes, one call lead per page view.
  • [ ] Text-back replies and completed calls are sent server-side, and the API secret lives only on the server.
  • [ ] No PII in any parameter.
  • [ ] method, page_type, link_position, and form_id are registered as event-scoped dimensions.
  • [ ] Build fails without a valid measurement ID, and a post-deploy check confirms the tag is in the HTML.
  • [ ] A first-party lead log exists, and GA4 is treated as a sample.

Every Kinexis plan includes form-lead tracking, and Lead System and Plus add call tracking with a monthly report. Pricing is on our plans page if you'd rather not wire this up yourself.

If you run a trade business and skipped to the end

You don't need to read the code. What matters is that your website should be able to tell you how many people called or asked for a quote last month, and from which page. If it can't, that's the first thing to fix, before any redesign. If you'd like to see what a lead-ready homepage for your business could look like, we make a free homepage preview in two business days, with no card and no obligation.

Colton Wehr is the founder of Kinexis Digital, which builds website plans for local service businesses in the United States.

๐Ÿ“ฐ Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.