Cloudflare Worker
A small Worker in front of your site sees every request, including ones served from Cloudflare's cache. It reports AI crawler visits to Rankealo and passes everything else straight to your site.
Prerequisites#
- Your domain on Cloudflare with the proxy on (orange cloud) for the hostname you want to track. Any Cloudflare plan works, including Free.
- Your site key and ingest URL from Rankealo → Traffic → Agent Analytics in the app (the key identifies your site, and you can regenerate it there). You set them as environment variables on your host (see Environment variables); the code only reads them, so it never contains a key. See the HTTP API reference for the full payload.
Best option for hosted builders
Webflow, Framer, Squarespace, Shopify, and WordPress.com do not let you run server code. If the domain is proxied through Cloudflare, this Worker is how you track crawlers on them.Steps#
- 1
Create a Worker
In the Cloudflare dashboard, open Workers & Pages → Create and start from the "Hello World" template. - 2
Paste the code
Click Edit code, replace everything with the snippet below, and Deploy. The code reads its settings from the Worker's environment, so it contains no keys. - 3
Add a route
In the Worker's Settings → Domains & Routes, add a route such aswww.your-site.com/*on your zone. Add one for the bare domain too if it serves pages. - 4
Add the secrets
In Settings → Variables and Secrets, addRANKEALO_BOT_TOKENandRANKEALO_INGEST_URLas type Secret (or runnpx wrangler secret put RANKEALO_BOT_TOKENfor each one).
// Set RANKEALO_BOT_TOKEN and RANKEALO_INGEST_URL under
// Worker > Settings > Variables and Secrets (or `npx wrangler secret put <NAME>`).
export default {
async fetch(request, env, ctx) {
const token = env.RANKEALO_BOT_TOKEN;
const ingestUrl = env.RANKEALO_INGEST_URL;
const ua = request.headers.get("user-agent") || "";
if (token && ingestUrl
&& /bot|crawler|spider|chatgpt|gptbot|claude|perplexity|bing|google|applebot|bytespider|ccbot/i.test(ua)
&& (request.method === "GET" || request.method === "HEAD")) {
const url = new URL(request.url);
ctx.waitUntil(fetch(ingestUrl, {
method: "POST",
headers: { "content-type": "application/json", authorization: "Bearer " + token },
body: JSON.stringify({
domain: url.hostname,
href: url.protocol + "//" + url.host + url.pathname,
ai: {
userAgent: ua,
ip: request.headers.get("CF-Connecting-IP"),
source: "server_middleware",
},
}),
}).catch(() => {}));
}
return fetch(request);
},
};
Environment variables#
The code reads two environment variables. If any is missing it does nothing, so your site keeps working while you set them up.
RANKEALO_BOT_TOKEN: Per-site ingest key for this website. Keep it secret.RANKEALO_INGEST_URL: The Rankealo ingest endpoint the code posts crawler hits to.
Where to set them: Cloudflare: Worker → Settings → Variables and Secrets (type Secret), or run `npx wrangler secret put <NAME>` for each one.
The values are in Rankealo → Traffic → Agent Analytics, each with a copy button. Paste them into your host's settings yourself; never commit them to your repository.
What is sent#
- URLScheme, host, and path. The query string is never sent.
- User agentUsed to identify the crawler.
- IPFrom CF-Connecting-IP; hashed on arrival, never stored raw.
The report is sent with ctx.waitUntil, so the response is never held back, and the request goes to your site unchanged.
Limitations#
- The snippet reports any request whose user agent looks like a crawler; Rankealo keeps known AI and search crawlers and drops the rest.
- Workers on the Free plan have a daily request limit. The Worker runs on every request on its route, not only crawler ones, so check your plan on high-traffic sites.
- No status code is sent, because the Worker reports before your site responds.
Confirm data is flowing#
- 1In Rankealo, open Traffic → Agent Analytics.
- 2Press Check now in step 3. Once a crawler has visited, it shows Receiving data with the time of the last hit.
- 3Open the Bot traffic tab to see hits by crawler and by page.
The first hit depends on when a crawler next visits, which can take up to 24 hours. To test right away, request a page with a crawler user agent, for example curl -A "GPTBot/1.2" https://www.your-site.com/, then press Check now. A test like this is recorded as a claimed identity, like any hit without CDN verification.
Troubleshooting#
The Worker never runs+
Check now says No data received+
My site broke after adding the Worker+
Still stuck? Contact support
