A/B testing React components with Redux and debug tools. Isomorphic with a simple, universal interface. Well documented and lightweight. Tested in popular browsers and Node.js. Includes helpers for React, Redux, and Segment.io
npm install redux-ab-test



Support for testing multiple versions of your components with React and Redux.
- Works great with React
- Integrated with Redux
- Supports multiple experiments and variations with a simple DSL
- Respects precedence order when specifying audience and react-router criteria
- Can be used for server rendering
- Few dependencies, small (20k, 6k gzipped)
Redux AB Test is distributed via npm:
```
npm install --save redux-ab-test
`js
import React, { Component } from 'react';
class App extends Component { { /* Try out new versions of your homepage! / } { /* Default homepage experience / } { /* Guided Onboarding Wizard / } { /* Modals for all of the things! / }
render() {
return (
Welcome to my app!
Checkout my amazing homepage!
);
}
}
`
`js
import { createStore, applyMiddleware, compose } from 'redux';
import { reactAbTest, reactAbTestInitialState, reduxAbTestMiddleware } from 'redux-ab-test';
import { createAction, handleActions } from 'redux-actions';
import { PLAY, WIN } = 'redux-ab-test';
// Create a middleware that listens for plays & wins
const pushToAnalytics = store => next => action => {
const output = next(action);
switch(action.type) {
case PLAY: {
const experiment = action.payload.get('experiment');
const variation = action.payload.get('variation');
window.trackEvent('Experiment Played', { ... })
break;
}
case WIN: {
const experiment = action.payload.get('experiment');
const variation = action.payload.get('variation');
const actionType = action.payload.get('actionType');
const actionPayload = action.payload.get('actionPayload');
window.trackEvent('Experiment Won', { ... })
break;
}
}
return output;
};
const middlewares = [ reduxAbTestMiddleware, pushToAnalytics /, thunk, promise, .../ ];
const finalCreateStore = compose(applyMiddleware.apply(this, middleware))(createStore);
const reducers = { reactAbTest };
export default finalCreateStore(reducers, {});
`
Please ★ on GitHub!
- Installation
- Alternative Libraries
- Resources for A/B Testing with React
- API Reference
-
-
- Tests
- Running Tests
redux-ab-test is compatible with React 0.15.x.
`bash`
npm install redux-ab-test
Please let us know about alternate libraries not included here.
* Product Experimentation with React and PlanOut on the HubSpot Product Blog
* Roll Your Own A/B Tests With Optimizely and React on the Tilt Engineering Blog
* Simple Sequential A/B Testing
* A/B Testing Rigorously (without losing your job)
Please let us know about React A/B testing resources not included here.
Experiment container component. Children must be of type Variant.
* Properties:
* name - Name of the experiment.string
* Required
* Type: "My Example"
* Example: userIdentifier
* - Distinct user identifier. When defined, this value is hashed to choose a variant if defaultVariantName or a stored value is not present. Useful for server side rendering.string
* Optional
* Type: "7cf61a4521f24507936a8977e1eee2d4"
* Example: defaultVariantName
* - Name of the default variant. When defined, this value is used to choose a variant if a stored value is not present. This property may be useful for server side rendering but is otherwise not recommended.string
* Optional
* Type: "A"
* Example:
Variant container component.
* Properties:
* name - Name of the variant.string
* Required
* Type: "A"
* Example:
* Product Experimentation with React and PlanOut on the HubSpot Product Blog
* Roll Your Own A/B Tests With Optimizely and React on the Tilt Engineering Blog
* Simple Sequential A/B Testing
* A/B Testing Rigorously (without losing your job)
Please let us know about React A/B testing resources not included here.
Mocha tests are performed on the latest version of Node.
Please let me know if a different configuration should be included here.
Locally:
`bash``
npm install
npm test