fivebar

Proxying

Copy page
View Markdown
Open with
Connect MCP
Claude Mistral Vibe Cursor VS Code

Serve the script from your own domain, and content blockers that block fiveb.ar let it through.

A content blocker that knows fiveb.ar hides its users’ visits from your stats. Served from your own domain, the script is part of your site, and those visits count. It’s worth it when many of your visitors use a blocker, as developers do, or when you’d rather your pages loaded nothing from elsewhere. It takes more than the tag alone: your platform’s recipe passes two paths on to fivebar and says who each visitor is, and then you load the script from your own domain.

How it works

Your site answers two paths and passes each on to fivebar:

Your sitePasses on to
GET /js/tally.jshttps://fiveb.ar/js/tally.js
POST /api/tallyhttps://fiveb.ar/api/tally

Then load the script from your own domain. The script sends its counts to the host it was loaded from, so nothing else changes:

<script async data-domain="example.com" src="/js/tally.js"></script>

Proxy those two paths and nothing else: never the dashboard, sign-in or anything else of fivebar’s.

Who the visitor is

Every count now reaches fivebar from your proxy, so your proxy has to say who the visitor is, in headers. Otherwise fivebar sees only the proxy: every visitor counts as one, in the place the proxy runs, and a proxy on a cloud network is taken for a bot, so every visit lands on the Bots page and none in your figures.

HeaderHolds
X-Forwarded-ForThe visitor’s IP address, first. Most proxies set it for you.
X-Fivebar-IPThe visitor’s IP address, where you’d rather set it yourself. It comes before X-Forwarded-For.
X-Fivebar-CountryTheir country, as a two-letter code, such as GB
X-Fivebar-CityTheir city, such as London
X-Fivebar-ASNTheir network’s AS number, such as 2856

The address is the one that matters: fivebar tells visitors apart by it, as always, and never keeps it. The rest say where the visitor is, let fivebar recognise bots by their network, and leave out the networks and countries your site excludes. Send what your platform knows. Without them, visits still count, but with no country or city, and bots are told by their user agent alone, so a visit from a hosting network counts as a person’s. Write a name outside ASCII percent-encoded, as encodeURIComponent() does. fivebar also reads CloudFront’s CloudFront-Viewer-* headers and Vercel’s x-vercel-ip-* ones where they reach it.

Recipes

Each sets up the two paths and names the visitor, and passes on neither your site’s cookies nor its Authorization header, such as a staging site’s password. Put the tag above on your pages once the proxy is live.

  • Cloudflare, with a Worker on your own zone
  • Vercel, with Routing Middleware, and Next.js
  • Netlify, with an Edge Function
  • Amazon CloudFront, with two behaviours in your distribution
  • nginx, with two locations in your server block
  • Caddy, with two handlers in your Caddyfile

Other paths

If /js/tally.js or /api/tally is already taken on your site, proxy other paths, and tell the script where to send its counts with data-api:

<script async data-domain="example.com" data-api="/stats/event" src="/stats/script.js"></script>

Content Security Policy

Served from your own domain, the script is allowed by 'self' in script-src and connect-src, so a Content Security Policy needs no mention of fiveb.ar.

Check it works

Open a page of your site with your browser’s developer tools on the Network panel. The script should load from your own domain, and a request to your own /api/tally should be answered 202: Troubleshooting says what any other answer means. Then open your dashboard: you should be among those on the site now, in the right country.

Check from your own connection. Where your proxy sends the visitor’s network, in X-Fivebar-ASN or CloudFront-Viewer-ASN, as the Cloudflare and CloudFront recipes do, a visit through a VPN or from a cloud server is a bot’s, and is on the Bots page instead. Without it, such a visit counts as yours.

If every visit counts as one visitor, all in one place, or nothing shows at all, your proxy isn’t naming the visitor: check it sends X-Forwarded-For or X-Fivebar-IP with the visitor’s address.