How to track visitors on Cloudflare.
For Cloudflare Pages, add the tracker to your shared HTML layout. For an origin website you control but cannot edit, a Worker can inject it into HTML responses. Both methods record browser visits and page URLs; a server request log alone also includes bots and asset requests.
What you need
- • For Pages: access to the site source and permission to publish a new deployment.
- • For origin-proxy injection: a domain you control, proxied through Cloudflare — orange cloud, not DNS-only.
- • For origin-proxy injection: a Cloudflare account able to deploy Workers and bind routes.
- • For the Worker deploy command below: Node and npx available locally.
- • A VisitorPing site key, in the form vp_ABC23456 — the prefix vp_ and eight characters. The alphabet leaves out I, O, 0 and 1, so there is nothing to misread when copying it.
Install it
- 1
Choose Pages installation or edge injection
If your site is on Cloudflare Pages and you can edit its HTML or framework layout, paste this tag before the closing head tag and replace the example key with your own. Publish the site, then skip to the verification step. Do not also inject it with a Worker.
The remaining steps are for a separate origin behind a proxied custom domain. A Worker that calls fetch(request) is an origin proxy, not a drop-in Pages Functions file. Keep existing framework-generated Workers intact.
<script defer crossorigin="anonymous" src="https://cdn.visitorping.com/site/vp_ABC23456.js"></script> - 2
Prepare the edge injection Worker
Use the Cloudflare integration supplied with VisitorPing. Its plugins/cloudflare directory contains src/index.ts and wrangler.jsonc; do not run the deploy command from an empty directory.
The Worker fetches the origin response, checks for status 200 and text/html, then uses HTMLRewriter to append the tracker to the head. Images, JSON and error responses pass through. Your account must control the domain and its Worker routes.
- 3
Set your site key
Put your key in wrangler.jsonc as VISITORPING_SITE_KEY, or add it as a Worker secret if you would rather not commit it.
- 4
Deploy the Worker
From the worker directory.
npx wrangler deploy - 5
Route your traffic through it
In the Cloudflare dashboard add a Worker Route such as *yourdomain.com/* mapped to the Worker.
- 6
Check the live site
Load the published site in a private window and view the source. Confirm exactly one tracker tag contains your site key. In browser developer tools, check that the script loads and a collection request succeeds.
Open a second page, then check VisitorPing Live Radar for that page URL and the test visit. For a client-rendered app, also test a navigation that does not reload the page. Installation is complete only after a visit reaches your own dashboard.
Pages Functions, Workers and visitor URL tracking
Pages Functions use an onRequest handler; an existing middleware obtains the downstream response with context.next(). An advanced-mode Pages project uses _worker.js and ignores the functions directory. Use the shared-layout script when possible to avoid changing that routing.
Worker request URLs describe incoming HTTP traffic, including crawlers and static assets. The browser tracker adds page navigation and referral context to a visitor session. Neither approach reveals an anonymous visitor's name or email.
A route such as *yourdomain.com/* is for a domain you control in your Cloudflare zone. It does not give you control over someone else's website or an arbitrary pages.dev hostname.
Verify visitor URLs with a two-page test
Open your published homepage, then follow a link to a second page. Live Radar should show the same test visitor moving between the expected page paths. Repeat using your app's client-side navigation if it has one.
If the script loads but no visit appears, inspect the collection request and your site's Content Security Policy. If every route appears twice, check for both a layout tag and Worker injection. The script detector can find a tag in fetched HTML; it cannot prove that the browser executed it or that a visitor reached your dashboard.
When this is the right answer
Use it when the platform gives you no way to add a script — a closed website builder, a site whose origin code you cannot edit but whose Cloudflare account you administer, or one where custom code sits behind a plan upgrade you would rather not buy.
It is also the tidiest option for an agency running many client sites on the same Cloudflare account.
Check the SSL mode first
If your host issues its own certificate for the domain, putting Cloudflare's proxy in front of it needs the right SSL mode or the site will error for every visitor. Confirm that on a staging domain before pointing production through it.
What you will actually see
Per visit: the city and region the network resolves to, where the visitor came from, the page they landed on, their device and browser, and whether they have been before.
You do not get a name, an email address, or an identity. Nobody can give you that from a page view, whatever the marketing says. Geolocation resolves a network rather than a doorstep, so a visitor on a VPN or a mobile network can appear in the wrong city entirely. Treat location as a hint.
You are collecting visitor data, so say so in your privacy notice and check which consent rules apply where your customers are — a question for your own legal advice, not for a setup guide.
If it is not working
- Page views are duplicated
- Check whether the tag is installed in the layout and also injected at the edge. Keep one installation method, publish, and repeat the two-page test.
- The tag exists but no browser visit arrives
- Check the site key and collection request in developer tools. Content Security Policy, a content blocker or a denied consent choice can stop tracking. Respect visitor choices; do not weaken the entire site's security policy to work around a blocked script.
- The site returns an SSL error after enabling the proxy
- The SSL mode does not match how your origin serves HTTPS. Full (Strict) is usually correct when the origin has a valid certificate.
- The Worker is deployed but the tag is missing
- No route is bound to it, or the route pattern does not match the paths visitors use. A Worker with no route runs for nothing.
Find what is costing you search clicks, then watch the fix work.
VisitorPing reads your own Search Console data for the pages losing clicks, then rings your phone the moment someone lands on your website.