Skip to content

Caddy proxy

Why a proxy? It loads the PureMetrix script and sends its data via your own domain, so ad blockers block it less often. Here is how to set it up with Caddy.

What you configure

Template reference: adapters/proxy/Caddyfile.

Use the reverse_proxy blocks in adapters/proxy/Caddyfile for /px/js/* and /px/event.

Reload Caddy and check that events reach PureMetrix.

What the snippet looks like

<script defer data-domain="example.com" data-key="YOUR_PUBLIC_KEY"
  src="https://www.example.com/px/js/script.js"></script>

Copy your public key in PureMetrix under Site settings → General. Once the proxy works, pageviews appear as usual in app.puremetrix.org.

Troubleshooting

  • Error 403 or 404 on /px: a firewall is blocking the path, or the rewrite rule is missing.
  • Requests are sent but no stats appear: check that the public key and domain match your Site settings.
  • Wrong country or city: make sure X-Forwarded-For (the visitor’s original IP address) is passed on exactly once.

Related