Docs · Reference

Track AI crawlers and search bots

See which AI assistants, search engines and training crawlers read your site.

Using an AI coding tool?Hand it the prompt below, or point it at this page as markdown: bot-traffic.md

Most crawlers request raw HTML and never run JavaScript, so a tracker script can't see them. Bot tracking reports them from your server instead: one call in the code that handles your requests. Reports go out in the background, so they don't hold up your responses. There’s a markdown version of this page to hand to an agent.

What it shows

The Bot traffic card on your Overview lists which companies' crawlers requested your site and which pages they read, sorted into four groups:

  • AI answers: Fetched while someone was asking an assistant a question.
  • Indexing: Search and answer engines finding and refreshing your pages.
  • Training: Collecting public pages that may be used to train models.
  • Other: SEO tools and other known crawlers.

Hand this to your AI

Building with Claude Code, Cursor, Lovable or another AI tool? Create your key and set it yourself first (steps 1 and 2 below), then paste this in. It never needs to see the key.

Add Statlark bot tracking to this project for my site. It records which AI assistants, search engines and training crawlers request the site. It has to run on the server.

Follow this guide for the exact code: https://statlark.com/docs/bot-traffic.md
If that link doesn't open, try the same address without .md. If neither opens, stop and tell me. Don't write this from memory.

1. Check whether this project already sends bot traffic to Statlark, with @statlark/bots or a call to its API. If it does, stop and tell me. If the package is installed but nothing calls it yet, carry on.
2. Work out how the site is served and use that section of the guide. Static sites on Vercel or Cloudflare have sections too, even with no server code yet. For any other server, use its "Any server" section. If the host can't run code on each request, or you can't tell how it's served, stop and ask me.
3. Add the tracking call before any login or session check.
4. robots.txt, llms.txt and sitemap.xml must reach the tracking call and skip login and session checks. Use the guide's example. Don't just widen a middleware matcher.
5. Read the key from STATLARK_BOT_KEY on the server only. Never give it a NEXT_PUBLIC_ or VITE_ prefix, put it in browser code, commit it, or ask me to paste it here.
6. Don't change anything else. Run the site and request a page and /robots.txt signed out, once normally and once with curl -A GPTBot/1.1. Each must return the same status as before, with no redirect.
7. Tell me what you changed, and remind me to set STATLARK_BOT_KEY with my hosting provider.

Set up by hand

  1. Create a bot key under Settings → Bot tracking. It's shown once, and it can only send bot requests for that site.
  2. Set it as STATLARK_BOT_KEY with your hosting provider, on the server only. Never give it a NEXT_PUBLIC_ or VITE_ prefix, put it in browser code, or paste it into an AI chat.
  3. npm install @statlark/bots, then follow the section for your setup.
npm install @statlark/bots

Next.js

Call trackBot first in proxy.ts, before any login check. Before Next 16 the file is middleware.ts and the function is middleware.

On Vercel it reads the address from x-real-ip. Anywhere else, pass { ip } yourself, or requests show as unverified.

If the app also serves an MCP server or OAuth endpoints, they're skipped: AI clients call them with crawler-like user agents, so every tool call would otherwise show up as a crawler visit. Paths under /mcp and /oauth are never reported. If yours live elsewhere, don't call trackBot for them.

import { NextResponse, type NextFetchEvent, type NextRequest } from "next/server";
import { trackBot } from "@statlark/bots/next";

export function proxy(request: NextRequest, event: NextFetchEvent) {
  trackBot(request, event);

  // These return here, before any login or session check.
  const { pathname } = request.nextUrl;
  if (pathname === "/robots.txt" || pathname === "/sitemap.xml" || pathname === "/llms.txt") {
    return NextResponse.next();
  }

  // Your existing proxy code goes here.
  return NextResponse.next();
}

export const config = {
  matcher: [
    // Keep your existing matcher, then add these three as exact entries.
    "/((?!_next/static|_next/image|favicon.ico).*)",
    "/robots.txt",
    "/sitemap.xml",
    "/llms.txt",
  ],
};

Static site on Vercel

Add Routing Middleware: a middleware.ts at the project root. It needs no vercel.json. Keep the .ts name in a plain JavaScript project too: Vercel compiles it without TypeScript installed, and it ignores middleware.mjs.

A matcher is optional. Without one it runs on every request, assets included, which adds latency and cost to each one. If you add one, it must not exclude robots.txt, llms.txt or your sitemaps.

import { reportBotHit } from "@statlark/bots";

export default function middleware(
  request: Request,
  context: { waitUntil(promise: Promise<unknown>): void },
) {
  context.waitUntil(
    reportBotHit({
      url: request.url,
      userAgent: request.headers.get("user-agent"),
      ip: request.headers.get("x-real-ip"),
    }),
  );
}

