This is a fork of rn-redux-mixpanel pointing ot madhums/rn-redux-mixpanel#1.2.0 with supporting $set_once
method
rn-redux-mixpanel
Configurable redux middleware that sends your actions & user profile data to Mixpanel. It also works with React Native ;)
Installation
npm install --save rn-redux-mixpanel
Example
// store/index.js // define a blacklist to be used in the ignoreAction filterconst blacklist = INIT_PERSISTENCE HYDRATE SESSION_ACTIVITY; // Export configured mixpanel redux middleware // add ignore action filter { return blacklist > -1; } // Mixpanel Token token: YOUR_MIXPANEL_TOKEN // derive Mixpanel event name from action and/or state // Per-action selector: Mixpanel event `distinct_id` { if statesession && statesessionuserId return statesessionuserId else if SIGN_IN === actiontype && actionuser return actionuser_id } // Per-action selector: Mixpanel Engage user profile data { const user = actionuser // Only update user profile data on SIGN_IN action type if SIGN_IN === actiontype && user // User data to `$set` via Mixpanel Engage request const userProfileData = '$first_name': user'first_name' '$last_name': user'last_name' '$email': user'email_address' '$created': user'date_created' return userProfileData } // Per-action selector: Mixpanel Engage user profile set data once { const user = actionuser // Only update user profile data on SIGN_IN action type if SIGN_IN === actiontype && user // User data to `$set_once` via Mixpanel Engage request return 'Has Logged In': true }
Usage
Configure the mixpanel
redux middleware by invoking with an options object, containing:
token
– Your Mixpanel application token.ignoreAction
– An optional function, that receives an action and returns a truthy value, if it should be ignored.selectDistinctId
– A selector function that returns thedistinct_id
(user id), given the action and store state.selectUserProfileData
– A selector function that returns user profile data for a Mixpanel Engage request, given the action and store state.selectUserProfileDataOnce
- A selector that returns people properties and sets it for once. (uses$set_once
people property)selectEventName
– A optional selector function that returns the Mixpanel event name, given the action and store state. By default action.type.selectProperties
- An optional selector function that returns Mixpanel properties to add to the request, given the action and store state.