analytics

Lightweight analytics abstraction layer for tracking page views, custom events, & identifying visitors

What is analytics?

Lightweight analytics abstraction layer for tracking page views, custom events, & identifying visitors

Overview of analytics

What it is

analytics is a lightweight analytics abstraction library for tracking page views, custom events, and identifying visitors. It is designed to work with any third-party analytics tool or your own backend. The library provides a pluggable abstraction layer that allows developers to easily add, remove, or swap analytics providers without changing application code. It works in both browser and server environments (isomorphic), queues events until analytic libraries are loaded, and supports offline usage. The project is hosted on GitHub and has a documentation site at getanalytics.io. It is licensed under MIT and is open source.

Key features

  • Extendable: Bring your own third-party tools and plugins.
  • Test and debug analytics integrations with time travel and offline mode.
  • Add functionality or modify tracking calls with baked-in lifecycle hooks.
  • Isomorphic: Works in browser and on server.
  • Queues events to send when analytic libraries are loaded.
  • Conditionally load third-party scripts.
  • Works offline.
  • TypeScript support.

Use cases

  • Abstracting analytics logic across multiple providers (e.g., Google Analytics, Customer.io) so that switching or adding providers requires only configuration changes.
  • Tracking page views, custom events (e.g., purchases, sign-ups), and user identification in web applications.
  • Testing and debugging analytics integrations during development with time travel and offline mode.
  • Respecting visitor privacy settings and allowing opt-out mechanisms.
  • Conditionally loading third-party analytics scripts based on user consent or environment.

Getting started

Install the package via npm, yarn, pnpm, or bun: bash npm install analytics --save Or using yarn: bash yarn add analytics Or using pnpm: bash pnpm add analytics Or using bun: bash bun add analytics Then initialize analytics with plugins and use the API: js import Analytics from 'analytics' import googleAnalytics from '@analytics/google-analytics' import customerIo from '@analytics/customerio' const analytics = Analytics({ app: 'my-app-name', version: 100, plugins: [ googleAnalytics({ measurementIds: ['G-XXXXXXXX'] }), customerIo({ siteId: '123-xyz' }) ] }) analytics.page() analytics.track('userPurchase', { price: 20, item: 'pink socks' }) analytics.identify('user-id-xyz', { firstName: 'bill', lastName: 'murray', email: '[email protected]' }) For Node.js usage, use require as shown in the repository README.

License and pricing

The license is MIT. The project is open source and free to use.

Based on the project's public README and repository metadata.

Add this badge to your README

Featured on YunoDB Badge styles & help

Maintain this project? Show that it is featured on YunoDB.

Markdown[![Featured on YunoDB](https://yunodb.com/badge/davidwellsanalytics.svg)](https://yunodb.com/tools/davidwellsanalytics?utm_source=github&utm_medium=badge)
HTML<a href="https://yunodb.com/tools/davidwellsanalytics?utm_source=github&utm_medium=badge"><img src="https://yunodb.com/badge/davidwellsanalytics.svg" alt="Featured on YunoDB" height="20"></a>