analytics, track or collect. With a reverse proxy, the browser talks only to your own site, and your site forwards the requests to the collector.
What to proxy
The SDK sends only
POST <endpoint>/v0/events. It removes one trailing / from the endpoint and appends /v0/events. So data-endpoint="https://yourdomain.com/ua" posts to https://yourdomain.com/ua/v0/events. Proxy that exact path, not the whole API. An npm install bundles the SDK, so it needs only the events path.
Change your snippet to:
endpoint: '/ua' or endpoint: 'https://yourdomain.com/ua'.
Choose a neutral path
Filter lists match URL substrings. Avoid/analytics.js, /track, /collect, /tracking, /stats and the collector host name. Use a short neutral prefix such as /ua, or a name from your own app. The /v0/events suffix is fixed.
Subresource Integrity
If your snippet hasintegrity="sha384-...", the browser checks the hash against the bytes it receives. A proxy that forwards the same pinned file unchanged keeps the same hash. It fails if the proxy points at a different or unpinned build, or changes the file. Keep crossorigin="anonymous".
Headers to forward
The collector does not read
Host, so it can be any value. If the proxy drops Origin, the Publishable key and the page URL domain check still apply.
Examples
Replacehttps://YOUR_COLLECTOR_ENDPOINT with your collector URL and SCRIPT_URL with the src from your setup page.
- Next.js rewrites
- Next.js proxy.ts
- Vercel
- Cloudflare Worker
- nginx
X-Forwarded-For. The collector looks up the country from it.Verify
- Load your site with the browser developer tools open.
- Confirm that the script loads from
/ua.jsand thatPOST /ua/v0/eventsreturns202. - Confirm that no request goes to the collector host or the CDN.
- Open Activity. Your events appear with the visitor’s country, not
ZZ(unknown) or the proxy’s country.