Proxy
Ad blockers and privacy browsers can drop analytics requests. Serve the SDK and send events through your own domain with a reverse proxy. The browser then talks only to your site.
What to proxy
| Request | Upstream | Your path (example) |
|---|---|---|
Events (POST) | Your collector URL plus /v0/events, for example https://api.example.com/v0/events | /mana/v0/events |
| SDK script (script installs only) | The script src from your project setup page: the pinned jsDelivr build or the dashboard's /sdk.js | /mana.js |
The SDK removes a trailing slash from the endpoint and appends /v0/events. So an endpoint of https://yourdomain.com/ua posts to https://yourdomain.com/mana/v0/events. npm installs bundle the SDK and need only the events path.
Choose path names
Filter lists match URL substrings. Do not use paths such as /analytics.js, /track, /collect, /tracking, or /stats, and do not put the collector host in the path. Use a short neutral prefix such as /ua or a name from your own app. The /v0/events suffix is fixed by the SDK.
Change the snippet
<script src="https://yourdomain.com/mana.js"
integrity="sha384-..." crossorigin="anonymous"
data-publishable-key="YOUR_PUBLISHABLE_KEY"
data-endpoint="https://yourdomain.com/mana"
defer></script>Keep the integrity and crossorigin attributes from your setup page. The integrity check still passes when the proxy forwards the same pinned file unchanged. It fails if the proxy points at a different or unpinned build, or if you host a copy that is not byte-identical. For npm installs, change only the endpoint:
const analytics = createAnalytics({
publishableKey: 'YOUR_PUBLISHABLE_KEY',
endpoint: '/mana', // posts to /mana/v0/events on your own site
});Next.js rewrites
// next.config.js
module.exports = {
async rewrites() {
return [
// Script installs only; skip for npm installs.
{ source: '/mana.js', destination: 'https://cdn.jsdelivr.net/npm/@manalens/web@0.1.0/dist/snippet.global.js' },
{ source: '/mana/v0/events', destination: 'https://api.example.com/v0/events' },
];
},
};The rewrite forwards the visitor IP in X-Forwarded-For. The collector looks up the country from that IP, so no country header is needed.
Next.js 16 proxy.ts
Next.js 16 renamed Middleware to Proxy: the file is proxy.ts and the function is proxy. If your app already has a proxy.ts, add this branch to it.
// proxy.ts (next to app/). Next.js 15 and older: middleware.ts and middleware().
import { NextResponse, type NextRequest } from 'next/server';
const COLLECTOR = 'https://api.example.com';
export function proxy(request: NextRequest) {
const headers = new Headers(request.headers);
headers.set('host', new URL(COLLECTOR).host);
const country = request.headers.get('x-vercel-ip-country');
if (country) headers.set('x-visitor-country', country);
return NextResponse.rewrite(new URL('/v0/events', COLLECTOR), { request: { headers } });
}
export const config = { matcher: '/mana/v0/events' };Vercel rewrites (any framework)
Add this to vercel.json.
{
"rewrites": [
{ "source": "/mana.js", "destination": "https://cdn.jsdelivr.net/npm/@manalens/web@0.1.0/dist/snippet.global.js" },
{ "source": "/mana/v0/events", "destination": "https://api.example.com/v0/events" }
]
}Cloudflare Worker
// Routes: yourdomain.com/mana.js and yourdomain.com/ua/*
const COLLECTOR = 'https://api.example.com';
const SCRIPT = 'https://cdn.jsdelivr.net/npm/@manalens/web@0.1.0/dist/snippet.global.js';
export default {
async fetch(request) {
const url = new URL(request.url);
if (url.pathname === '/mana.js') return fetch(SCRIPT, { cf: { cacheEverything: true, cacheTtl: 3600 } });
if (url.pathname !== '/mana/v0/events') return new Response('Not found', { status: 404 });
const headers = new Headers(request.headers);
headers.set('x-forwarded-for', request.headers.get('cf-connecting-ip') ?? '');
if (request.cf?.country) headers.set('x-visitor-country', String(request.cf.country));
return fetch(COLLECTOR + '/v0/events', { method: request.method, headers, body: request.body });
},
};nginx and other servers
location = /mana.js {
proxy_pass https://cdn.jsdelivr.net/npm/@manalens/web@0.1.0/dist/snippet.global.js;
proxy_ssl_server_name on;
}
location = /mana/v0/events {
proxy_pass https://api.example.com/v0/events;
proxy_ssl_server_name on;
# $remote_addr replaces any value the browser sent.
proxy_set_header X-Forwarded-For $remote_addr;
}Headers to forward
Origin: keep it unchanged. The collector accepts your registered domain and its subdomains. A proxy that dropsOriginalso works; each event's page URL must still be on your domain.X-Forwarded-For: keep it. The collector looks up the visitor's country from the first public IP in it, in memory, and never stores or logs the IP. Most proxies set it by default.X-Visitor-Country: optional. A two-letter country that overrides the IP lookup, for example fromrequest.cf.countryin a Cloudflare Worker.User-Agent,X-Publishable-Key,Content-Type: unchanged.Hostcan be anything.
There is no per-visitor, per-proxy or per-project event rate limit, so all visitors behind your proxy are accepted. The Publishable key, the domain check, schema validation and request size limits still apply.
Verify
- Load your site with the browser developer tools open.
- Confirm that the script loads from
/mana.jsand thatPOST /mana/v0/eventsreturns 202. - Confirm that no request goes to the collector host or jsDelivr.
- Open Activity in the dashboard. Your events appear with the visitor's country.
Country lookup: Cloudflare's published geofeed for Cloudflare addresses (for example WARP), then IP Geolocation by DB-IP.
Frequently asked questions
Why do ad blockers drop analytics requests?
Filter lists block known analytics hosts and URL paths that contain words such as analytics, track, or collect. A request to your own domain on a neutral path does not match those rules.
Does the SRI integrity hash still work through a proxy?
Yes, if the proxy forwards the same pinned file unchanged. The browser checks the hash against the bytes, not the URL. It fails for a different or unpinned build, or a self-hosted copy that is not byte-identical.
Do I need to proxy the whole API?
No. The SDK only sends POST requests to its endpoint plus /v0/events. Proxy that one path and, for script installs, the SDK script.