Visitor location (divisions and districts)
Record where visitors are beyond their country, so the dashboard map can show Bangladesh's 8 divisions and 64 districts. Uses MaxMind's free GeoLite2 database.
Out of the box PixelFox knows each visitor's country, from Cloudflare's
CF-IPCountry header. That is enough for the world map. To see regions and,
for Bangladesh, divisions and districts, the backend needs an IP location
database. PixelFox uses MaxMind's free GeoLite2-City database, read from a
file on the backend. Until it is there, the Bangladesh map still draws, but every
district shows zero and says why.
What you get
| Recorded | Used for |
|---|---|
| Country | World map, top countries |
| Region (Bangladesh: division) | Region list; the 8 divisions |
| Second-level region (Bangladesh: district), city | The 64 districts |
| Approximate latitude, longitude, time zone | Stored with the event; not shown yet |
The IP address itself is still truncated before it is stored (IPv4 /24, IPv6 /48). The full address is used only for the lookup, in memory.
Set it up
-
Create a free MaxMind account at maxmind.com/en/geolite2/signup.
-
In your MaxMind account, open Manage license keys and generate a key. Note your account id too.
-
In
apps/backend, run:MAXMIND_ACCOUNT_ID=123456 MAXMIND_LICENSE_KEY=your-key bun run geoip:updateThis downloads the database to
apps/backend/data/GeoLite2-City.mmdb(about 70 MB, git-ignored). SetGEOIP_DB_PATHto keep it elsewhere, for example on a mounted volume in production. -
Restart the backend, or wait up to an hour: it reopens the file when it changes. The log says
geoip: loaded …. -
Browse your site. New visitors now carry a division and district. Open Dashboard → Overview → Where your visitors are, pick Bangladesh, and pin it to make it your default map.
Only events recorded after this are located. Earlier events have no region and are not backfilled.
Keep it current
MaxMind updates GeoLite2 regularly and its terms ask you to use recent data. Run the same command weekly (cron or CI). It writes to a temporary file and renames it into place, so a running backend never reads a half-written database.
MaxMind's terms also require credit wherever the data is shown. The map includes it; do not remove the footer line.
How accurate is it
IP location is approximate, and in Bangladesh it is coarse. Many connections resolve to an internet provider's head office, so Dhaka and Chattogram read high and smaller districts read low. The map shows what share of visitors has a division and a district, so you can judge how far to trust it. Treat it as a guide to where traffic clusters, not a count of where people live.
Names and boundaries
MaxMind and the boundary files spell some places differently (Chittagong and Chattogram, Comilla and Cumilla, Jessore and Jashore). PixelFox matches them through one table of the 8 divisions and 64 districts, with the old and new spellings, so each visitor lands in the right district. Places that do not match are left out of the district map rather than guessed.
The Bangladesh district shapes come from geoBoundaries (source: Bangladesh Bureau of Statistics and OCHA ROAP, licence CC BY 3.0 IGO). The world map is Natural Earth (public domain). Both are credited under the map.