Caddy proxy

Proxy the attribu.tech script and API through Caddy.

This is a server-specific guide. See Proxy the tracking script for an overview of why and how proxying works.

Caddyfile configuration

Add these handle blocks to your Caddyfile:

yourdomain.com {
    # Proxy the attribu.tech tracking script
    handle /js/attribu.js {
        rewrite * /js/script.js
        reverse_proxy https://attribu.tech {
            header_up Host attribu.tech
        }
    }

    # Proxy the attribu.tech event API
    handle /api/proxy/events {
        rewrite * /api/events
        reverse_proxy https://attribu.tech {
            header_up Host attribu.tech
        }
    }

    # Your existing site config below
    # ...
}

Reload Caddy after saving the Caddyfile:

sudo systemctl reload caddy

Update your script tag

Point the script src to your proxied path and set data-api-url to your proxied API endpoint:

<script
  defer
  data-website-id="YOUR_SITE_ID"
  data-domain="yourdomain.com"
  data-api-url="https://yourdomain.com/api/proxy/events"
  src="/js/attribu.js"
></script>
Replace YOUR_SITE_ID with your actual Website ID from attribu.tech. Replace yourdomain.com with your website's root domain.

Verify installation

  1. Visit your site in an incognito/private window.
  2. Open your browser's Developer Tools and go to the Network tab.
  3. Confirm the script loads from /js/attribu.js on your domain.
  4. Confirm the pageview POST goes to /api/proxy/events on your domain.
  5. Check your attribu.tech dashboard. A new pageview should appear within a few seconds.

What's next

Copied