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.



