Skip to content

Hosts

CrispStats on Vercel: install and proxy

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.

Updated

Set up CrispStats on Vercel

  1. 01

    Step 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 instead, which uses next/script and a route handler for the proxy.

    Replace the highlighted values with your own.

    <scriptdeferdata-site="cs_pk_your_site_key"data-domains="example.com"src="https://in.crispstats.com/d.js"></script>
  2. 02

    Step 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. 03

    Step 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, 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
    {"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. 04

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

    <scriptdeferdata-site="cs_pk_your_site_key"data-domains="example.com"data-api="/k3x9qe"src="/k3x9qe/d.js"></script>
  5. 05

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

    { "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 the install check shows once the first events land, on the demo site, Quillbook, on generated traffic.
  • What you get

    • Pageviews, visitors, sources and channels for the production domain, with preview deployments left out by data-domains.
    • Visitors whose 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 and limits

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

The docs page covers the optional steps this guide leaves out.

Setup questions. Straight answers.

What people ask before they connect it.

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

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

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

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

Not answered here? Write to hello@crispstats.com

Go further

Related

Guides

Your traffic, crisp and clear

One script, no cookies, and every feature from the first day. Set up takes about as long as pasting a snippet.