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';
}
}));
// 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 hereImportant: If you notice all visitors showing from the same location in your analytics, use the managed proxy for automatic visitor IP handling, or review your proxy provider's forwarding settings.
3. Update Your Script Tag
Replace your existing DataFast script with the proxied version:
<script
defer
data-website-id="dfid_******"
data-domain="your_domain.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:
- 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
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:
- Use the managed proxy for automatic visitor IP handling, or review your proxy provider's forwarding settings.