Proxy DataFast with Express.js

Learn how to proxy DataFast analytics through your Express.js server to bypass adblockers and improve accuracy.

1. Install Required Dependencies

npm install express-http-proxy

2. Add Proxy Configuration

Add the following to your Express.js application:

const express = require('express');
const proxy = require('express-http-proxy');
const app = express();

app.set('trust proxy', true);

// Proxy the script
app.use('/js/script.js', proxy('datafa.st', {
  https: true,
  proxyReqPathResolver: function (req) {
    return '/js/script.js';
  }
}));

// Proxy the events endpoint
app.use('/api/events', proxy('datafa.st', {
  https: true,
  proxyReqPathResolver: function (req) {
    return '/api/events';
  },
  proxyReqOptDecorator: function(proxyReqOpts, srcReq) {
    return proxyReqOpts;
  }
}));

// Your other routes...
app.listen(3000);

Note: 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

3. Update Your Script Tag

Replace your existing DataFast script with the proxied version:

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

4. Deploy your server

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 ✍️