Proxy DataFast with Caddy
Learn how to proxy DataFast analytics through Caddy to bypass adblockers and improve accuracy. Caddy's simple configuration makes it easy to set up.
1. Basic Caddy Configuration
Add the following to your Caddyfile
:
yourdomain.com { # Proxy the analytics script handle /js/script.js { reverse_proxy https://datafa.st { 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 events endpoint handle /api/events { reverse_proxy https://datafa.st { 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} } } # Your other site configurations... }
2. Optional: Add Caching Configuration
For better performance, you can add caching:
yourdomain.com { # Cache configuration cache { path /var/cache/caddy ttl 1y capacity 10GB } handle /js/script.js { cache reverse_proxy https://datafa.st { 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" } # ... rest of the configuration }
3. Update Your Script Tag
Replace your existing DataFast script with the proxied version:
<script
defer
data-website-id="yourwebsiteid"
data-domain="yourdomain.com"
src="/js/script.js"
></script>
4. Reload Caddy
# Test the configuration
caddy validate
# If the test is successful, reload Caddy
caddy reload
Verification
To verify the proxy is working:
- Visit your website
- Open the network tab in your browser's developer tools
- Check that analytics requests are going through your domain instead of datafa.st