Hosts
CrispStats on Netlify: install and proxy
To use CrispStats on Netlify, add the script tag to the head of your pages, either in your code or with Netlify's snippet injection setting, and deploy. To count visitors whose ad blocker stops analytics hosts, add one edge function that forwards a path such as /k3x9qe/* to the collector with only safe headers, the visitor's address and their location.
Updated
Set up CrispStats on Netlify
- 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 layout or HTML files. This is the most reliable route, because it covers every page however Netlify serves it.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> - 02
Step 2: Or paste it with snippet injection
Without touching code, open Project configuration, Developer settings, Post processing, find Snippet Injection, select Add Snippet, paste the tag, choose to insert it before
</head>and select Save. Netlify injects it at once, with no redeploy. Netlify’s help page states no plan restriction for it. It says snippets are injected when pages are served, and not on server-rendered pages, routes handled by functions or proxy routes, so those pages need the tag in code. - 03
Step 3: Add the proxy edge function
Under Settings, Tracking code, Proxy through your own domain, the dashboard proposes a path for your site. Save this function with that path. The
configexport at the end sets the path it runs on. Use it rather than a_redirectsproxy rule, which copies every request header, including your visitors’ login cookies.netlify/edge-functions/crispstats.ts// Forwards /k3x9qe/* to the collector. Sends only the headers below:// never your visitors' cookies or authorization.import type { Config, Context } from "@netlify/edge-functions";const PREFIX = "/k3x9qe/";const UPSTREAM = "https:/ / in. crispstats. com/ p/ ";const FORWARD = ["content-type", "user-agent", "accept-language", "referer", "origin", "if-none-match"];const RETURN = ["content-type", "cache-control", "etag", "access-control-allow-origin"];export default async (request: Request, context: Context) => {const url = new URL(request.url);const headers = new Headers();for (const name of FORWARD) {const value = request. headers. get( name);if (value) headers.set(name, value);}headers. set( "x-forwarded-for", context.ip);if ( context. geo. country? . code) headers. set( "x-crispstats-country", context. geo. country. code);if ( context. geo. subdivision? . code) headers. set( "x-crispstats-region", context. geo. subdivision. code);if (context.geo.city) headers. set( "x-crispstats-city", encodeURIComponent( context. geo. city));const secret = Netlify. env. get( "CRISPSTATS_PROXY_SECRET");if (secret) headers. set( "x-crispstats-proxy-secret", secret);const upstream = await fetch(UPSTREAM + url. pathname. slice( PREFIX. length) + url.search, {method: request.method,headers,body: request.method === "POST" ? await request.arrayBuffer() : undefined,});const out = new Headers();for (const name of RETURN) {const value = upstream. headers. get( name);if (value) out.set(name, value);}return new Response(upstream.body, { status: upstream.status, headers: out });};export const config: Config = { path: "/k3x9qe/*" }; - 04
Step 4: Point the script tag at the path
Replace the tag, in code or in the snippet.
data-apiis required: without it the script sends events to/eon 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> - 05
Step 5: Sign the requests (optional)
Reveal the proxy secret (
cs_px_…) under Advanced: sign proxied requests, add it asCRISPSTATS_PROXY_SECRETin the site’s environment variables and redeploy. The function reads it withNetlify.env.getand sends it when it is set.
Check that it works
Deploy, then 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 "visitorAddressForwarded": true, "cookiesForwarded": false and "location": { "source": "proxy" }. In the network panel, /k3x9qe/d.js loads with 200 or 304 and the POST to /k3x9qe/e answers 202. Your visit appears on Realtime within seconds.
CrispStats on Netlify
What you get
- Pageviews, visitors, sources and channels for your production domain, with no cookies set on the visitor’s device.
- Visitors whose ad blocker stops analytics hosts, counted again once the edge function is live.
- Country, region and city from Netlify’s
context.geo, instead of a country guessed from the browser’s timezone. - Revenue attribution through the proxy:
crispstats.id()asks/k3x9qe/id, which the same function forwards. - A core script of about 2.2 KB gzipped, cached by browsers for a day and revalidated with a
304.
Notes and limits
- Deploy previews on
*.netlify.appsend nothing, becausedata-domainslists only your real domain. Add a preview hostname only if you want those visits counted. - A
_redirectsrule with status 200 is a plain proxy: the setup check would report"cookiesForwarded": true. The edge function forwards only the headers inFORWARD. - The function passes
context.ipasx-forwarded-for. The collector uses it for the daily visitor hash and your excluded IP addresses, then discards it. - A blocker that lists your own path can still stop it. A path unique to your site makes that unlikely.
- Deploy previews on
The docs page covers the optional steps this guide leaves out.
Setup questions. Straight answers.
What people ask before they connect it.
Use snippet injection under Project configuration, Developer settings, Post processing, and insert the tag before the closing head tag. Netlify says it does not reach server-rendered pages or routes handled by functions.
A proxy rule copies every request header to the collector, including your visitors' login cookies. The edge function picks the headers itself and adds the visitor's address and location.
It passes cache-control and etag back and forwards if-none-match, so browsers keep the script for a day and then revalidate it with a 304.
Yes. Every CrispStats feature is on every plan and in the 14-day free trial. Netlify's own limits and pricing for edge functions apply to your site.
Not answered here? Write to hello@crispstats.com
Go further
Related
- Ad blockers and analytics
An ad blocker stops ads and trackers from loading in the browser.
- Cookieless analytics explained
How cookieless analytics counts unique visitors with a daily rotating hash instead of a cookie, what it can and cannot tell you, and the trade-offs.
- Plain HTML install
Add CrispStats to a static or hand-written HTML site with one script tag in the head of every page.
- Revenue attribution
See which source, page and campaign each payment came from.
- Proxy on Vercel
Add CrispStats to a site hosted on Vercel, then serve it from your own domain with one route in vercel.json that strips cookies before forwarding.
- Proxy with a Cloudflare Worker
Serve CrispStats from your own domain with a Cloudflare Worker on one route, so visitors behind ad blockers are counted.
Other integrations
Hosts
Frameworks
Site builders
Ecommerce platforms
Tag managers
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.