Support/Proxy Guides
Proxy Guides

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

Terminal
npm install express-http-proxy

2. Set Up the Proxy

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

JavaScript
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/main.js',
  proxy('analytics.flowsery.com', {
    https: true,
    proxyReqPathResolver: function (req) {
      return '/js/main.js';
    },
  })
);
 
// Proxy the event collection endpoint + forward real visitor IP
app.use(
  '/api/track',
  proxy('analytics.flowsery.com', {
    https: true,
    proxyReqPathResolver: function (req) {
      return '/analytics/events';
    },
    proxyReqOptDecorator: function (proxyReqOpts, srcReq) {
      // Determine the real visitor IP. Use whichever header your edge provides.
      const clientIp =
        srcReq.headers['cf-connecting-ip'] || srcReq.headers['x-real-ip'] || srcReq.headers['x-forwarded-for']?.split(',')[0]?.trim() || srcReq.ip;
 
      // CRITICAL: Flowsery reads `x-flowsery-real-ip` as the authoritative
      // visitor IP. Without it, every visitor resolves to your server's
      // region because the proxy hop rewrites `cf-connecting-ip`.
      if (clientIp) {
        proxyReqOpts.headers['x-flowsery-real-ip'] = clientIp;
      }
 
      return proxyReqOpts;
    },
  })
);
 
// Your other routes...
app.listen(3000);

Note: If your app already uses /api/track, 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 x-flowsery-real-ip is set to the real visitor IP (not the proxy server's 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:

HTML
<script defer data-fl-website-id="flid_******" src="/js/main.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 sets x-flowsery-real-ip to the actual visitor IP (not the server IP) when forwarding requests to the Flowsery Analytics /events endpoint.
  2. If Express sits behind another proxy (Nginx, Cloudflare, etc.), srcReq.ip is that upstream proxy, not the visitor. Read cf-connecting-ip / x-real-ip directly instead, as shown in step 2.