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, 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 for how the path, the check and signing work on every host.
Set up the proxy
1
Add the route to vercel.json
vercel.json
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: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:Look for
"proxied": true, "visitorAddressForwarded": true and "cookiesForwarded": false. The proxy overview 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’sx-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:
Vercel transform
"signed": true in the setup check. See sign proxied requests.
FAQ
Why not a plain rewrite?
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.My vercel.json already has rewrites. What now?
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.Does crispstats.id() work behind the proxy?
Does crispstats.id() work behind the proxy?
Yes. It asks
/k3x9qe/id, which the same route forwards.Next steps
Proxy overview
The path, the check, caching, limits and signing.
Next.js route handler
The proxy for Next.js apps, with location.
Ad blockers
What a proxy recovers and what it does not.