Docsllms.txtSign inGo to your sites

Updated

View as Markdown

Bot tracking

Crawlers and AI agents do not run JavaScript, so the browser script never sees them. To count them, your server sends one small request to twelvebit for each request from a known bot.

Ask your coding agent

Paste this into Claude Code, Codex or Cursor in your project folder. It holds no key: the agent gets one with the CLI, and you approve the sign-in in the browser. To do it yourself, follow the steps after it.

Prompt for your coding agent · holds no key
Report AI crawler and search bot visits on <production domain> to twelvebit. Crawlers do not run JavaScript, so the server must report them. 1. Key: the server code needs a twelvebit site key in TWELVEBIT_API_KEY with the write:events scope. If .env has no TWELVEBIT_API_KEY, run npx -y twelvebit@latest init <production domain> in the project root. It opens the browser so that I can approve the sign-in, then it saves the key in .env (the default key includes write:events). If the API answers 403 insufficient_scope, stop and ask me to create a key with write:events in Settings → API & MCP and put it in .env myself. Never print the key, never put it in browser code or git, and never ask me to paste it into this chat. 2. Detect the framework and add code that runs on every page request: - Next.js 16: proxy.ts next to the app folder (in src/ if the project uses it). Next.js 15 and earlier: middleware.ts. If the file exists, add to its function. - Express, Fastify, Hono or another Node.js server: a middleware. - Any other backend: the same logic early in the request pipeline. 3. When the User-Agent matches this pattern (case-insensitive), send POST https://twelvebit.app/api/v1/bots with the header "Authorization: Bearer <TWELVEBIT_API_KEY>" and the JSON body {"user_agent": <the User-Agent>, "path": <the request path>}: chatgpt-user|claude-user|perplexity-user|duckassistbot|mistralai-user|meta-externalfetcher|oai-searchbot|claude-searchbot|perplexitybot|youbot|gptbot|claudebot|anthropic-ai|ccbot|google-extended|applebot-extended|bytespider|meta-externalagent|facebookbot|amazonbot|cohere-ai|cohere-training-data-crawler|diffbot|ai2bot|omgilibot|imagesiftbot|timpibot|pangubot|googlebot|bingbot|duckduckbot|applebot|yandexbot|baiduspider|slurp|bravebot|kagibot|seznambot|petalbot|qwantbot 4. Send it in the background (event.waitUntil in Next.js, no await elsewhere) and ignore errors. Never slow down or fail a page. Skip static files. Do nothing when TWELVEBIT_API_KEY is not set. 5. Add TWELVEBIT_API_KEY to .env.example with no value, and tell me to set it in the production environment too. 6. Check it: start the app and run curl -A "GPTBot/1.2" http://localhost:<port>/. Then run set -a; . ./.env; set +a and curl -sS "https://twelvebit.app/api/v1/bots?period=today" -H "Authorization: Bearer $TWELVEBIT_API_KEY". GPTBot must be in the result. It also shows in Settings → Bot tracking. Reference code: https://twelvebit.app/docs/bots.md. At the end, show me the diff. Fill in <production domain> and <site id> from this project: the site id is data-website-id in the twelvebit script tag, or TWELVEBIT_SITE_ID in .env. Ask me if you cannot find them.

The three kinds

KindWhat it meansBots
ai_answer (AI answers)An assistant fetches the page because a person asked about it now. These visits are the closest thing to a reader from ChatGPT, Claude or Perplexity.ChatGPT-User, Claude-User, Perplexity-User, DuckAssistBot, MistralAI-User, Meta-ExternalFetcher
indexing (Search indexing)A search engine crawls the page for its index: classic search (Googlebot, Bingbot) and AI search (OAI-SearchBot, Claude-SearchBot, PerplexityBot).OAI-SearchBot, Claude-SearchBot, PerplexityBot, YouBot, Googlebot, Bingbot, DuckDuckBot, Applebot, YandexBot, Baiduspider, Yahoo Slurp, Bravebot, Kagibot, SeznamBot, PetalBot, Qwantbot
training (AI training)A crawler collects the page as training data for a model.GPTBot, ClaudeBot, anthropic-ai, CCBot, Google-Extended, Applebot-Extended, Bytespider, meta-externalagent, FacebookBot, Amazonbot, cohere-ai, cohere-training-data-crawler, Diffbot, AI2Bot, Omgilibot, ImagesiftBot, Timpibot, PanguBot

Unknown user agents are ignored, so you can send every request and twelvebit keeps only the bots on this list. The list is maintained on the server, so it stays current without changes to your code.

The endpoint

Shell
curl -sS -X POST https://twelvebit.app/api/v1/bots -H "Authorization: Bearer $TWELVEBIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"user_agent": "Mozilla/5.0 (compatible; GPTBot/1.2; +https://openai.com/gptbot)", "path": "/pricing"}'
FieldTypeNotes
user_agentstringRequired. The request's User-Agent header.
pathstringThe requested path. A full URL is reduced to its path.

The response is 202 with { "tracked": true, "bot": "GPTBot", "kind": "training" }, or { "tracked": false } for a user agent that is not on the list. The limit for this endpoint is 1,200 requests per minute per key. Read the counts with GET /api/v1/bots?period=30d.

Use a site key (tbk_…) from the environment. Never send the key to the browser.

