I Built My Own Analytics + AB Testing Tool in a Weekend With Claude Code.
Summary
An individual developed a custom analytics and A/B testing tool over a weekend, leveraging Claude Code to create a robust event pipeline. This tool aims to replace traditional, cookie-dependent solutions by collecting user interaction data—such as pageviews, clicks, and scrolls—without cookie banners or per-seat costs. The system identifies users via a "sessionStorage"-based session ID and a hashed visitor ID derived from stable browser traits, ensuring cookieless operation. Events are batched and reliably transmitted using "navigator.sendBeacon" to prevent data loss during page unload, with a fallback to "XMLHttpRequest". A Hono-based ingestion server processes these events, performing validation and batch-inserting them into a denormalized PostgreSQL "events" table. This table is optimized with four specific indexes for efficient analytics queries. A key architectural principle emphasized is abstracting direct database queries behind dedicated functions to simplify future database migrations, such as to ClickHouse. This initial installment details the core data collection and storage infrastructure.
Key takeaway
For software engineers building custom analytics or event tracking systems, prioritize a robust data ingestion pipeline that handles browser unload gracefully using "navigator.sendBeacon". Implement cookieless identity with "sessionStorage" and browser trait hashing to avoid consent banners. Critically, abstract your database interactions behind dedicated functions from day one; this "seam" will dramatically simplify future migrations to high-performance data stores like ClickHouse as your event volume scales, saving significant refactoring effort.
Key insights
Building custom analytics requires cookieless identity, reliable event capture, and a flexible, performant data ingestion pipeline.
Principles
- Cookieless identity can use "sessionStorage" and browser trait hashes.
- Abstract direct database queries behind functions.
- Denormalized tables optimize analytics queries for scale.
Method
Events are queued in the browser, batched every 5s, and flushed on unload via "sendBeacon". A Hono server validates and batch-inserts them into a denormalized PostgreSQL table.
In practice
- Implement "sendBeacon" for critical event capture.
- Hash stable browser traits for cookieless visitor IDs.
- Create a wide, denormalized events table for analytics.
Topics
- Web Analytics
- Cookieless Tracking
- Event Data Pipeline
- navigator.sendBeacon
- PostgreSQL Schema Design
- Database Migration Strategy
Best for: AI Engineer, Software Engineer, Data Scientist
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Towards AI - Medium.