netlify/edge-functions/crispstats.ts that forwards /k3x9qe/* 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.
Use an edge function rather than a _redirects proxy rule: a plain proxy rule passes your visitors’ cookies along, while this function picks the headers itself. 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 edge function
netlify/edge-functions/crispstats.ts
config export at the end sets the path the function runs on.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
"visitorAddressForwarded": true, "cookiesForwarded": false and "location": { "source": "proxy" }. The proxy overview explains every field.Visitor address and location
Netlify gives the function the visitor’s address ascontext.ip and their location as context.geo. The function passes the address as x-forwarded-for, and the country code, region code and city as x-crispstats-country, x-crispstats-region and x-crispstats-city. The collector uses the address for the daily visitor hash and your excluded IP addresses, then discards it.
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 site’s environment variables and redeploy. The function reads it with Netlify.env.get and sends it when it is set. Then look for "signed": true in the setup check. See sign proxied requests.
FAQ
Why not a _redirects rule with status 200?
Why not a _redirects rule with status 200?
A proxy rule copies every request header to the collector, including your visitors’ login cookies. The setup check would report
"cookiesForwarded": true. The edge function forwards only the headers in FORWARD.Does the function cache the script?
Does the function cache the script?
It passes
cache-control and etag back and forwards if-none-match, so browsers cache the script for a day and revalidate it with a 304. See script caching.Does crispstats.id() work behind the proxy?
Does crispstats.id() work behind the proxy?
Yes. It asks
/k3x9qe/id, which the same function forwards.Next steps
Proxy overview
The path, the check, caching, limits and signing.
Content Security Policy
What to allow once the script is first-party.
Ad blockers
What a proxy recovers and what it does not.