0.1.0 • Published 10 years ago
redux-segmentio v0.1.0
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
analyticsproperty inside itsmetaproperty - have a
collectionproperty inside itsanalyticsproperty
and MAY
- have an
eventproperty inside itsanalyticsproperty
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
}
}
}
}
}0.1.0
10 years ago