Install DataPocket on Caddy

Updated

A single handle block. Caddy sets X-Forwarded-For for you. Sign in and these snippets fill in your site ID and domain. Until then, swap YOUR_SITE_ID and YOUR_DOMAIN with the values from your Install page.

  1. 1

    In your site block of the Caddyfile:

    caddy
    @datapocket path_regexp ^/dp/(js/script(\.[a-z]+)?(@\d+\.\d+\.\d+)?\.js|api/event)$
    handle @datapocket {
        uri strip_prefix /dp
        reverse_proxy https://datapocket.vo1d.studio {
            header_up Host {upstream_hostport}
            header_up -Cookie
            header_up -Authorization
            header_down -Set-Cookie
        }
    }
  2. 2

    Then load the script from your own domain. Ad blockers can't tell it apart from your own code, so visits from people whose ad blocker blocks analytics domains are still counted:

    html
    <script
      defer
      data-site-id="YOUR_SITE_ID"
      data-domain="YOUR_DOMAIN"
      src="/dp/js/script.js"
    ></script>
  3. 3

    Behind Cloudflare or a load balancer? Add `servers { trusted_proxies static private_ranges }` (or Cloudflare's ranges) to the global options so the visitor's IP, not the balancer's, is forwarded.

Related guides

Install DataPocket on Caddy · DataPocket