---
title: "Install DataPocket on Caddy"
description: "Add DataPocket web analytics with revenue attribution to Caddy. A single handle block. Caddy sets X-Forwarded-For for you."
url: "https://datapocket.vo1d.studio/docs/caddy"
lang: "en"
updated: "2026-11-23"
---

# Install DataPocket on Caddy

A single handle block. Caddy sets X-Forwarded-For for you. Replace `YOUR_SITE_ID` and `YOUR_DOMAIN` with the values from your site's Install page. This guide serves the script from your own domain, so ad blockers can't tell it apart from your own code.

## Steps

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

## Verify

1. Deploy or publish, then open your site in a normal browser window (ad blockers off).
2. In the browser's Network tab, look for a POST to `/api/event` (or `/dp/api/event` when proxied) that returns `{"ok":true}`.
3. The DataPocket Install page for this site switches to "Receiving data" within a few seconds.

## Related guides

- [Next.js](https://datapocket.vo1d.studio/docs/nextjs): App Router or Pages Router. Client-side navigations are tracked automatically.
- [Astro](https://datapocket.vo1d.studio/docs/astro): Static or server-rendered. Navigations with <ClientRouter /> (view transitions) are tracked automatically.
- [React Router](https://datapocket.vo1d.studio/docs/react-router): Framework mode (Remix) and library mode. pushState navigations are tracked automatically.
- [Vue.js](https://datapocket.vo1d.studio/docs/vue): Vue 3 + Vue Router, Nuxt, Vite. History-mode routing is tracked automatically.
- [AI crawler tracking](https://datapocket.vo1d.studio/docs/ai-bots)
