This `universal-analytics` package provides a Node.js module for interacting with Google's Universal Analytics (UA) tracking via the Measurement Protocol v1. It enables server-side tracking of user behavior without requiring client-side browser integration. The current stable version is 0.5.3. This library is specifically designed for Universal Analytics, which has been deprecated by Google in favor of Google Analytics 4 (GA4). Consequently, this package is primarily for maintaining existing legacy systems that still rely on Universal Analytics properties, as new UA properties stopped processing data in July 2023, and all UA processing will cease in July 2024. There is no active release cadence as the underlying service is sunsetting, differentiating it from clients for modern GA4 properties.
npm install universal-analyticsVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing a Universal Analytics visitor, sending a basic pageview, and sending an event with persistent parameters and an explicit client ID.
Migrate your analytics implementation to Google Analytics 4 (GA4). This will require using a different client library or implementing the GA4 Measurement Protocol directly, as this package does not support GA4.
Always chain `.send()` at the end of a tracking call (e.g., `visitor.pageview('/').send()`) or provide a callback (e.g., `visitor.event('Cat', 'Act', callback)`). Without it, data will not be transmitted.If you need to use a custom client ID that is not a UUID v4, pass `strictCidFormat: false` in the options object during visitor initialization: `ua('UA-XXXX-XX', 'CUSTOM_CLIENTID', { strictCidFormat: false })`.To force HTTP, include `{ http: true }` in the options object during visitor initialization: `ua('UA-XXXX-XX', { http: true })`.After any tracking call (e.g., `pageview`, `event`), ensure you append `.send()` or provide a callback function, for example: `visitor.pageview('/home').send();` or `visitor.event('Category', 'Action', () => console.log('Event sent'));`Ensure that `ua('UA-XXXX-XX')` is called with your valid Universal Analytics Tracking ID (e.g., 'UA-12345-6'). Check for typos or missing configuration.No dependency data recorded yet.