Skip to main content
NewNMC’s advertising guidelines for doctors are in force from 6 Oct 2026. See what to change, and get a free compliance auditNew NMC advertising rules for doctors: what to change
Analytics

Dynamic Number Insertion on Hospital Sites: Session Attribution, Caching and DPDP Notes

How dynamic number insertion works on a hospital site, why page caching and CDNs break it, how calls are matched to sessions, and what call recording means for notice and consent under DPDP.

Dynamic Number Insertion on Hospital Sites: Session Attribution, Caching and DPDP Notes

Dynamic number insertion, usually shortened to DNI, replaces the phone number on a web page with a tracking number that depends on who is looking at it. Done well, it lets a hospital say which campaign, keyword or page produced which call. Done badly, it shows the wrong number, shows a cached number to the wrong visitor, or records calls without telling the caller.

This article is for marketing technologists and operations leads at hospitals and diagnostic chains who are deploying or auditing DNI. It explains how the swap works, how calls are matched to sessions, what happens when a CDN or page cache is in the way, and what call recording implies for consent. It is not legal advice; your counsel decides what notice and consent your recording practice needs.

How DNI works

There are two parts.

The number pool. Your call tracking provider gives you a pool of tracking numbers that all forward to your real lines. The size of the pool determines how many concurrent visitors can each hold their own number.

The swap script. A JavaScript snippet on the page finds your phone number (by a CSS class or by matching the digits) and replaces it with a number from the pool. The provider records which number was assigned to which session, along with the traffic source and landing page. When someone calls that number, the provider matches the call to the session and passes the details on.

Google offers a version of this for Google Ads. Its website call conversion documentation describes a snippet that swaps your number for a Google forwarding number, and says the default tag tracks only one number per page. It also says that if your site uses dynamic number insertion or third-party call tracking, Google's automated system may be unable to verify your phone number, and the workaround is to link Search Console to Google Ads or place the Google tag in the raw HTML. In practice, running two swap systems on one page is a recipe for confusion; pick one owner of the number.

Session attribution: what the provider matches

A call can be tied to a session in two ways.

Session-level. The provider assigns each visitor session its own number from the pool for the duration of the visit plus a window after it. A call to that number during the window is attributed to that session. This gives you the landing page, source, medium, campaign, keyword and click ID for the call.

Source-level. Instead of one number per visitor, the provider assigns one number per traffic source (for example, one for Google Ads, one for organic, one for direct). It is cheaper, needs fewer numbers and gives channel-level attribution only.

For a hospital, session-level tracking is worth the cost on the pages where calls matter, such as appointment pages and department landing pages. Source-level is acceptable for the rest of the site.

Check four details with your provider:

  • How long a number is held after the visit. A patient may browse on the phone, close the browser and call two minutes later. If the number returns to the pool too quickly, the call is attributed to the wrong session or to nobody.
  • What happens when the pool runs out. The page should fall back to a default number. If the pool is exhausted during a campaign burst, attribution quietly degrades.
  • What identifiers are passed. To tie calls to GA4 or Google Ads, the provider should capture the GA4 client or session identifier and the click ID. Check this with a test call, not with documentation.
  • Where the data goes. Call metadata, and any recording, is stored by the provider. Know where, for how long and under what contract.

Caching: where DNI usually breaks

Hospital sites are often served through a CDN or a full-page cache. If the swap happens in the browser after the page loads, caching is mostly harmless: every visitor receives the same cached HTML with the default number, and the script then replaces it with that visitor's tracking number. The problems come from a few specific patterns.

  • Server-side swap with a cached page. If your server writes the tracking number into the HTML, and the CDN caches that HTML, the next visitor receives the first visitor's number. Calls from many people are attributed to one session. Avoid server-side swapping on cacheable pages, or vary the cache correctly.
  • The script loads late. If it loads after a long delay, the visitor sees the default number briefly, then the swap. A tap in that gap calls the wrong number. Load the script early, and avoid layout shift when the number changes.
  • Number inside images, PDFs or JSON-LD. The script swaps visible text. It does not change a phone number inside an image, a downloadable brochure, or structured data. Those keep the default number, which is useful for consistency, but they produce unattributed calls.
  • Click-to-call links. The visible text may change while the tel: link still points to the default number. Check both.
  • Single-page apps and dynamic content. Numbers added after the script has run, such as a modal or a client-rendered footer, need the script to be re-run on DOM changes.
  • Cached AMP or mirrored pages. If a copy of your site is served from another origin, the script may not run there.

Test it: open the site in a private window, from a campaign URL, and check the number in the text, in the link target and in the page source. Then request the page twice through the CDN and check that the number differs between sessions or that the swap is client-side.

