Proxying Flowsery Analytics with Express.js

Route Flowsery Analytics through your Express.js server to prevent adblocker interference and capture more accurate visitor data.

1. Install Dependencies

npm install express-http-proxy

2. Set Up the Proxy

Add the following proxy configuration to your Express.js app:

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

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

// Proxy the tracking script
app.use(
  '/js/script.js',
  proxy('analytics.flowsery.com', {
    https: true,
    proxyReqPathResolver: function (req) {
      return '/js/script.js';
    },
  })
);

// Proxy the event collection endpoint
app.use(
  '/api/events',
  proxy('analytics.flowsery.com', {
    https: true,
    proxyReqPathResolver: function (req) {
      return '/events';
    },
    proxyReqOptDecorator: function (proxyReqOpts, srcReq) {
      // Determine the real visitor IP
      const clientIp = srcReq.headers['x-real-ip'] || srcReq.headers['x-forwarded-for']?.split(',')[0]?.trim() || srcReq.ip;

      // Attach the x-flowsery-ip header for correct geolocation
      proxyReqOpts.headers['x-flowsery-ip'] = clientIp;

      return proxyReqOpts;
    },
  })
);

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

Note: If your app already uses /api/events, add data-api to the Flowsery Analytics script tag to redirect events elsewhere. For example, data-api="/flowsery-events" sends data to /flowsery-events instead.

Important: If every visitor appears to be in the same location in your dashboard, confirm that the x-flowsery-ip header is being set to the real visitor IP (not the proxy server IP) when forwarding requests to the Flowsery Analytics /events endpoint.

3. Modify the Script Tag

Replace the original Flowsery Analytics snippet with the proxied version:

<script defer data-fl-website-id="flid_******" data-domain="your_domain.com" src="/js/script.js"></script>

4. Deploy

After deploying your server, the proxy configuration activates automatically.

Confirming It Works

To validate that the proxy is functioning correctly:

  1. Navigate to your website
  2. Open your browser's developer tools and switch to the Network tab
  3. Verify that analytics requests are served from your domain rather than analytics.flowsery.com

Troubleshooting

Every visitor appears from the same location

When all visitors show a single geographic location (typically your server's region), the proxy is not forwarding real visitor IPs correctly.

Resolution:

  1. Ensure your proxy includes the x-flowsery-ip header containing the actual visitor IP address (not the server IP) when forwarding requests to the Flowsery Analytics /events endpoint