> ## 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.

# Collector endpoints reference

> Reference for the public CrispStats collector at in.crispstats.com: the script, POST /e for browser and server events, GET /id, the /p proxy routes, the setup check, /bot and the live count.

The collector at `https://in.crispstats.com` serves the tracking script and receives every event. The script calls it for you, so most sites never touch it directly. Use this reference when you send events from your own server, proxy the collector through your domain, check a setup, report AI crawler hits from your edge, or need the exact payload and status codes.

## Routes

| Route | Purpose |
| - | - |
| `GET /d.js`, `GET /d.core.js` | The tracking script, with and without the optional modules. `GET /js/script.js` is the same file as `/d.js`. |
| `POST /e` | Receive an event from a browser, or from your server with a secret key. |
| `GET /id` | The anonymous visitor id for the current browser, for revenue attribution. |
| `GET /check` | Check a direct install: is the key known, where does the location come from. |
| `GET /p/…` and `POST /p/e` | The same routes for a site that proxies the collector through its own domain. See [proxy routes](#proxy-routes). |
| `POST /api/event`, `GET /api/id` | Older proxy routes, kept working: `/api/event` is `/p/e`, `/api/id` is `/p/id`. |
| `POST /bot` | Report an AI crawler hit seen at your edge. |
| `GET /live/{siteId}/count` | The live visitor count behind the public badge. |

All routes allow requests from any origin. Request bodies on `POST /e`, `POST /p/e`, `POST /api/event` and `POST /bot` are limited to 16 KB (16,384 bytes); a larger body returns `413` with `{ "error": "payload_too_large" }`. Every route is rate limited; see [collector limits](https://docs.crispstats.com/api-reference/rate-limits.md#collector-limits).

## Who the visitor is

The collector derives the anonymous visitor id from the visitor's address and User-Agent, then discards both. Which address it uses depends on the route:

| Route | Visitor address |
| - | - |
| `/e`, `/id`, `/check` | The connecting address. `X-Forwarded-For` is ignored. |
| `/p/e`, `/p/id`, `/p/check`, `/api/id` | The first public address in `X-Forwarded-For`. Private and malformed entries are skipped. Without one, the connecting address. |
| `/api/event` | The first `X-Forwarded-For` entry when it is a public address, otherwise the connecting address. |

## POST /e

The collector endpoint. It behaves in two ways depending on the `Authorization` header.

### From a browser

The script sends one JSON payload per event with `navigator.sendBeacon`, or `fetch` with `keepalive`, as `text/plain` so the browser sends no preflight. The collector parses the body as JSON whatever the content type, answers `202 Accepted` with an empty body at once, and does the work afterwards.

| Status | When |
| - | - |
| `202` | Always for a JSON object, including unknown site keys, bots, blocked sites, rate-limited addresses and payloads that fail validation. The answer never reveals which. |
| `400` | The body is not a JSON object: `{ "error": "invalid_json" }`. |
| `413` | The body is over 16 KB. |

Because a browser request always gets `202`, use [`GET /check`](#get-/check) to confirm a setup, and the [realtime view](https://docs.crispstats.com/dashboard/realtime.md) to confirm events arrive. [Troubleshooting](https://docs.crispstats.com/help/troubleshooting.md) covers the usual causes when they do not.

### From your server

Send the same payload as `application/json` with `Authorization: Bearer cs_sk_…`. Write the header exactly like that, with `Bearer` capitalized and a single space: any other form is treated as a browser request and gets a silent `202`. Create the key under **API keys** on the [workspace page](https://docs.crispstats.com/account/api-keys.md#create-a-key) with the **Events** scope (**Write** and **Admin** also work); it must cover the site in `k`. A key with only **Read** gets `403`.

Server calls accept three event types: `event`, `revenue` and `identify`. No IP address or User-Agent is used: the event joins a visit only through `vid`, a visitor id you saved earlier from `crispstats.id()` or [`GET /id`](#get-/id). `u` is required but may be empty.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://in.crispstats.com/e" \
  -H "Authorization: Bearer $CRISPSTATS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "k": "cs_pk_xxxxxxxx",
    "t": "event",
    "n": "subscription_renewed",
    "u": "",
    "p": { "plan": "pro" },
    "vid": "0f3c9a1e2b4d5f60718293a4b5c6d7e8",
    "i": "user_42"
  }'
```

Server calls get real status codes:

| Status | Body | Meaning |
| - | - | - |
| `202` | empty | Accepted. Also returned, without storing anything, when the site is blocked. |
| `400` | `{ "error": "invalid_payload", "fields": ["n"] }` | The payload failed validation. `fields` lists up to 10 failing fields. |
| `400` | `{ "error": "unsupported_event_type" }` | `t` is not `event`, `revenue` or `identify`. |
| `401` | `{ "error": "invalid_api_key" }` | The key is unknown, revoked or expired. |
| `403` | `{ "error": "key_not_valid_for_site" }` | The key lacks a sending scope, or does not cover the site in `k`. |
| `429` | `{ "error": "rate_limited" }` | Too many server events for this site. |
| `503` | `{ "error": "temporarily_unavailable" }` | The key could not be checked. Retry later. |

Without a valid `vid` (32 lowercase hex characters), the event is counted on its own and is not linked to any visit. A `revenue` event carries the amount in `a` (integer minor units) and the currency in `c`; without `c`, the site's currency is used. A negative amount records a refund, which only a secret key may send.

[Server-side events](https://docs.crispstats.com/track/server-side-events.md) walks through the whole flow.

### Payload

The payload uses short keys because the script sends it on every pageview. Only `k`, `t` and `u` are required.

| Field | Type | Description |
| - | - | - |
| `k` | string, 4 to 64 | The site's public key, `cs_pk_…`. |
| `t` | string | Event type: `pageview`, `event`, `vitals`, `error`, `identify`, `revenue` or `ping`. Server calls accept `event`, `revenue` and `identify`. |
| `u` | string, up to 2048 | Full page URL. May be empty on server calls. |
| `n` | string, up to 120 | Event name for custom events, such as `signup`. |
| `r` | string, up to 2048 | Referrer URL. |
| `w` | integer, 0 to 20000 | Screen width in CSS pixels. The device class is derived from it. |
| `l` | string, up to 35 | Browser language, such as `en-GB`. |
| `z` | string, up to 64 | IANA timezone, such as `Europe/Berlin`. |
| `p` | object | Flat custom properties. Keys up to 60 characters; values are strings up to 500 characters, numbers, booleans or `null`. |
| `a` | integer | Revenue amount in minor units. |
| `c` | string, 3 letters | ISO 4217 currency code for `a`. |
| `v` | object | Web vitals: `lcp`, `inp`, `cls`, `fcp`, `ttfb` in milliseconds, CLS multiplied by 1000. |
| `e` | object | Error details: `message` (required, up to 1000), `source`, `line`, `col`, `stack` (up to 4000). |
| `i` | string, up to 200 | Your own user id, set by `crispstats.identify()`. |
| `d` | integer, 0 to 86400 | Seconds the page was visible, sent on `ping`. |
| `s` | integer, 0 to 100 | Maximum scroll depth in percent, sent on `ping`. |
| `ts` | integer | Client timestamp in milliseconds. Server time is authoritative. |
| `vid` | string, up to 64 | Visitor id. Sent by the script only with [persistent visitors](https://docs.crispstats.com/privacy/persistent-visitors.md), and by server calls. |

### What is stored from the URLs

Whatever the script sends, the collector stores the page path with only the query parameters the site keeps (set in the site's settings); everything else on the query string is dropped. UTM values (`utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, `utm_content`, and `ref`, `source` or `via` as the source) are read into their own fields, and the names of ad click ids such as `gclid` decide the paid channel; their values are not stored. Of the referrer, only the host is stored. A URL fragment is kept only as a hash route (`#/settings`), never as `#access_token=…`.

### Which events count toward the plan

Pageviews and custom events (`t` of `pageview` or `event`) count toward the plan's monthly events. That includes the events the script sends for you: `404`, `Outbound link` and `File download` are custom events. `identify`, `revenue`, `ping`, `vitals` and `error` do not count, and neither do payments from webhooks. Only stored events count: events dropped as bots, excluded pages or duplicates do not.

## GET /id

Returns the anonymous id the collector files this browser's events under right now. Put it on the checkout as `metadata.crispstats_visitor_id` (or `client_reference_id`) so a payment is attributed to the visit. The script calls it for you through `crispstats.id()`.

**k** `string` *required*

The site's public key, `cs_pk_…`.

**vid** `string`

The persistent visitor id, up to 64 characters, when the site uses persistent visitors.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://in.crispstats.com/id?k=cs_pk_xxxxxxxx"
```

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{ "id": "0f3c9a1e2b4d5f60718293a4b5c6d7e8" }
```

The response is never cached. A key that is not shaped like a public key (`cs_pk_` followed by letters, digits, `_` or `-`, 8 to 64 characters in all) returns `400` with `{ "error": "invalid_key" }`. A well-formed key that does not exist still returns an id, so the endpoint does not reveal which keys exist.

Call it from the visitor's browser: the id is derived from the request, so calling it from your server returns an id for your server, not for the visitor. A site behind a proxy calls `<prefix>/id`, which reaches `GET /p/id`. Calling `https://in.crispstats.com/id` directly from the browser also works on a proxied site, and returns the same id when the proxy forwards the visitor's address. See [visitor id at checkout](https://docs.crispstats.com/revenue/visitor-id-at-checkout.md).

## GET /check

Checks a setup and says what the collector sees. It reveals nothing about a key beyond whether it is known (public keys are in every page's source anyway), and never echoes an address. For a direct install, open it in the browser on the page you are checking; for a proxy, request `<prefix>/check` so the request takes the same path as the script's.

**k** `string` *required*

The site's public key, `cs_pk_…`.

**tz** `string`

An IANA timezone, such as `Europe/Lisbon`. Fills `location.country` when the location would come from the timezone.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://example.com/mw/check?k=cs_pk_xxxxxxxx"
```

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "ok": true,
  "version": "0.1.0",
  "site": "known",
  "proxied": true,
  "visitorAddressForwarded": true,
  "signed": true,
  "signatureRequired": false,
  "cookiesForwarded": false,
  "location": { "source": "proxy", "country": "PT" },
  "hostnames": ["example.com", "*.example.com"]
}
```

| Field | Description |
| - | - |
| `ok` | `true` when the key is known and, behind a proxy, the visitor address arrives, no cookies are forwarded and a required signature is present. |
| `version` | The tracking script's version. |
| `site` | `"known"` or `"unknown"`. |
| `proxied` | The request came in on a `/p` route. |
| `visitorAddressForwarded` | The collector found a public visitor address in `X-Forwarded-For` and believes it. `false` on `/check`. |
| `signed` | The request carried the site's proxy secret. `null` when not proxied. |
| `signatureRequired` | The site only trusts signed proxies. |
| `cookiesForwarded` | The request carried a `Cookie` header: the proxy is forwarding the visitor's cookies and should not. |
| `location.source` | `"edge"` (Cloudflare's location of a direct visitor), `"proxy"` (location headers from the proxy) or `"timezone"` (the browser's timezone, country only). |
| `location.country` | ISO 3166-1 alpha-2 code, or `null`. |
| `hostnames` | The hostnames the site accepts events from. Only present when the key is known. Without a list in the site's settings, the site's domain and its subdomains. |

The response is never cached. Over the rate limit it returns `429` with `{ "ok": false, "error": "rate_limited" }`.

## Proxy routes

A site can serve the script and collector from its own domain with one forwarding rule: everything under a path of yours, such as `/mw`, goes to `https://in.crispstats.com/p/`. The script tag then points at your path:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script defer data-site="cs_pk_xxxxxxxx" data-api="/mw" src="/mw/d.js"></script>
```

| Route | Same as |
| - | - |
| `GET /p/d.js`, `GET /p/{name}.js` | `GET /d.js`. Any file name made of letters, digits, `.`, `_` and `-` works, so you can pick one ad blockers do not list. |
| `GET /p/d.core.js` | `GET /d.core.js`. |
| `POST /p/e` | `POST /e`, with the visitor address forwarded. |
| `GET /p/id` | `GET /id`, with the visitor address forwarded. |
| `GET /p/check` | `GET /check`, for the proxy. |

The scripts under `/p` are served with exactly the same caching and `ETag` as `/d.js`. The older `POST /api/event` and `GET /api/id` follow the same rules for location headers, signatures and limits as `/p/e` and `/p/id`. [Proxy through your domain](https://docs.crispstats.com/tracking/proxy.md) has ready proxies for Next.js, Cloudflare Workers and other hosts.

### What the proxy forwards

Forward only these request headers: `content-type`, `user-agent`, `accept-language`, `referer`, `origin` and `if-none-match`, plus `x-forwarded-for` set to the visitor's address. Never forward `cookie` or `authorization`: the collector needs neither, and `GET /p/check` reports `cookiesForwarded: true` when a proxy does. Return only `content-type`, `cache-control`, `etag` and `access-control-allow-origin` from the collector's response; the last one lets the dashboard read `<prefix>/check` from another origin.

### Location

Behind a proxy, Cloudflare's location data describes your server, not the visitor. A proxy that knows the visitor's location can pass it on; otherwise the country comes from the browser's timezone.

| Header | Value |
| - | - |
| `x-crispstats-country` | ISO 3166-1 alpha-2 code, such as `PT`. Required for the other two to count. |
| `x-crispstats-region` | Region, up to 64 characters. |
| `x-crispstats-city` | City, up to 80 characters. Percent-encode non-ASCII names, as `encodeURIComponent` does. |

Vercel's `x-vercel-ip-country`, `x-vercel-ip-country-region` and `x-vercel-ip-city` are read too when a proxy passes them on. A country that is not a real two-letter code, and a region or city that is too long or not printable text, is ignored.

### Signed proxies

A server-side proxy can prove a request is its own with the header `x-crispstats-proxy-secret`, set to the site's proxy secret (`cs_px_` and 32 hex characters, shown with the proxy setup in the dashboard). Keep it on your server, in an environment variable; never put it in the page. A signed request is fully trusted: its forwarded address and location headers are used.

Without the header, forwarding is trusted as long as the site does not require signing. A site can require signed proxies in its settings: then a request on a proxy route without a valid secret is treated as coming from your server's address, and its forwarded address and location headers are ignored. This stops anyone from posting events with made-up visitor addresses.

## POST /bot

Reports a request from an AI crawler that your edge or middleware saw. AI crawlers do not run JavaScript, so the script cannot count them.

```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; GPTBot/1.2; +https://openai.com/gptbot)", "path": "/pricing", "status": 200 }'
```

| Field | Type | Description |
| - | - | - |
| `k` | string, 4 to 64, required | The site's public key. |
| `ua` | string, up to 1024, required | The crawler's User-Agent. |
| `path` | string, up to 2048, required | The requested path, or a full URL. The query string is dropped. |
| `status` | integer, 100 to 599 | The status your server answered with. Defaults to `200`. |

The collector answers `202` for any valid body and records the hit only when the User-Agent matches a known AI crawler. A body that fails validation returns `400` with `{ "error": "invalid_payload" }`. Hits are limited per site. See [AI crawlers](https://docs.crispstats.com/ai/ai-crawlers.md).

## GET /live/{siteId}/count

The number of visitors on the site right now, as shown by the [live visitor badge](https://docs.crispstats.com/share/live-visitor-badge.md). It works only when the site has the public live count turned on.

**siteId** `string` *required*

The site id.

**k** `string` *required*

The site's public key. It must belong to `siteId`.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://in.crispstats.com/live/YOUR_SITE_ID/count?k=cs_pk_xxxxxxxx"
```

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{ "visitors": 12 }
```

The response is cached for 10 seconds (`Cache-Control: public, max-age=10`). An unknown site, a key that does not match, a blocked site and a site without the public count all return `404` with `{ "error": "not_found" }`.

## GET /d.js and GET /d.core.js

The tracking script. `/d.js` includes every optional module, each switched on by its own attribute; `/d.core.js` leaves the optional modules out and ignores their attributes. `/js/script.js` and every `/p/{name}.js` serve the same file as `/d.js`, and `/p/d.core.js` the same as `/d.core.js`. See [script builds](https://docs.crispstats.com/tracking/script-builds.md).

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script defer data-site="cs_pk_xxxxxxxx" src="https://in.crispstats.com/d.js"></script>
```

All of them are served with:

| Header | Value |
| - | - |
| `Cache-Control` | `public, max-age=86400, stale-while-revalidate=604800` |
| `ETag` | Changes with each script version. A matching `If-None-Match` returns `304`. |
| `Cross-Origin-Resource-Policy` | `cross-origin` |
| `Access-Control-Allow-Origin` | `*` |

## Other routes

* `POST /hooks/{provider}/{ref}` receives payment webhooks. When you connect a provider with a key, CrispStats creates the webhook at the provider with this URL where the key allows it; you never copy it yourself. Razorpay, the App Store and the Shopify App Store are read on a schedule instead, because CrispStats cannot create a webhook with their keys. See [revenue attribution](https://docs.crispstats.com/revenue/overview.md).
* Any other path returns `404` with `{ "error": "not_found" }`.

## Next steps

> [card] [Server-side events](https://docs.crispstats.com/track/server-side-events.md)
>
> Send events from webhooks, crons and background jobs.

> [card] [Proxy through your domain](https://docs.crispstats.com/tracking/proxy.md)
>
> Serve the script and collector from your own domain.

> [card] [Collector limits](https://docs.crispstats.com/api-reference/rate-limits.md#collector-limits)
>
> How many events an address and a site may send.


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