Proxying Flowsery Analytics with DigitalOcean

Route Flowsery Analytics through DigitalOcean to prevent adblocker interference and capture more accurate visitor data. This guide covers both App Platform and Droplet-based setups.

Option 1: DigitalOcean App Platform

If you are running on DigitalOcean App Platform with Node.js, refer to the framework-specific guide that matches your stack:

App Platform automatically handles IP forwarding via the X-Forwarded-For header, so the configurations in those guides work without modification.

Option 2: DigitalOcean Droplet with Nginx

If you are running a DigitalOcean Droplet with Nginx as your web server or reverse proxy, use the following configuration.

1. Connect to Your Droplet

ssh root@your-droplet-ip

2. Open the Nginx Configuration

Edit the site configuration file (usually at /etc/nginx/sites-available/your-site):

sudo nano /etc/nginx/sites-available/your-site

3. Add the Proxy Location Blocks

Insert the following location blocks into your server configuration:

server {
    listen 80;
    server_name your_domain.com;

    # Your existing configuration...

    # 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
        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;

        # Allow POST requests
        proxy_method POST;
        proxy_pass_request_body on;
    }

    # Your other location blocks...
}

Note: If you already have an /api/events location block, add data-api to the Flowsery Analytics script tag to redirect events. For example, data-api="/flowsery-events" sends data to /flowsery-events instead.

4. Test and Reload Nginx

Validate the configuration for syntax errors:

sudo nginx -t

If the test passes, reload Nginx:

sudo systemctl reload nginx

5. Optional: Enable Caching

For improved performance, configure an Nginx cache zone:

# Place this outside the server block (typically at the top of nginx.conf)
proxy_cache_path /var/cache/nginx/flowsery_cache
    levels=1:2
    keys_zone=flowsery_cache:10m
    max_size=100m
    inactive=60m
    use_temp_path=off;

# In your server block, update the script location
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;

    proxy_pass https://analytics.flowsery.com/js/script.js;
    proxy_set_header Host analytics.flowsery.com;

    add_header Cache-Control "public, max-age=31536000";
    expires 1y;
}

Option 3: DigitalOcean Spaces CDN

If you are using DigitalOcean Spaces CDN in front of your Droplet, ensure it forwards client IPs properly:

  1. In the DigitalOcean dashboard, navigate to Networking > CDN
  2. Confirm that your CDN is configured to pass through request headers
  3. The CDN automatically adds X-Forwarded-For headers
  4. Your Nginx configuration will pick up visitor IPs from those headers

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>

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
  4. Check your Flowsery Analytics dashboard to confirm visitor locations are displayed accurately

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