Proxying Flowsery Analytics with Nginx

Route Flowsery Analytics through Nginx to prevent adblocker interference and capture more accurate visitor data. This guide applies to both standalone Nginx setups and Nginx as a reverse proxy in front of an application server.

1. Core Nginx Configuration

Add these location blocks to your Nginx config (typically in /etc/nginx/sites-available/your-site or /etc/nginx/conf.d/your-site.conf):

# Proxy the analytics script
location /js/script.js {
    proxy_pass https://analytics.flowsery.com/js/script.js;
    proxy_set_header Host analytics.flowsery.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    # Cache the script for 1 year
    proxy_cache_valid 200 1y;
    add_header Cache-Control "public, max-age=31536000";
    expires 1y;
}

# Proxy the event collection endpoint
location /api/events {
    proxy_pass https://analytics.flowsery.com/events;
    proxy_set_header Host analytics.flowsery.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header x-flowsery-ip $remote_addr;

    # Allow POST requests
    proxy_method POST;
    proxy_pass_request_body on;
}

Note: If your server already uses an /api/events location block, add data-api to the Flowsery Analytics script tag to route events to a different path. 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 set to the real visitor IP (not the proxy server IP) when forwarding requests to the Flowsery Analytics /events endpoint.

2. Optional: Enable Caching

For improved performance, configure an Nginx cache zone:

# Define cache zone
proxy_cache_path /var/cache/nginx/flowsery_cache levels=1:2 keys_zone=flowsery_cache:10m max_size=10g inactive=60m use_temp_path=off;

# In your server block
location /js/script.js {
    proxy_cache flowsery_cache;
    proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
    proxy_cache_valid 200 1y;
    proxy_cache_bypass $http_pragma;
    proxy_cache_revalidate on;

    # ... remainder of the configuration from step 1
}

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. Test and Reload Nginx

# Validate the configuration
sudo nginx -t

# If validation passes, reload Nginx
sudo systemctl reload nginx

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