app/k3x9qe/[...path]/route.ts that forwards everything under that path to https://in.crispstats.com/p/, 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, so those visitors are counted.
The handler is the same on Vercel, on Node and on Cloudflare with OpenNext (@opennextjs/cloudflare) or vinext. It forwards only the headers analytics needs and the visitor’s address, never their cookies. Use your own path instead of /k3x9qe: Settings, Tracking code, Proxy through your own domain proposes one for your site and fills it into this code. See the proxy overview for how the path, the check and signing work on every host.
Set up the proxy
1
Add the route handler
Create the file at
app/k3x9qe/[...path]/route.ts (src/app/k3x9qe/[...path]/route.ts if you use a src folder). The folder name is your path, so it must start with a letter: Next.js does not route folders that start with _. Nothing goes in next.config.ts.app/k3x9qe/[...path]/route.ts
2
Keep proxy.ts away from the path
If your
proxy.ts (or middleware.ts) runs on every path, leave /k3x9qe out of its matcher, so sign-in redirects and other logic never touch these requests.3
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. In JSX a flag attribute takes an empty string: data-outbound="".4
Deploy and run the setup check
Deploy, then open the check through your proxy, in a browser, on your own site:A working proxy answers like this:
"visitorAddressForwarded": true and "cookiesForwarded": false are the two values that matter most. The proxy overview explains every field.Visitor address and location
The handler takes the visitor’s address fromcf-connecting-ip on Cloudflare, then x-real-ip (Vercel and most hosts), then the first x-forwarded-for entry, and sends it as x-forwarded-for. The collector uses it for the daily visitor hash and your excluded IP addresses, then discards it.
For location, it passes Vercel’s x-vercel-ip-country, x-vercel-ip-country-region and x-vercel-ip-city, or Cloudflare’s cf-ipcountry, cf-region-code and cf-ipcity, as the x-crispstats-country, x-crispstats-region and x-crispstats-city headers. On Cloudflare, turn on the Add visitor location headers managed transform for your zone to pass the region and city too. On a host that sends none of these, the collector looks the country, region and city up from the visitor’s address itself.
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, then give it to your host as CRISPSTATS_PROXY_SECRET. The handler sends it when it is set.
Open the setup check again and look for
"signed": true. See sign proxied requests.
FAQ
Why not a rewrite in next.config.ts?
Why not a rewrite in next.config.ts?
A rewrite to another host forwards every request header, including your visitors’ cookies. The route handler copies only the headers listed in
FORWARD.Does it work with the Pages Router?
Does it work with the Pages Router?
The route handler needs the
app folder. An app that otherwise uses the Pages Router can still add this one file under app/.Does crispstats.id() work behind the proxy?
Does crispstats.id() work behind the proxy?
Yes. It asks
/k3x9qe/id, which the same handler forwards. See the visitor id behind a proxy.Next steps
Proxy overview
The path, the check, caching, limits and signing.
Next.js install
The script element for the root layout.
Ad blockers
What a proxy recovers and what it does not.