# CrispStats on Vercel: install and proxy

Updated 2026-11-23

To use CrispStats on Vercel, add the script tag to your site's pages and deploy; Vercel needs no setting of its own. To count visitors whose ad blocker stops analytics hosts, add one route to vercel.json that forwards a path such as /k3x9qe/* to the collector and deletes the cookie and authorization headers on the way.

## Steps

### 1. Add the script tag to your site

Copy the tag from **Settings**, **Tracking code** in the dashboard and put it inside `<head>` on every page, in your source code or layout. For a Next.js app, follow the [Next.js guide](/integrations/nextjs) instead, which uses `next/script` and a route handler for the proxy.

```html
<script
  defer
  data-site="cs_pk_your_site_key"
  data-domains="example.com"
  src="https://in.crispstats.com/d.js"
></script>
```

### 2. Deploy and open the production domain

Deploy as usual, then open the site on its real domain. `data-domains` keeps preview deployments on `*.vercel.app` out of your numbers, so a preview URL sends nothing until you add its hostname. That is on purpose: previews are not visitors.

### 3. Add the proxy route to vercel.json

Under **Settings**, **Tracking code**, **Proxy through your own domain**, the dashboard proposes a path for your site. Add a route that forwards it to the collector. The two `delete` transforms, documented in [Vercel's vercel.json reference](https://vercel.com/docs/project-configuration/vercel-json), remove cookies and authorization before the request leaves Vercel. Vercel processes routes in the order you list them, so put this one before any catch-all route.

`vercel.json`

```json
{
  "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" } }
      ]
    }
  ]
}
```

### 4. Point the script tag at the path

Replace the tag with this one. `data-api` is required: without it the script sends events to `/e` on your own domain, and those requests fail.

```html
<script
  defer
  data-site="cs_pk_your_site_key"
  data-domains="example.com"
  data-api="/k3x9qe"
  src="/k3x9qe/d.js"
></script>
```

### 5. Sign the requests (optional)

Reveal the proxy secret (`cs_px_…`) under **Advanced: sign proxied requests**, add it as `CRISPSTATS_PROXY_SECRET` in the project's environment variables, add this transform to the route's `transforms` and redeploy.

```json
{ "type": "request.headers", "op": "set", "target": { "key": "x-crispstats-proxy-secret" }, "args": "$CRISPSTATS_PROXY_SECRET", "env": ["CRISPSTATS_PROXY_SECRET"] }
```

## Check that it works

After deploying, open `https://example.com/k3x9qe/check?k=cs_pk_your_site_key` with your domain, path and key, in a browser on your own site. Look for `"proxied": true`, `"visitorAddressForwarded": true` and `"cookiesForwarded": false`. `"location": { "source": "proxy" }` means Vercel's location headers came through; `"timezone"` means the country comes from the browser's timezone instead. Your visit then appears on **Realtime**.

## What you get

- Pageviews, visitors, sources and channels for the production domain, with preview deployments left out by `data-domains`.
- Visitors whose [ad blocker](/glossary/ad-blocker) stops analytics hosts, counted again once the route is live.
- Visits from AI assistants such as ChatGPT and Perplexity in their own channel, with landing pages and revenue.
- Revenue attribution through the proxy: `crispstats.id()` asks `/k3x9qe/id`, which the same route forwards.
- A core script of about 2.2 KB gzipped, cached by browsers for a day and revalidated with a `304`.

## Notes for Vercel

- Do not proxy with a plain rewrite to another host: it passes every request header on, including your visitors' login cookies. The transforms in the route are what make it safe.
- If your `vercel.json` already has `rewrites`, `redirects` or `headers`, [Vercel's reference](https://vercel.com/docs/project-configuration/vercel-json) says `routes` can sit alongside them, and that `src` matching is then case-sensitive. Run the setup check after deploying, and if it fails, forward the path from a server-side function instead.
- Vercel adds the visitor's address to the forwarded request. The collector uses it for the daily visitor hash and your excluded IP addresses, then discards it.
- AI crawlers do not run JavaScript, so they never appear as visitors. Report them from your server or edge code if you want them in the AI crawler report: see [AI crawlers](/docs/ai/ai-crawlers).

Full reference: [Vercel in the docs](https://docs.crispstats.com/tracking/proxy/vercel)

## Frequently asked questions

### How do I add analytics to a site hosted on Vercel?

Put the script tag in the head of every page in your code and deploy. Vercel serves it like any other HTML, so there is no Vercel setting or integration to turn on.

### Why do preview deployments show no visits?

The snippet's data-domains attribute lists your real domain, so events from vercel.app preview URLs are not sent. Add a preview hostname to data-domains only if you want those visits counted.

### How is this different from Vercel Web Analytics?

Vercel Web Analytics is Vercel's own product for projects on Vercel. CrispStats works on any host and includes revenue attribution, funnels, error tracking and uptime on every plan. The comparison page has the details.

### Does the proxy cost extra?

Not on the CrispStats side: every feature is on every plan and in the 14-day free trial. Vercel's own limits and pricing apply to your project.

## Related

- [CrispStats vs Vercel Analytics](/vs/vercel-analytics)
- [Next.js analytics](/integrations/nextjs)
- [Revenue attribution](/features/revenue-attribution)
- [First-party data explained](/glossary/first-party-data)
- [Proxy on Netlify](/integrations/netlify)
- [Proxy with a Cloudflare Worker](/integrations/cloudflare)