Want this applied to your practice? Get a free analytics audit.

Book my free audit

Numbers that should never be swapped

  • Emergency and ambulance lines. A patient in crisis must reach the real number reliably, even if the script fails, the pool is exhausted or the provider has an outage. Keep these as static numbers and make sure they are never part of a tracked pool.
  • Numbers on your Google Business Profile and in structured data. Keep your main listed number as the consistent public number across profile, schema markup and directories. DNI is for visitors on specific pages, not for rewriting how your organisation is listed. Our Google Business Profile guide covers consistency.
  • Contact details inside regulated clinical documents. Leave the printed number in reports and consent forms unchanged.

Call recording and DPDP

Attribution only needs call metadata: the number called, the time, the duration, the source and the session. Recording the audio is a separate decision, and for a hospital it carries more weight. Callers describe symptoms, tests, results and their families. A recording is personal data, often about health.

India's Digital Personal Data Protection Act, 2023 is built on notice, purpose limitation and security safeguards. The Rules were notified in November 2025 with an eighteen-month period for phased compliance. Our article on the DPDP Act for healthcare marketing explains it in a marketing context. For recording, work through these questions with counsel:

  • Do you need to record at all? If the purpose is attribution, you do not. If the purpose is training or quality, say so, and keep it separate.
  • Notice. Tell the caller before recording begins, in the languages callers use, and say what the recording is used for. A short announcement at the start of the call is the usual way.
  • Consent and the option to decline. Decide how a caller who objects is handled, for example by being routed to a line that is not recorded.
  • Purpose limitation. Recordings collected for quality should not be reused for ad targeting or model training without a basis.
  • Retention. Set a period, delete on schedule, and be able to show it.
  • Access control. Limit who can listen, and log access.
  • Processor contract. The call tracking provider handles the data for you. Agree what it may do, where it stores data and how it deletes it.
  • Transcripts and AI summaries. If an AI tool transcribes calls, the transcript is also personal data. Our call tracking and analytics service page describes what that can look like.
  • Telecom and clinical confidentiality. Telecom rules and clinical confidentiality obligations may apply to recorded calls. Ask counsel.

Do not pass call audio, transcripts or the caller's number to analytics or advertising platforms. Send only an event with a call ID, a duration band and a source. If you need to import a conversion into Google Ads, use the click ID and conversion time, not the caller's identity.

Pitfalls summary

  • Pool too small for campaign bursts.
  • Number held for too short a time after the visit.
  • Cached server-swapped pages.
  • Late script loading.
  • Two swap systems on one page.
  • Click-to-call link not updated.
  • Emergency number included in the pool.
  • Recording switched on by default with no notice.

Deployment checklist

  1. Decide session-level or source-level tracking for each page type.
  2. Size the pool from peak concurrent sessions, with headroom.
  3. Choose a client-side swap and confirm the CDN cache behaviour.
  4. Exclude emergency numbers and keep the public listed number consistent.
  5. Test text, link target, page source and a real call from a campaign URL.
  6. Confirm the provider passes the GA4 identifiers and click ID.
  7. Decide whether to record. If yes, add a call announcement, a retention period, an access list and a processor contract.
  8. Review attribution every month and compare call totals with your front-desk log.

For setup help, see our call tracking and attribution service and our analytics and tracking service. For background on the compliance frame, read the compliance overview.

Filed underdynamic number insertionDNI call tracking hospitalcall tracking number swapcall tracking CDN cachingcall recording consent Indiacall attribution diagnostics

About the author

Co-Founder & CTO · Gurugram, India

Arush builds the systems the rest of the company runs on — the patient-acquisition pipelines, the AI chatbots, the analytics that tie a single click to a booked appointment. If a campaign reports a number, it's because something his team built is tracking it.

Free guide · 15 pages

The Patient Acquisition Blueprint

A 90-day plan from first search to booked appointment.

The Pioneers Brief — one essay, three benchmarks, one teardown, every Thursday. Subscribe free →

Free analytics audit

Your next chapter starts with a conversation.

Three quick questions. We come prepared with a plan for your specialty and city.

  • A 30-minute call with a healthcare specialist
  • Your top three growth opportunities, in writing
  • Honest advice — even if that means not hiring us
  • No obligation and no hard sell
You’ll speak with a senior strategist
Consultations are hosted by Arush Thapar’s team.
Step 1 of 3Takes 30 seconds

What do you want to improve first?

Details stay privateNo obligationReply within 1 working day

Client portfolio · Healthcare websites

Work relevant to dynamic number insertion on hospital sites session attribution.

Explore client work →