Next.js (proxy.ts)

Next.js 16 calls middleware "proxy". Put this file next to your app folder (in src/ if you use it). event.waitUntil sends the request after the response, so it adds no delay. If you already have a proxy.ts (or middleware.ts in Next.js 15 and earlier), add the if block to your function.

proxy.ts
// proxy.ts
import { NextResponse, type NextFetchEvent, type NextRequest } from "next/server";

// Known crawlers and AI agents. Other requests are not sent.
const BOTS = /chatgpt-user|claude-user|perplexity-user|duckassistbot|mistralai-user|meta-externalfetcher|oai-searchbot|claude-searchbot|perplexitybot|youbot|gptbot|claudebot|anthropic-ai|ccbot|google-extended|applebot-extended|bytespider|meta-externalagent|facebookbot|amazonbot|cohere-ai|cohere-training-data-crawler|diffbot|ai2bot|omgilibot|imagesiftbot|timpibot|pangubot|googlebot|bingbot|duckduckbot|applebot|yandexbot|baiduspider|slurp|bravebot|kagibot|seznambot|petalbot|qwantbot/i;

export function proxy(request: NextRequest, event: NextFetchEvent) {
  const ua = request.headers.get("user-agent") ?? "";
  const key = process.env.TWELVEBIT_API_KEY;
  if (key && BOTS.test(ua)) {
    event.waitUntil(
      fetch("https://twelvebit.app/api/v1/bots", {
        method: "POST",
        headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
        body: JSON.stringify({ user_agent: ua, path: request.nextUrl.pathname }),
      }).catch(() => {}),
    );
  }
  return NextResponse.next();
}

export const config = {
  // Skip build files and images. robots.txt, sitemap.xml and llms.txt still match.
  matcher: ["/((?!_next/static|_next/image|favicon.ico|.*\\.(?:png|jpe?g|gif|webp|avif|svg|ico|css|js|woff2?)$).*)"],
};

Express

JavaScript
// Node.js 18+ has fetch built in.
const BOTS = /chatgpt-user|claude-user|perplexity-user|duckassistbot|mistralai-user|meta-externalfetcher|oai-searchbot|claude-searchbot|perplexitybot|youbot|gptbot|claudebot|anthropic-ai|ccbot|google-extended|applebot-extended|bytespider|meta-externalagent|facebookbot|amazonbot|cohere-ai|cohere-training-data-crawler|diffbot|ai2bot|omgilibot|imagesiftbot|timpibot|pangubot|googlebot|bingbot|duckduckbot|applebot|yandexbot|baiduspider|slurp|bravebot|kagibot|seznambot|petalbot|qwantbot/i;

app.use((req, res, next) => {
  const ua = req.get("user-agent") || "";
  if (process.env.TWELVEBIT_API_KEY && BOTS.test(ua)) {
    // Fire and forget: do not await, do not block the response.
    fetch("https://twelvebit.app/api/v1/bots", {
      method: "POST",
      headers: { Authorization: `Bearer ${process.env.TWELVEBIT_API_KEY}`, "Content-Type": "application/json" },
      body: JSON.stringify({ user_agent: ua, path: req.path }),
    }).catch(() => {});
  }
  next();
});

Other servers

Any backend works: for a request whose User-Agent matches the pattern above (case-insensitive), send POST /api/v1/bots with user_agent and path, in the background, with a short timeout.

Cloud networks

Some bots run a real browser on a server, so the browser script sees them as visitors. Almost all of them run in a data centre. twelvebit checks the visitor's IP address against the published IP ranges of large cloud and hosting providers: AWS, Google Cloud, Microsoft Azure, Oracle Cloud, DigitalOcean, Akamai (Linode), Hetzner, OVHcloud, GitHub Actions.

By default, a visit from these ranges is a likely bot:

  • People, visitor counts, reports, funnels, conversion rates, alerts and Live leave it out.
  • It makes no billable events, so it does not count toward your plan's usage.
  • The AI and crawler card on the overview shows it under Cloud networks, by provider. GET /api/v1/bots has the same numbers in cloud_networks, and GET /api/v1/usage has events.cloud_visits.
  • twelvebit stores the provider's name with the visit. The IP address is not stored.

Some real people browse from a data centre: cloud desktops (Amazon WorkSpaces, Windows 365) and some VPNs. If your visitors do, turn on Count cloud-network visits in Settings → Bot tracking, or set count_cloud_visits: true with PATCH /api/v1/sites/{siteId} (scope write:config) or the MCP tool update_site_settings. The setting applies to new visits. The card still shows how many visits came from cloud networks.

Shell
curl -sS -X PATCH "https://twelvebit.app/api/v1/sites/example.com" -H "Authorization: Bearer $TWELVEBIT_API_KEY" \
  -H "Content-Type: application/json" -d '{"count_cloud_visits": true}'

Limits:

  • The check needs the visitor's own address. Behind a proxy that you host (data-api), twelvebit sees your proxy's address, so the script marks those requests and the check is off. The managed proxy is not affected. App SDK events are not checked.
  • Privacy services that real people use (iCloud Private Relay, Cloudflare WARP) are not in the list, and neither are CDN networks.
  • The ranges are a snapshot from the providers' lists (last refresh: 2026-10-18), updated with twelvebit releases. The check makes no request to another service.