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 Rewrites Configuration

Create or update your next.config.js file in your project root:

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",
      },
    ];
  },
};

Next.js will automatically proxy both the script and events endpoint with proper IP forwarding.

If you already have an /api/events API endpoint, add data-api-url to the DataFast script tag to send events to your own API endpoint. For example, data-api-url="/datafast-events" will send events to /datafast-events instead of /api/events. Read more here

2. Update Your Script Tag

Replace your existing DataFast script with the proxied version:

<Script
  strategy="afterInteractive"
  data-website-id="dfid_******"
  data-domain="yourdomain.com"
  src="/js/script.js"
></Script>

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

Troubleshooting

All visitors showing from the same location

If your analytics show all visitors from a single location (usually your server's location), your proxy isn't forwarding visitor IPs.

To fix:

  1. Verify your proxy sends x-real-ip or x-forwarded-for headers with the client IP
  2. If the issue persists, contact support with your proxy configuration
Something missing? Suggest features ✍️