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

# Proxy CrispStats on Vercel with vercel.json

> Serve the CrispStats script and events from your own domain on Vercel with one route in vercel.json that strips cookies and authorization before forwarding.

To proxy CrispStats on Vercel, add one route to `vercel.json` that forwards `/k3x9qe/*` to `https://in.crispstats.com/p/*` and deletes the `cookie` and `authorization` headers on the way, then point the script tag at the path with `data-api`. Ad blockers that stop known analytics hosts then see a request to your own domain.

This page is for sites on Vercel that are not Next.js. For a Next.js app, use the [route handler](https://docs.crispstats.com/tracking/proxy/nextjs.md), which also passes the visitor's location. Use your own path instead of `/k3x9qe`: **Settings**, **Tracking code**, **Proxy through your own domain** proposes one for your site. See [the proxy overview](https://docs.crispstats.com/tracking/proxy.md) for how the path, the check and signing work on every host.

## Set up the proxy

**1. Add the route to vercel.json**

```json vercel.json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "routes": [
    {
      "src": "/k3x9qe/(.*)",
      "dest": "https://in.crispstats.com/p/$1",
      "transforms": [
        { "type": "request.headers", "op": "delete", "target": { "key": "cookie" } },
        { "type": "request.headers", "op": "delete", "target": { "key": "authorization" } }
      ]
    }
  ]
}
```

Vercel does not allow `routes` in the same file as `rewrites`, `redirects` or `headers`. If your `vercel.json` uses those, use a route handler or another server-side function instead.

**2. Point the script tag at the path**

`src` loads the script from your domain, and `data-api` sends events and visitor id requests to the same path:

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

`data-api` is required. Without it the script sends events to `/e` on your own domain, and those requests fail.

**3. Deploy and run the setup check**

Deploy, then open the check through your proxy, in a browser, on your own site:

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

Look for `"proxied": true`, `"visitorAddressForwarded": true` and `"cookiesForwarded": false`. The [proxy overview](https://docs.crispstats.com/tracking/proxy.md#check-it-works) explains every field.

## Visitor address and location

Vercel adds the visitor's address to the forwarded request, and the collector uses it for the daily visitor hash and your excluded IP addresses, then discards it. The collector also reads Vercel's `x-vercel-ip-country`, `x-vercel-ip-country-region` and `x-vercel-ip-city` headers when they arrive with the request. Run the setup check: `"location": { "source": "proxy" }` means the location came through, `"timezone"` means the country comes from the browser's timezone instead.

## Sign the requests (optional)

Signing proves a forwarded request came from your proxy. Reveal the secret (`cs_px_…`) in **Settings**, **Tracking code**, **Proxy through your own domain**, **Advanced: sign proxied requests**. Add it as `CRISPSTATS_PROXY_SECRET` in the project's environment variables, and add this transform to the route's `transforms`:

```json Vercel transform theme={"theme":{"light":"github-light","dark":"github-dark"}}
{ "type": "request.headers", "op": "set", "target": { "key": "x-crispstats-proxy-secret" }, "args": "$CRISPSTATS_PROXY_SECRET", "env": ["CRISPSTATS_PROXY_SECRET"] }
```

Redeploy, then look for `"signed": true` in the setup check. See [sign proxied requests](https://docs.crispstats.com/tracking/proxy.md#sign-proxied-requests).

## FAQ

> [accordion] Why not a plain rewrite?
>
> A plain rewrite to another host passes every request header on, including cookies. The two `delete` transforms in the route remove `cookie` and `authorization` before the request leaves Vercel.

> [accordion] My vercel.json already has rewrites. What now?
>
> `routes` cannot sit next to `rewrites`, `redirects` or `headers`. Add a small server-side function that forwards the path instead, or, for a Next.js app, the [route handler](https://docs.crispstats.com/tracking/proxy/nextjs.md).

> [accordion] Does crispstats.id() work behind the proxy?
>
> Yes. It asks `/k3x9qe/id`, which the same route forwards.

## Next steps

> [card] [Proxy overview](https://docs.crispstats.com/tracking/proxy.md)
>
> The path, the check, caching, limits and signing.

> [card] [Next.js route handler](https://docs.crispstats.com/tracking/proxy/nextjs.md)
>
> The proxy for Next.js apps, with location.

> [card] [Ad blockers](https://docs.crispstats.com/help/ad-blockers.md)
>
> What a proxy recovers and what it does not.


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