The visitor's IP address

Docs·Proxy guide

Proxy with Caddy

Two handle_path blocks in your site's Caddyfile serve Spreelytics from /sp/. This guide uses /sp/. Any path works if nothing else on your site uses it and it doesn't contain words like "analytics" or "tracking", which blockers look for.

Add the blocks

Add these inside your site's block in the Caddyfile, then reload Caddy:

# The script files.
handle_path /sp/js/* {
    rewrite * /cdn/sdk{path}
    reverse_proxy https://cdn.spreelytics.com {
        header_up Host cdn.spreelytics.com
        header_up -Cookie
    }
}

# Everything else: the tracking requests. Caddy adds X-Forwarded-For itself.
handle_path /sp/* {
    rewrite * /1.0{path}
    reverse_proxy https://sdk.spreelytics.com {
        header_up Host sdk.spreelytics.com
        header_up -Cookie
    }
}

Point the script at your proxy

In your Spreelytics snippet, load the script through /sp/js/ and add api_host:

<script src="/sp/js/spreelytics-loader.js"></script>
<script>
  Spreelytics.init({
    client_key: "YOUR_CLIENT_KEY",
    api_host: "https://www.example.com/sp",
  });
</script>

Check it works

Open your site with the browser's Network tab open and filtered by /sp/. The script files and requests like track/page should come from your own domain, with status 200. In Spreelytics, Settings → Tracking script says "Last seen just now" and Realtime shows you in your own country.

  • Wrong country, or 200 and nothing arrives: the proxy isn't passing the visitor's IP address in X-Forwarded-For. See The visitor's IP address below.
  • 401: the Origin and Referer headers didn't arrive, or your domain isn't in Allowed domains.

The visitor's IP address

Caddy sets X-Forwarded-For to the address it sees. If Cloudflare or a load balancer sits in front of Caddy, list it in the trusted_proxies global option, or every visitor arrives from its address.

See your own numbers today.

Free up to 1M events a month · no credit card

Contact

Tell us what you need.

A real person reads these. We usually reply within one working day.

Or email us directly at contact@spreelytics.com.