Skip to content
Tools and automation

NGINX analytics proxy and snippet injection

2 min read · Updated · By the Reveata team

Short answerNGINX can insert the Reveata snippet into every HTML page with sub_filter, and proxy the script and events through two locations on your own domain. With your website's proxy secret, Reveata trusts the visitor's address NGINX forwards, so locations stay accurate.

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.js on 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

  1. Create a proxy secret in Reveata (Settings → General → Tracking code). It starts with dt_proxy_ and is shown once.
  2. Store it in a root-only file at the http level, 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.
  3. Add the two locations, point the snippet at them, test with nginx -t and 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.

Frequently asked questions

What happens if I proxy without the secret?

Every visit looks as if it came from your server: countries, IP exclusions and per-visitor limits stop working, and in cookieless mode all visitors look alike.

Can I cache the event endpoint?

Never cache /dt/event. The script itself may be cached; Reveata sends the right Cache-Control.

I don't have server access. What then?

The managed proxy does the same with one DNS record.

See it with your own numbersReveata ties every visit and sale to the source that brought it. Add your website in a minute.
Get started
Was this page useful?
IntegrationCaddy analytics proxy for ReveataTwo handle routes in your Caddyfile serve the Reveata script and pass events on from your own domain, with your proxy secret taken from Caddy's environment. If you can't edit the pages, the replace-response plugin can insert the snippet into every HTML response.IntegrationConnect ChatGPT to your website analyticsAdd Reveata in ChatGPT's Apps and Connectors settings, or create it in developer mode with Reveata's MCP server address and OAuth. You pick which websites to share, and ChatGPT answers questions about traffic, revenue, goals and funnels with cards and charts, reading only.IntegrationConnect Claude to your analytics with MCPAdd Reveata as a connector in Claude's settings, or with one command in Claude Code, and sign in through Reveata to choose websites and permissions. Claude then reads your analytics through Reveata's MCP server and shows inline cards for overviews, rankings, realtime, goals and funnels.IntegrationDiscord alerts for website traffic and revenueCreate a webhook in a Discord channel's Integrations settings, paste its URL into a Reveata alert, and Reveata posts to that channel when the alert fires. Posts never ping anyone, even if your message contains @everyone.IntegrationGemini CLI with Reveata analyticsRun gemini mcp add with Reveata's server URL, start gemini and run /mcp auth reveata. Reveata opens in your browser to choose websites and permissions, and Gemini CLI can then answer questions about your analytics.IntegrationGitHub commits on your analytics chartConnect a GitHub repository and Reveata imports the last 90 days of commits on its default branch, then adds new ones within seconds through a push webhook. Each day with commits gets a marker on your main chart, so you can see what shipped when traffic or revenue moved.