> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Report AI crawler hits from your server or edge

> Count GPTBot, ClaudeBot, PerplexityBot and other AI crawlers in CrispStats from Next.js proxy.ts, a Cloudflare Worker or any server with a POST to /bot.

AI crawlers such as GPTBot, ClaudeBot and PerplexityBot request your pages but never run JavaScript, so the CrispStats script cannot see them. To count them, post each crawler request from your server, middleware or edge to the collector's `/bot` endpoint. The hits then appear in the **AI crawlers** section of the [AI traffic](https://docs.crispstats.com/ai/ai-traffic.md) screen. There is no package to install: the code below uses `fetch` and nothing else.

## What gets sent

One small request to `https://in.crispstats.com/bot` with four fields: your public key, the User-Agent, the URL's path and the response status. No IP address, no query string, no cookies and no other headers. The code checks the User-Agent first, so requests from anything that is not a known AI crawler make no network call.

The call never throws into your request: errors are swallowed. Do not await it in the request path; hand the promise to `waitUntil` so the response is not delayed.

## Set it up

**1. Report crawler requests**

Use your site's public key, the `cs_pk_` key from **Settings**, **Tracking code**. The same code, with your key filled in, appears in the **AI crawlers** section of the AI traffic screen until the first hit arrives.

> [tab] Next.js
>
> Add the call to `proxy.ts` at the root of your project, next to `app` (or inside `src` if you use one). Before Next.js 16 the file is `middleware.ts` and the exported function is named `middleware`.
>
> ```ts proxy.ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
> import { NextResponse, type NextFetchEvent, type NextRequest } from "next/server";
>
> // AI crawlers do not run JavaScript, so this reports their visits from the server.
> const AI_CRAWLERS = /GPTBot|OAI-SearchBot|ChatGPT-User|ClaudeBot|Claude-SearchBot|Claude-User|PerplexityBot|Perplexity-User|Google-Extended|GoogleOther|Applebot-Extended|Amazonbot|Bytespider|CCBot|meta-externalagent|meta-externalfetcher|MistralAI-User|DuckAssistBot|cohere-ai|YouBot/i;
>
> export function proxy(request: NextRequest, event: NextFetchEvent) {
>   const ua = request.headers.get("user-agent") ?? "";
>   if (AI_CRAWLERS.test(ua)) {
>     // Sends only the User-Agent and the path: no address, no query string, no cookies.
>     event.waitUntil(
>       fetch("https://in.crispstats.com/bot", {
>         method: "POST",
>         headers: { "content-type": "application/json" },
>         body: JSON.stringify({ k: "cs_pk_xxxxxxxx", ua, path: request.nextUrl.pathname }),
>       }).then(() => undefined, () => undefined),
>     );
>   }
>   return NextResponse.next();
> }
>
> export const config = {
>   matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
> };
> ```
>
> If you already have a `proxy.ts`, add the `if` block to your existing function and keep your own return value. If you [proxy the script](https://docs.crispstats.com/tracking/proxy.md) through a path on your site, leave that path out of the matcher too. The proxy runs before the page is rendered, so it does not know the final status: every hit is reported as `200`.

> [tab] Cloudflare Worker
>
> Report the hit after you have the response, so the real status is sent. This example serves static assets through an `ASSETS` binding; replace `env.ASSETS.fetch(request)` with however your Worker produces its response. The types `Fetcher`, `ExecutionContext` and `ExportedHandler` come from your Worker's generated types (`wrangler types`).
>
> ```ts worker.ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
> // AI crawlers do not run JavaScript, so this reports their visits from the edge.
> const AI_CRAWLERS = /GPTBot|OAI-SearchBot|ChatGPT-User|ClaudeBot|Claude-SearchBot|Claude-User|PerplexityBot|Perplexity-User|Google-Extended|GoogleOther|Applebot-Extended|Amazonbot|Bytespider|CCBot|meta-externalagent|meta-externalfetcher|MistralAI-User|DuckAssistBot|cohere-ai|YouBot/i;
>
> interface Env {
>   ASSETS: Fetcher;
> }
>
> export default {
>   async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
>     const response = await env.ASSETS.fetch(request);
>     const ua = request.headers.get("user-agent") ?? "";
>     if (AI_CRAWLERS.test(ua)) {
>       ctx.waitUntil(
>         fetch("https://in.crispstats.com/bot", {
>           method: "POST",
>           headers: { "content-type": "application/json" },
>           body: JSON.stringify({ k: "cs_pk_xxxxxxxx", ua, path: new URL(request.url).pathname, status: response.status }),
>         }).then(() => undefined, () => undefined),
>       );
>     }
>     return response;
>   },
> } satisfies ExportedHandler<Env>;
> ```

Replace `cs_pk_xxxxxxxx` with your key. The public key is safe to use here; never use a secret `cs_sk_` key.

**2. Deploy and confirm**

Deploy the change and wait for a crawler to visit, or send a test request with a crawler's User-Agent:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -A "Mozilla/5.0 (compatible; GPTBot/1.2; +https://openai.com/gptbot)" https://example.com/
```

Open **AI traffic** in the dashboard. The **AI crawler hits** chart replaces **Not set up** with a count, and GPTBot appears in the **AI crawlers** table.

The pattern above is the [list of recognized crawlers](#recognized-crawlers). If you would rather let the collector decide, post every request: the collector stores only known AI crawlers, at the cost of one request to the collector per page request.

## The /bot request

From any language, send the same request: `POST https://in.crispstats.com/bot` with a JSON body.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST https://in.crispstats.com/bot \
  -H "content-type: application/json" \
  -d '{"k":"cs_pk_xxxxxxxx","ua":"Mozilla/5.0 (compatible; PerplexityBot/1.0; +https://perplexity.ai/perplexitybot)","path":"/pricing","status":200}'
```

**k** `string` *required*

The site's public key, 4 to 64 characters.

**ua** `string` *required*

The request's User-Agent, up to 1,024 characters.

**path** `string` *required*

The requested path, up to 2,048 characters. A full URL is accepted too. The collector drops the query string and fragment, removes a trailing slash and stores at most 1,024 characters of the path.

**status** `number` (default: 200)

The response status, an integer from 100 to 599.

The collector answers `202` with an empty body as soon as the payload is valid, and does the work afterwards. It answers `400` with `{"error":"invalid_payload"}` when a field is missing or out of range, and `413` with `{"error":"payload_too_large"}` for a body over 16 KB.

A `202` does not mean the hit was stored. The collector silently ignores a hit when the User-Agent is not a known AI crawler, the key does not belong to a site, the site is blocked, or the site is over its per-site rate limit for crawler hits.

## Recognized crawlers

The collector matches each User-Agent against this list, case-insensitively, as a substring. The **Purpose** column is what the dashboard shows next to each crawler.

| Crawler | Operator | Purpose |
| - | - | - |
| GPTBot | OpenAI | Training |
| OAI-SearchBot | OpenAI | Search |
| ChatGPT-User | OpenAI | User-triggered |
| ClaudeBot | Anthropic | Training |
| Claude-SearchBot | Anthropic | Search |
| Claude-User | Anthropic | User-triggered |
| PerplexityBot | Perplexity | Search |
| Perplexity-User | Perplexity | User-triggered |
| Google-Extended | Google | Training |
| GoogleOther | Google | Training |
| Applebot-Extended | Apple | Training |
| Amazonbot | Amazon | Training |
| Bytespider | ByteDance | Training |
| CCBot | Common Crawl | Training |
| Meta-ExternalAgent | Meta | Training |
| Meta-ExternalFetcher | Meta | User-triggered |
| MistralAI-User | Mistral | User-triggered |
| DuckAssistBot | DuckDuckGo | Search |
| cohere-ai | Cohere | Training |
| YouBot | You.com | Search |

The purposes mean:

* **Training:** collects pages to train AI models.
* **Search:** indexes pages so an AI search product can cite them.
* **User-triggered:** fetches a page because someone asked an assistant about it.

## Crawlers never count as visitors

If an AI crawler does load the script, for example through a headless browser, the collector drops that event. AI crawlers are excluded from pageviews and visitors at every [bot filtering](https://docs.crispstats.com/privacy/bot-filtering.md) level, including **off**: they are counted only through `/bot`.

## Learn more on crispstats.com

* Glossary: [AI crawler](https://crispstats.com/glossary/ai-crawler), [llms.txt](https://crispstats.com/glossary/llms-txt) and [bot traffic](https://crispstats.com/glossary/bot-traffic).
* Feature: [AI traffic](https://crispstats.com/features/ai-traffic), where crawler hits and assistant referrals are reported side by side.

## Next steps

> [card] [See AI traffic](https://docs.crispstats.com/ai/ai-traffic.md)
>
> Read crawler hits next to the visitors AI assistants send you.

> [card] [Bot filtering](https://docs.crispstats.com/privacy/bot-filtering.md)
>
> How other bots and automated browsers are kept out of your numbers.

> [card] [Server-side events](https://docs.crispstats.com/track/server-side-events.md)
>
> Send custom events and revenue from your server.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.