Proxy
Proxy with Caddy
Two handle blocks rewrite your paths and reverse-proxy them to MetricRaven.
Set it up
Add a reusable snippet
Caddyfile# Top of the same Caddyfile, outside any site block (metricraven_upstream) { header_up Host {upstream_hostport} # The visitor's IP. Behind a CDN or load balancer, set trusted_proxies first. header_up X-Visitor-IP {client_ip} header_up -Cookie header_up -Authorization header_up -Referer }Add the handlers to your site block
Replace
example.comwith your existing site address and keep your current directives below the two handlers.Caddyfile# Caddyfile · Caddy 2.7 or later example.com { @metricravenScript { method GET path /a/script } handle @metricravenScript { rewrite * /js/script.js reverse_proxy https://metricraven.com { import metricraven_upstream header_down Cache-Control "public, max-age=3600" } } @metricravenEvent { method POST path /a/event } handle @metricravenEvent { rewrite * /api/v1/collect reverse_proxy https://metricraven.com { import metricraven_upstream header_down Cache-Control "no-store" } } # ...your existing site configuration }Reload Caddy
terminalcaddy reload --config /etc/caddy/CaddyfilePoint your script tag at your own paths
Replace your MetricRaven tag with this one.
srcloads the tracker from your domain anddata-apisends its events there too.Your website's shared layout<script defer src="/a/script" data-api="/a/event" data-site-id="YOUR_SITE_ID"></script>
Verify it works
Open your live site. In the browser's Network panel, /a/script loads the tracker and /a/event answers with ok: true. Nothing goes to metricraven.com from the browser.
In Traffic, your own visit should show your real country and city. If every visit appears to come from your server's or host's location, the visitor IP isn't being forwarded.
Notes
{client_ip}needs Caddy 2.7 or later. Behind a CDN or load balancer, settrusted_proxiesin the globalserversoptions so it is the visitor, not the proxy.header_up Host {upstream_hostport}is required for an HTTPS upstream; without it the request reaches MetricRaven with your site's hostname and fails.
How the proxy works and which headers it must send: Use your own domain.
Details
- The proxy forwards only
Content-Type,Origin,User-Agentand the visitor's IP asx-visitor-ip. Your site's cookies and auth headers never leave your server. Originmatters: MetricRaven checks it against your site's allowed domains. A missing or wrong origin is refused withdomain_not_allowed.- MetricRaven allows about 120 events per minute per visitor IP. Without
x-visitor-ip, all of your visitors share the proxy's IP, so busy sites lose events as well as locations. - A proxy doesn't guarantee that every blocker will allow tracking.