NGINX sits in front of a lot of sites: static builds, Django and Laravel apps, self-hosted Ghost. That position lets it do two jobs for Reveata without touching your application code.
What you get
- Tracking on pages you can't edit, by adding the snippet to every HTML response on its way out.
- A first-party script address, such as
/dt/script.json your own domain, so fewer visits are lost to ad blockers. - Accurate visitor locations through the proxy, because NGINX sends the visitor's address with your proxy secret.
- A Content Security Policy that stays simple: with the proxy,
'self'covers the script and events.
Injecting the snippet with sub_filter
NGINX's sub module (opens in a new tab) replaces text in responses. Two sub_filter lines in the location that serves your pages insert the snippet before </head>. It only changes text/html responses by default. If that location uses proxy_pass and your app compresses responses, add proxy_set_header Accept-Encoding "";, because NGINX can only replace text it receives uncompressed. The exact lines are in the NGINX install guide.
Proxying the script and events
- Create a proxy secret in Reveata (Settings → General → Tracking code). It starts with
dt_proxy_and is shown once. - Store it in a root-only file at the
httplevel, for example/etc/nginx/conf.d/reveata.conf, since NGINX doesn't read environment variables in its config. With the official Docker image, a template file can fill it from an environment variable. - Add the two locations, point the snippet at them, test with
nginx -tand reload.
Behind a load balancer or CDN such as Cloudflare, use the realip module so $remote_addr becomes the visitor's address.
Checking it works
| Check | Good result |
|---|---|
Open /dt/script.js on your site |
The script loads |
The /dt/event request in the Network tab |
Response header x-reveata-proxy: trusted |
| Realtime in Reveata | Your own city, not your server's |
proxy_secret_invalid means the secret is missing, mistyped or rotated.
Revenue
NGINX only serves pages; payments come from your provider or app. Connect your provider and pass the visitor id at checkout from your framework, for example Django, Laravel or Express.