I Built My Own Analytics + AB Testing Tool in a Weekend With Claude Code.

· Source: Towards AI - Medium · Field: Technology & Digital — Software Development & Engineering, Data Science & Analytics, Artificial Intelligence & Machine Learning · Depth: Intermediate, medium

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

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

Topics

Best for: AI Engineer, Software Engineer, Data Scientist

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by Towards AI - Medium.