Proxy DataFast with Next.js

Learn how to proxy DataFast analytics through your own domain using Next.js to bypass adblockers and improve accuracy.

1. Add Configuration File

Create a next.config.js file in your project root (if you don't have one already).

module.exports = {
  async rewrites() {
    return [
      {
        source: '/js/script.js',
        destination: 'https://datafa.st/js/script.js',
      },
      {
        source: '/api/events',
        destination: 'https://datafa.st/api/events',
      },
    ]
  },
}

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

Make sure the src path match exactly what you specified in next.config.js.

3. Deploy your site

The proxy configuration will take effect automatically after deployment.

Verification

To verify the proxy is working:

  1. Visit your website
  2. Open the network tab in your browser's developer tools
  3. Check that analytics requests are going through your domain instead of datafa.st
Something missing? Suggest features ✍️