$ show peaksandpies/universal-analytics
universal-analytics is a Node.js library that implements Google's Universal Analytics Measurement Protocol, enabling server-side tracking of pageviews, events, transactions, exceptions, timings, and screenviews. It provides a `Visitor` class that queues hits and sends them as HTTP POST requests to Google Analytics, with support for batching, parameter validation, and persistent session data. The library includes an Express middleware for automatic client ID detection from cookies or sessions. The codebase is small, well-structured, and thoroughly tested. It demonstrates solid engineering practices: clean API design with flexible argument signatures, context-propagation for daisy-chaining, and a simple yet effective request module using native Node.js HTTP/HTTPS libraries. However, the library targets a deprecated service (Universal Analytics, being replaced by GA4), and its dependencies are outdated (e.g., uuid version 14.0.0 does not exist on npm). The last release (0.5.4) and the repository's commit activity suggest it is no longer actively maintained. As a library, it is tightly coupled to the Measurement Protocol specification, but internal components like the UUID utility and HTTP helper are reusable.
The LLM identified 2 files worth highlighting for reuse:
Provides functions `isUuid`, `isCookieCid`, and `ensureValidCid` for validating and normalizing version 4 UUIDs and Google Analytics cookie client IDs. This module is self-contained, has no internal dependencies, and implements regex-based validation logic that can be reused in any Node.js project requiring UUID format enforcement or GA cookie CID parsing.
A minimal, zero-dependency HTTP POST helper using Node's built-in `http` and `https` modules. It handles URL parsing, protocol selection, request body sending, and response collection with error handling. This module encapsulates a common pattern for making HTTP requests without third-party libraries and can be extracted and reused in any Node.js project needing simple POST functionality.