Proxying Flowsery Analytics with Caddy

Route Flowsery Analytics through Caddy to prevent adblocker interference and capture more accurate visitor data. Caddy's straightforward configuration makes this particularly easy to set up.

1. Core Caddy Configuration

Add the following directives to your Caddyfile:

your_domain.com {
    # Proxy the analytics script
    handle /js/script.js {
        reverse_proxy https://analytics.flowsery.com {
            header_up Host {upstream_hostport}
            header_up X-Real-IP {remote_host}
            header_up X-Forwarded-For {remote_host}
            header_up X-Forwarded-Proto {scheme}
        }

        # Cache the script for 1 year
        header Cache-Control "public, max-age=31536000"
        header Expires "1y"
    }

    # Proxy the event collection endpoint
    handle /api/events {
        reverse_proxy https://analytics.flowsery.com {
            header_up Host {upstream_hostport}
            header_up X-Real-IP {remote_host}
            header_up X-Forwarded-For {remote_host}
            header_up X-Forwarded-Proto {scheme}
            header_up x-flowsery-ip {remote_host}
        }
    }

    # Your other site directives...
}

Note: If your server already uses an /api/events path, add data-api to the Flowsery Analytics script tag to direct events elsewhere. For example, data-api="/flowsery-events" sends data to /flowsery-events instead.

Important: If every visitor appears to be in the same location in your dashboard, confirm that the x-flowsery-ip header is set to the real visitor IP (not the proxy server IP) when forwarding requests to the Flowsery Analytics /events endpoint.

2. Optional: Enable Caching

For better performance, you can add a caching layer:

your_domain.com {
    # Cache settings
    cache {
        path /var/cache/caddy
        ttl 1y
        capacity 10GB
    }

    handle /js/script.js {
        cache
        reverse_proxy https://analytics.flowsery.com {
            header_up Host {upstream_hostport}
            header_up X-Real-IP {remote_host}
            header_up X-Forwarded-For {remote_host}
            header_up X-Forwarded-Proto {scheme}
        }

        header Cache-Control "public, max-age=31536000"
        header Expires "1y"
    }

    # ... remainder of the configuration
}

3. Modify the Script Tag

Replace the original Flowsery Analytics snippet with the proxied version:

<script defer data-fl-website-id="flid_******" data-domain="your_domain.com" src="/js/script.js"></script>

4. Reload Caddy

# Validate the configuration
caddy validate

# If validation passes, reload Caddy
caddy reload

Confirming It Works

To validate that the proxy is functioning correctly:

  1. Navigate to your website
  2. Open your browser's developer tools and switch to the Network tab
  3. Verify that analytics requests are served from your domain rather than analytics.flowsery.com

Caddy manages HTTPS certificates and HTTP/2 automatically, making it a solid choice for proxying analytics. Confirm that your Caddy server has sufficient disk space if you enable the cache configuration.

Troubleshooting

Every visitor appears from the same location

When all visitors show a single geographic location (typically your server's region), the proxy is not forwarding real visitor IPs correctly.

Resolution:

  1. Ensure your proxy includes the x-flowsery-ip header containing the actual visitor IP address (not the server IP) when forwarding requests to the Flowsery Analytics /events endpoint