JSPM

redux-segmentio

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q14448F
  • License MIT

Redux middleware for sending analytics to Segment

Package Exports

  • redux-segmentio

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-segmentio) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

redux-segmentio

Redux middleware for sending analytics to Segment.io.

Usage

import segmentAnalytics from 'redux-segmentio';

// load analytics.js, globally unfortunately
analytics.load("YOUR_WRITE_KEY");
analytics.page();

let analyticsGlobals = {}; // define any globals you want to pass on with every event, such as user's browser info
let analyticsMiddleware = segmentAnalytics(window.analytics, analyticsGlobals);

The default export is a function requiring segment.io client instance. This function returns a middleware function, that can be applied using applyMiddleware from Redux.

If it receives an action whose meta property contains an analytics property with non-empty collection property, it will record the event in the Keen IO analytics.

Actions

An action that should be recorded to analytics MUST

  • have an analytics property inside its meta property
  • have a collection property inside its analytics property

and MAY

  • have an event property inside its analytics property

collection

The required collection property inside the analytics specifies the Keen IO event collection.

event

The optional event property inside the analytics contains the data of the Keen IO event.

An example of an action:

{
  type: ADD_TO_SHOPPING_CART,
  meta: {
    analytics: {
      collection: "add_item_to_shopping_cart"
    }
  }
}

An example with optional property event:

{
  type: ADD_TO_SHOPPING_CART,
  meta: {
    analytics: {
      collection: "add_item_to_shopping_cart",
      event: {
        item: {
          title: item.title,
          itemId: item.itemId
        }
      }
    }
  }
}