Skip to main content
Ad blockers stop requests to known analytics hosts, which hides part of your audience. To count those visitors, serve the CrispStats script and the event endpoint from a path on your own domain. One forwarding rule sends everything under that path to https://in.crispstats.com/p/, and the script tag points at the path with data-api. All four come from the same rule: /k3x9qe/* to https://in.crispstats.com/p/*. The examples on this page use /k3x9qe and example.com; use your own path and domain.
The older setup with two rules, /stats/d.js to /js/script.js and /stats/e to /api/event, keeps working. You do not have to change it. See the two-rule setup for what is different and why moving is worth it.

Guides by host

Each host has its own page with the rule, the script tag, the setup check, where the visitor’s address and location come from, and how to sign requests. This page covers what they share.

Next.js

A route handler. Vercel, Node and Cloudflare (OpenNext, vinext).

Vercel

A route in vercel.json, for sites that are not Next.js.

Netlify

An edge function.

Cloudflare Worker

A Worker on one route of your zone.

nginx

A location block.

Caddy

A handle_path block in the Caddyfile.

Choose a path

Use a short path that is unique to your site, not /stats, /analytics or /tracking: blockers can list a common path as easily as a host. Settings, Tracking code, Proxy through your own domain proposes one for each site, such as /k3x9qe, and fills it into every example there. It is derived from the site, so it never changes. Any other path works, as long as the rule and the script tag use the same one. For a Next.js route handler, the path becomes a folder name, so start it with a letter: Next.js treats folders that start with _ as private and does not route them. The proposed path always starts with a letter.

Set up the proxy

1

Forward the path to the collector

Pick your host. Each example forwards only the request headers analytics needs and the visitor’s address, never their cookies (see what a proxy forwards).
Create a route handler at app/k3x9qe/[...path]/route.ts (src/app/k3x9qe/[...path]/route.ts if you use a src folder). Nothing goes in next.config.ts or next.config.mjs.
app/k3x9qe/[...path]/route.ts
It runs on Vercel, on Node and on any other host. It reads the visitor’s address and, on Vercel and Cloudflare, their location. 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.
Do not use rewrites() in next.config.ts for this. A rewrite to another host forwards every request header, including your visitors’ login cookies.
2

Point the script tag at the path

Replace the tag on your site. src loads the script from your domain, and data-api sends events and visitor id requests to the same path:
Keep any other attributes you use, such as data-outbound. In JSX, a flag attribute takes an empty string: data-outbound="". The dashboard shows the tag for your platform with your key, domain and path filled in.data-api is required. Without it the script sends events to /e on the origin it was loaded from, which is your own domain, and those requests fail.
3

Run the setup check

Open the setup check through your proxy, in a browser, on your own site:
It answers with JSON. A working proxy looks like this:
Then open your site, filter the browser’s network panel by k3x9qe, and check that /k3x9qe/d.js loads with 200 (or 304 once cached) and the POST to /k3x9qe/e gets 202. Your visit appears in Realtime within a few seconds.

Check it works

The setup check, GET <your path>/check?k=<public key>, tells you what the collector sees for a request that came through your proxy. It never shows an address. Settings, Tracking code, Proxy through your own domain, step 3 Check it runs the same check from the dashboard once the first event arrives, and lists what it found. ok is true when the key is known, the visitor’s address arrives, no cookies are forwarded and, if the site requires it, the request is signed.
From the dashboard your browser sends no cookies to your site, so the dashboard cannot see cookie forwarding. Open the check in a tab on your own site, signed in as a user would be, and look for "cookiesForwarded": false.
A direct install has a check too: https://in.crispstats.com/check?k=cs_pk_xxxxxxxx. See the collector reference.

What a proxy forwards

The collector needs only a few request headers. Every example on this page forwards exactly these, and nothing else: Never forward cookie or authorization. A proxy that copies all request headers, such as new Headers(request.headers) in a Worker or rewrites() in next.config.ts, sends your visitors’ login cookies to a third party. The collector does not need them and the setup check reports them as cookiesForwarded: true. From the collector’s response, the examples pass back content-type, cache-control, etag and access-control-allow-origin. The last one lets the dashboard read your /check from another origin.

The visitor address

Behind a proxy, every request reaches the collector from your server. CrispStats counts visitors with a daily hash of the visitor’s address and User-Agent, so the proxy has to pass the visitor’s address along, in x-forwarded-for. The address is used for that hash and for your excluded IP addresses, then discarded. It is never stored. On /p routes the collector takes the first public address in x-forwarded-for. Private addresses (such as 10.x.x.x or 192.168.x.x) and malformed entries are skipped. Without a public address it uses your server’s address, and visitors on the same browser version merge into one. The direct routes, /e and /id, ignore x-forwarded-for. Where each host gets the address: To confirm it arrives, open the setup check and look for "visitorAddressForwarded": true.

Location