Cloudflare

On Workers, call trackBot at the top of fetch, and set the key with wrangler secret put STATLARK_BOT_KEY.

Static files never reach a Worker by default, so existing pages and robots.txt go uncounted unless the Worker runs first. Set run_worker_first to patterns that leave your asset folders out, as below: replace /assets/* with your own folders. Exclude folders, not file types, because a path that matches an exclusion never reaches your Worker, so a route that generates a .png would return a 404.

On the Workers Free plan, every request that reaches the Worker counts towards your account's 100,000 a day. Past that, those URLs fail until midnight UTC, your homepage included. Keeping your asset folders out keeps those requests free. Workers Paid has no daily limit.

import { trackBot } from "@statlark/bots/cloudflare";

export default {
  async fetch(request, env, ctx) {
    trackBot(request, ctx, env);
    return env.ASSETS.fetch(request); // or your existing handler
  },
};
# wrangler.toml
main = "src/index.js"

[assets]
directory = "./public"
binding = "ASSETS"
run_worker_first = ["/*", "!/assets/*"] # use your own asset folders

Cloudflare Pages

On Pages, use a Pages Function. If you have a _routes.json, it must not exclude your pages, robots.txt, llms.txt or your sitemaps.

Requests that reach the Function count towards the same Workers Free limit, so keep your asset folders out in _routes.json.

// functions/_middleware.js
import { trackBot } from "@statlark/bots/cloudflare";

export async function onRequest(context) {
  trackBot(context.request, context, context.env);
  return context.next();
}

Express

Add the middleware before your routes and before any login check. It reports in the background and calls next() straight away.

The IP comes from req.ip, so Express's trust proxy setting decides it, for your whole app. With nothing in front of Node, don't set it: with any value, req.ip comes from the X-Forwarded-For the client sent. Behind proxies you control that add X-Forwarded-For, set it to exactly that many hops, for example app.set("trust proxy", 1) for one. Never true, and never more hops than there are. If it's already set in your app, leave it. If you're not sure, leave it out: real crawlers then show as fake, which is safe, and the troubleshooting below has the fix.

The package is ESM-only. require() works on Node ^20.19 or >=22.12; on older versions use import or await import(). A CommonJS TypeScript project needs "module": "nodenext" on TypeScript 5.8 or later.

import express from "express";
import { statlarkBots } from "@statlark/bots/express";

const app = express();
app.use(statlarkBots());

Hono

Call reportBotHit and hand its promise to waitUntil inside a try/catch. c.executionCtx throws outside Workers-style runtimes, and without the try/catch every request would return a 500.

On Cloudflare Workers process.env often doesn't exist, so without this the package finds no key and sends nothing. Pass the key yourself, and the address too: reportBotHit({ url: c.req.url, userAgent: c.req.header("user-agent"), ip: c.req.header("cf-connecting-ip") }, { key: c.env.STATLARK_BOT_KEY }).

import { Hono } from "hono";
import { reportBotHit } from "@statlark/bots";

const app = new Hono();

app.use("*", async (c, next) => {
  const report = reportBotHit({ url: c.req.url, userAgent: c.req.header("user-agent") });
  try {
    c.executionCtx.waitUntil(report);
  } catch {
    // c.executionCtx throws outside Workers-style runtimes. The report still runs.
  }
  await next();
});

Any server

Anything that can make an HTTP request works. Run these steps in the background from whatever handles your requests.

Send ip only if you have a reliable address: your own socket if nothing sits in front of your server, or a header your own proxy sets if something does. Behind a proxy or load balancer the socket holds the proxy's address. A private one, such as 10.x or ::1, reads as unverified; a public one makes real crawlers show as fake, and their pages aren't recorded. Never use the leftmost X-Forwarded-For entry, because the client controls it. Without ip, requests show as unverified.

# 1. Only for user agents that match this pattern, ignoring case. Skip everything else,
#    or you'd send every human visit to us.
#
#    bot\b|bot/|crawl|spider|slurp|-user\b|-index\b|-training\b|-agent\b|amzn-|google-|googleother|meta-|bytespider|cohere|facebookexternalhit
#
# 2. Remove the query string and fragment from the URL.
# 3. Send it in the background, so nobody waits for it. Keep at most 20 running at once,
#    and drop the rest instead of queueing them.
curl --max-time 2 -X POST https://collect.statlark.com/bots \
  -H "Authorization: Bearer $STATLARK_BOT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/pricing","user_agent":"GPTBot/1.1","ip":"132.196.86.10"}'
# 4. Stop for a while if the answer is 402, or if it contains paused_until. On 429, wait the
#    seconds in Retry-After. After unknown_crawler, skip that user agent for an hour.

robots.txt, llms.txt and sitemaps

robots.txt, llms.txt and sitemap.xml are often the first things a crawler reads, so they're worth tracking. Many sites keep them out of their middleware, though, so the tracking call never sees them.

Only widening a matcher can redirect them to a login page. If your middleware checks a session, a signed-out crawler asking for robots.txt gets sent to your login screen instead. Add them as exact matcher entries, then return before any session or login check, as the Next.js example does.

After you change this, request /robots.txt signed out, once normally and once with curl -A GPTBot/1.1. Each must return the same status as before, with no redirect.

Adding middleware to a site that has none runs it on every request it matches, which puts a step before each response. On Vercel each one is a billable middleware invocation, so use a matcher that skips your static assets. Bot tracking itself only makes a network call for requests that look like crawlers.

Verified, unverified and fake

Anyone can claim to be GPTBot in a user agent, so where an operator publishes its addresses, we check them.

  • Verified: The address is on the operator's published list.
  • Can't be checked: The operator publishes no list, the list was unavailable, or no usable address was sent: none at all, or a private or local one such as 10.x or ::1, which only shows a proxy hid the real address. These show with an Unverified tag.
  • Fake: The operator publishes a list and the address isn't on it. That includes an IPv6 address when the list only has IPv4 ones, and the other way round. These are hidden by default, with a count and a Show them link. Past 10,000 an hour for one crawler on one site, fake requests stop being counted, so the count is then a lower bound.

If an operator's list is down, its crawlers show as unverified, never as fake. Lists refresh daily, so a crawler that has just changed address can read as fake for up to a day.

The allowance

Each workspace includes 100,000 crawler requests a month, on every plan, annual plans included. They're separate from your events and never count towards your event allowance. Fake requests don't count at all.

Requests we can't check stop being recorded at 80,000, so forged traffic alone can't use up the allowance and lock out real crawlers. Verified requests keep going to 100,000. The meter doesn't mark the 80,000 point.

At 100,000, bot tracking pauses until the next cycle. Nothing else changes: your analytics, goals and revenue keep working, and you're not charged. What was already collected stays visible.

Bot traffic is kept for 13 months.

Privacy

For requests that look like crawlers, your server sends us the user agent and the URL. The @statlark/bots package adds the IP address for crawlers with a published list, and for other crawlers a hash of the address keyed with your bot key. We use that hash only to limit repeated requests and don't write it to our database. It's a pseudonym, not anonymous: anyone holding your key could work out an IPv4 address from it. If you follow Any server or call the endpoint yourself, we receive whatever IP address you include, for any crawler.

Query strings and fragments are removed before anything leaves your server, and again when it reaches ours. A path segment that looks like an email address becomes [email], one holding a payment card number becomes [card], and one that looks like a random token of 20 characters or more becomes [token], because a private link pasted into an assistant can put any of them in a crawler's request. A segment of three or more plain words is kept, so a readable page name survives.

We use the IP address to check the crawler is genuine and to limit forged requests, and never write it to our database. We keep only the crawler's name, the page path and a count. A request can occasionally come from a person's device if it looks like a crawler, so mention this in your privacy policy if you list your data flows there.

Troubleshooting

Nothing is arriving
Check STATLARK_BOT_KEY is set on the server and that you redeployed. Without it the package warns once and does nothing. Then run curl -A GPTBot/1.1 against one of your pages. Static hosts need the extra setup above, or the request never reaches your code.
Everything looks fake
Scanners often fake crawler names, and that's normal. If real crawlers show as fake, there's probably a proxy in front of your server and you're sending its address. Pass the real one with the ip option, or on Express set trust proxy to your exact number of proxies.
Everything is unverified
No usable address is being sent. Outside Vercel, Cloudflare and Express none is sent by default, so pass ip if you have a reliable one. If you do pass one and it's private or local (10.x, 172.16-31.x, 192.168.x, 127.x, ::1), a proxy in front of your server is hiding the real address: read it from the header your proxy sets instead. Crawlers with no published list always show as unverified.
401 or 403
The key is wrong, revoked, or doesn't have the Bot tracking permission, or it's an all-sites key. Create a new one under Settings → Bot tracking.
402
The workspace has no active plan, so nothing is recorded until it has one.
A page is missing
A URL that ends in a file extension such as .js, .css, .map, .png or .mp4 counts as a file, not a page, so it isn't reported. That includes a real article like /blog/next.js, because the URL alone can't tell it from a script. Paths under /_next, /_vercel, /.well-known, /mcp and /oauth aren't reported either. Paths under /api are skipped by the package unless you pass reportApi: true, for a site that serves real pages there.

Last reviewed