node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



This is a pluggable event driven analytics library designed to work with any third party analytics tool.


  • Pluggable via middleware. Bring your own third party tool
  • Works on client & server-side
  • In client, works offline. Queues events to send when connection resumes


Companies frequently change their analytics requirements and add/remove services to their sites and applications. This can be a time consuming process integrating with N number of third party tools.

This library solves that.


You should never be locked into a tool.

To add or remove an analytics provider simply remove it as middleware.

The provider integrations can be run independently of this library or plugged into other tools.


npm i

Running Demo

cd _example && npm install && npm start


import analyticsLib from 'analytics'
import googleAnalytics from 'analytics-ga'
import loggerPlugin from 'analytics-logger'
const plugins = [
    trackingId: 'UA-121991291',
const analytics = analyticsLib({
  app: 'my-app-name',
  version: 100,
  plugins: plugins
// Using it:
// page tracking
// event tracking
analytics.track('userPurchase', {
  price: 20
// identifying users
analytics.identify('user-id-xyz', {
  firstName: 'bill',
  lastName: 'murray',
  email: ''

Adding Analytics providers

The library is designed to work with any third party vendor!

You simply need to supply the below methods (that apply to your integration).

Here is an example:

export default function googleAnalytics(config) {
  return {
    NAMESPACE: 'google-analytics',
    config: {
      whatever: 'youWant',
      googleAnalyticsId: // 'UA-82833-33833'
    initialize: function() {
      // load provider script to page (in browser)
    page: function() {
      // call provider specific page tracking
    track: function() {
      // call provider specific event tracking
    identify: function() {
      // call provider specific user identify method
    loaded: () => {
      // return boolean for loaded analytics library
      return !!window.gaplugins

You can also add whatever middleware functionality you'd like via redux middleware!

// logger example
const logger = store => next => action => {
  if (action.type) {
    console.log(`>> dispatching ${action.type}`, JSON.stringify(action))
  let result = next(action)
  return result
export default logger

To use the plugins/integrations simply include them when you boot up analytics, see usage example above.