Without a proxy, the collector places a visitor from its own network edge. Behind a proxy that edge sees your server, so the collector places the visitor in one of three ways, in this order:
  1. Your location headers, when your proxy sends them (below). They always win.
  2. The visitor’s address. When your proxy forwards the address in x-forwarded-for (every setup on this page does) and sends no location headers, the collector looks the address up in an IP-location database that CrispStats hosts itself. You get country, region, city and the point on the map with nothing to add to your code, behind any proxy, nginx and one-line rewrites included. The address is used for that lookup in memory only: it is never stored, and no third party receives it.
  3. The browser’s timezone, when neither arrived. That gives the country only.
A proxy that knows where the visitor is can still say so in three headers: The Next.js handler, the Netlify function and the Cloudflare Worker above set them from what the host provides. The collector also reads Vercel’s x-vercel-ip-country, x-vercel-ip-country-region and x-vercel-ip-city when a proxy passes them on. You do not need them for region and city any more; send them when your host knows the location, and they are used instead of the lookup. The setup check shows where the location came from: "location": { "source": "proxy" } when your headers arrived, "lookup" when the collector looked the address up, "timezone" when neither was possible.
IP Geolocation by DB-IP. The database is DB-IP’s IP to City Lite, licensed under CC BY 4.0 and refreshed monthly.

The visitor id behind a proxy

crispstats.id() returns the visitor id you pass to your payment provider for revenue attribution. Behind a proxy it asks <data-api>/id, which the one rule forwards to /p/id, so it works on every page, single-page apps included. If the proxy does not answer with the expected JSON, for example with the older two-rule setup that forwards no /id, the script asks https://in.crispstats.com/id directly instead. Calling https://in.crispstats.com/id?k=cs_pk_xxxxxxxx yourself from the visitor’s browser keeps working too. Both give the same id when your proxy forwards the visitor’s address, unless a blocker stops the direct request.

Script caching

The collector serves the script with Cache-Control: public, max-age=86400, stale-while-revalidate=604800 and an ETag, and answers 304 to a matching If-None-Match. Every example passes cache-control and etag back and forwards if-none-match, so browsers cache the script for a day and then revalidate it cheaply. The Cloudflare Worker also keeps the script in your zone’s cache for a day (cacheTtl: 86400), so most script requests never leave your zone. Events, /id and /check are never cached. See script builds. Under your path, any file name ending in .js serves the full script, so /k3x9qe/app.js works as well as /k3x9qe/d.js. /k3x9qe/d.core.js serves the core build.

Rate limits behind a proxy

Proxied requests are never limited by your proxy’s own address, so sites whose proxies share a host’s outgoing addresses (on Vercel, Netlify or Cloudflare) do not share a limit. On /p routes, the collector counts by site and visitor address, 1,200 events a minute for one visitor, with a ceiling of 6,000 a minute for all proxied traffic of one site in each Cloudflare location. A direct POST /e is counted by the connecting address, 1,200 a minute. Requests signed with your proxy secret skip the per-site ceiling, so forged unsigned traffic cannot crowd out your real visitors. See collector limits.

Sign proxied requests

Signing is optional, and worth doing for any site with real traffic. It proves that a forwarded request came from your proxy, so nobody else can post events to your site’s proxy routes with made-up visitor addresses or locations, and signed requests skip the per-site ceiling that forged traffic could otherwise fill.
1

Reveal the proxy secret

In Settings, Tracking code, Proxy through your own domain, open Advanced: sign proxied requests and select Reveal. Owners and admins can see it. The secret starts with cs_px_. Keep it on your server: never put it in the page.
2

Give it to your proxy

The code examples read it from an environment variable named CrispStats_PROXY_SECRET and send it as the x-crispstats-proxy-secret header when it is set.
Vercel transform
nginx
3

Check, then require it

Open the setup check and look for "signed": true. Then you can turn on Only accept proxied events signed with this secret in the same section. From then on, a request on a proxy route without a valid secret is treated as coming from your server: its forwarded address and location headers are ignored.
Without the switch, unsigned forwarding keeps working as before, and signed requests are trusted the same way.

The older two-rule setup

Sites set up before the one-rule proxy forward two paths: with the tag data-api="/stats" src="/stats/d.js". This keeps working. /api/event takes the visitor from the first x-forwarded-for entry when it is a public address, and follows the same location headers, signing and per-visitor limits as /p/e. crispstats.id() falls back to the collector directly, because these rules forward no /id. Moving to the one rule is worth it when:
  • your rules are rewrites that copy every request header (next.config.ts rewrites, a Netlify _redirects proxy, a Worker that uses new Headers(request.headers)): they send your visitors’ cookies to the collector,
  • you want /check and /id through your own domain,
  • your path is /stats, which blockers can list.
To move, deploy the new rule under a new path, switch the tag to that path, and remove the old rules once no cached page uses them.

What else changes behind a proxy

  • Content Security Policy. 'self' covers the script and events. See Content Security Policy.
  • Excluded IP addresses are compared with the forwarded visitor address. See exclude traffic.
  • Ad blockers that list your path can still stop it. A path unique to your site makes that unlikely. See ad blockers.

Next steps

Ad blockers

How blockers affect your counts and what a proxy recovers.

Script builds

Which file is which, caching and versions.

Collector reference

Every route under /p and what it answers.
Last modified on November 26, 2026