A San Diego plumber we work with gets most of his leads the same way: someone searches, lands on the site from an ad, and taps the phone number. The form on the page converts a handful of people a month. The phone converts several times that. His Google Ads account only knew about the form. Every call looked like it came from nowhere, so the campaign that produced the calls got its budget trimmed and the campaign that produced the forms got a raise.
If you build sites for service businesses, this is the gap you are most likely leaving open. A tel: link is not a pageview. The conversion happens off the web, on a phone, and nothing in your analytics stack sees it unless you wire it up yourself. Here is a small Next.js setup that fixes the three places the information gets lost, with no call tracking subscription required. The business side of this problem, how an owner can tell whether ad spend is producing jobs or just clicks, is covered on our journal. This post is the developer side.
Where the source gets lost
There are three leaks. First, the visitor arrives with utm_source, utm_campaign, and a gclid in the URL, then navigates to the services page, and the query string is gone. Second, the visitor comes back two days later by typing the domain, and even the referrer is gone. Third, when the call happens, nobody writes down which ad it came from, so there is nothing to send back to Google Ads as a conversion.
Fix the first two with a cookie set in middleware. Fix the third by attaching that cookie to the phone click and recording it where the office can see it.
Step 1: capture first touch in middleware
Middleware runs before the page renders, on every request, so it is the right place to catch the landing URL once and remember it.
// middleware.ts import { NextResponse, type NextRequest } from "next/server"; const KEYS = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "gclid", "gbraid", "wbraid"]; const COOKIE = "lu_src"; const NINETY_DAYS = 60 * 60 * 24 * 90; export function middleware(req: NextRequest) { const res = NextResponse.next(); if (req.cookies.has(COOKIE)) return res; // first touch wins const params = req.nextUrl.searchParams; const found: Record<string, string> = {}; for (const k of KEYS) { const v = params.get(k); if (v) found[k] = v.slice(0, 200); } if (Object.keys(found).length === 0) return res; found.landed = req.nextUrl.pathname; found.ts = new Date().toISOString(); res.cookies.set(COOKIE, JSON.stringify(found), { maxAge: NINETY_DAYS, path: "/", sameSite: "lax", secure: true, }); return res; } export const config = { matcher: ["/((?!_next|api|.*\\..*).*)"], }; Two decisions in that code are worth being deliberate about. The cookie is first touch: if it already exists, the middleware does nothing. For a service business, the first ad click is usually the one that did the work, and a return visit from a bookmark should not overwrite it. If you want last touch as well, store a second cookie and send both. The other decision is the ninety day window. Google Ads only counts an uploaded conversion if it lands inside the conversion window you set on the conversion action, and the longest window you can set is ninety days, so the cookie should live at least that long.
Notice the cookie is not httpOnly. The click handler on the client needs to read it.
Step 2: make the phone link carry its source
Every phone number on the site should go through one component. That single component reads the cookie, fires an analytics event, and tells your own server about the click.
// components/PhoneLink.tsx "use client"; function readSource() { const raw = document.cookie .split("; ") .find((c) => c.startsWith("lu_src=")) ?.slice("lu_src=".length); try { return raw ? JSON.parse(decodeURIComponent(raw)) : {}; } catch { return {}; } } export function PhoneLink({ number, label }: { number: string; label?: string }) { const display = label ?? number; const tel = number.replace(/[^\d+]/g, ""); function onClick() { const src = readSource(); const touch = window.matchMedia("(pointer: coarse)").matches; window.gtag?.("event", "phone_call_click", { utm_source: src.utm_source ?? "(none)", utm_campaign: src.utm_campaign ?? "(none)", gclid: src.gclid ?? "", touch_device: touch, page_path: location.pathname, }); navigator.sendBeacon( "/api/call-click", JSON.stringify({ ...src, page: location.pathname, touch, at: Date.now() }) ); } return ( <a href={`tel:${tel}`} onClick={onClick}> {display} </a> ); } sendBeacon matters here. A tel: link hands off to the phone app immediately, and a normal fetch can get cancelled mid flight. Beacons survive the navigation.
The touch_device flag is the single most useful field in that payload. On a phone, tapping a tel: link starts a call. On a desktop, clicking one usually opens a dialog asking which app to use and the person closes it. If you count every click as a call, your desktop campaigns will look better than they are. In GA4, build the conversion on phone_call_click where touch_device is true, and treat the rest as intent, not outcome.
Step 3: record the click where the office can act on it
The API route does two things: it writes the click somewhere durable, and it stamps the time so a human can match it to the call log later.
// app/api/call-click/route.ts import { NextResponse } from "next/server"; export async function POST(req: Request) { const body = await req.json().catch(() => null); if (!body) return NextResponse.json({ ok: false }, { status: 400 }); const row = { at: new Date(body.at ?? Date.now()).toISOString(), page: String(body.page ?? ""), touch: Boolean(body.touch), utm_source: body.utm_source ?? null, utm_campaign: body.utm_campaign ?? null, gclid: body.gclid ?? null, landed: body.landed ?? null, first_touch_at: body.ts ?? null, }; // Your own helper. Append to whatever the office already looks at: // a Sheet, a DB table, a Slack channel. await appendToSheet(process.env.CALL_LOG_SHEET_ID!, row); return NextResponse.json({ ok: true }); } Use whatever store the office already opens every day. For most of our clients that is a Google Sheet, because the person answering the phone will add a column called "Booked?" to a Sheet and will never open a database. The row has a timestamp and a gclid. The phone's call log has a timestamp. Matching them takes a minute a day.
Step 4: close the loop with Google Ads
This is the step that changes how the campaigns bid. Once a week, take the rows where "Booked?" is yes and that have a gclid, and upload them to Google Ads as offline conversions. You can do that by hand with a CSV in the Conversions section of the account, or on a schedule with the Google Ads API. Either way, the campaign that produced a phone call that became a job now gets credit for a conversion with a real value attached, and the bidding system starts optimizing toward callers instead of form fillers. We do this as part of paid search management for service businesses, and it is usually the single change that moves cost per job the most.
If you skip this step, you still have better reporting, but the ad platform is still blind. Automated bidding only improves on the signals it receives, and a plateau is what it looks like when the bid system runs out of first-party data to learn from.
What this does not do
It does not record the call, measure its length, or tell you the caller was a wrong number. Call tracking services do that by swapping the number per visitor and listening on the line, and if call quality is the whole question, pay for one. What this setup gives you for free is source attribution on every call that started from your site, a record the office can annotate, and a path to feed the results back into the account that paid for the click. For most small service businesses that is the part that was missing.
Written by the team at Level Up Digital Marketing Group, a San Diego agency that builds websites, SEO, and paid search for service businesses.
