Self-Hosting Analytics: Why Privacy Matters
Most websites default to Google Analytics. It's free and easy, but the privacy trade-off is significant. You are essentially feeding your user's data into a massive ad-targeting machine. For this website, I decided to build my own analytics engine.
What I Track
I wanted to know: * Where are visitors coming from? (Referrers) * Which pages are popular? * What devices are they using?
I do not track: * Personal Identifiable Information (PII) * Cross-site behavior (cookies)
The Tech
I built a custom Flask Blueprint that logs every request to a Visitor table. I use GeoIP2 databases to resolve IP addresses to cities (stored locally, no API calls to third parties).
Heatmaps
I even went a step further and implemented basic heatmap tracking. By recording mouse clicks and scroll depth via JavaScript and sending them in batches to the server, I can visualize how users interact with the UI.
Ownership
The best part is data ownership. The database lives on my server. No third party has access to it. It’s a bit more work to maintain, but for a personal portfolio, the privacy and control are absolutely worth it.