All Projects → olahol → React Ab

olahol / React Ab

Simple declarative and universal A/B testing component for React.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Ab

Expan
Open-source Python library for statistical analysis of randomised control trials (A/B tests)
Stars: ✭ 275 (-35.14%)
Mutual labels:  ab-testing
Relate
[ARCHIVED] experimenting React + GraphQL + Next.js web app on the theme of mindfulness
Stars: ✭ 324 (-23.58%)
Mutual labels:  universal
Regal
A/B Testing or publish smart grouping engine
Stars: ✭ 396 (-6.6%)
Mutual labels:  ab-testing
Jackblog React
Jackblog react 版, 个人博客系统, 使用服务端渲染(Universal / Isomorphic), react, redux, react-router, react-bootstrap, immutablejs, redux-form等
Stars: ✭ 292 (-31.13%)
Mutual labels:  universal
React Experiments
React components for implementing UI experiments
Stars: ✭ 311 (-26.65%)
Mutual labels:  ab-testing
Pwa
An opinionated progressive web app boilerplate
Stars: ✭ 353 (-16.75%)
Mutual labels:  universal
Go Starter Kit
[abandoned] Golang isomorphic react/hot reloadable/redux/css-modules/SSR starter kit
Stars: ✭ 2,855 (+573.35%)
Mutual labels:  universal
Gitops Istio
GitOps Progressive Delivery demo with Istio, Flux, Helm Operator and Flagger
Stars: ✭ 412 (-2.83%)
Mutual labels:  ab-testing
Isomorphic React
A simple but powerful React application built on a standards-compliant back-end
Stars: ✭ 318 (-25%)
Mutual labels:  universal
Judo Heroes
A React application to showcase rendering with Universal JavaScript
Stars: ✭ 373 (-12.03%)
Mutual labels:  universal
Planout.js
A JavaScript port of Facebook's PlanOut Experimentation Framework
Stars: ✭ 292 (-31.13%)
Mutual labels:  ab-testing
Study
A simple, progressive, client/server AB testing library 📚
Stars: ✭ 293 (-30.9%)
Mutual labels:  ab-testing
React Native Responsive Grid
Bringing the Web's Responsive Design to React Native
Stars: ✭ 369 (-12.97%)
Mutual labels:  universal
Racket
A complete starting app for developing universal React/Redux web apps with generators, best practices and more
Stars: ✭ 290 (-31.6%)
Mutual labels:  universal
React Server
🚀 Blazing fast page load and seamless navigation.
Stars: ✭ 3,932 (+827.36%)
Mutual labels:  universal
Bayesab
🐢 bayesAB: Fast Bayesian Methods for A/B Testing
Stars: ✭ 273 (-35.61%)
Mutual labels:  ab-testing
Ngx Meta
Dynamic page title & meta tags utility for Angular (w/server-side rendering)
Stars: ✭ 331 (-21.93%)
Mutual labels:  universal
Cra Universal
🌏 Create React App companion for universal app. No eject, auto SSR, zero config, full HMR, and more (inactive project)
Stars: ✭ 419 (-1.18%)
Mutual labels:  universal
Preact Render To String
📄 Universal rendering for Preact: render JSX and Preact components to HTML.
Stars: ✭ 411 (-3.07%)
Mutual labels:  universal
Proctor
Proctor is a Java-based A/B testing framework developed by, and used heavily within, Indeed.
Stars: ✭ 371 (-12.5%)
Mutual labels:  ab-testing

react-ab

npm version Build Status Coverage Status Dependency Status Size

Simple declarative and universal A/B testing component for React.

Demo

A/B Testing Demo

Install

npm install react-ab --save

or

bower install react-ab --save

Examples

Using Mixpanel.

var Experiment = require("react-ab").Experiment
  , Variant = require("react-ab").Variant;

var App = React.createClass({
  choice: function (experiment, variant, index) {
    mixpanel.register({
      "tagline": variant
    });
  }

  , click: function (e) {
    mixpanel.track("click");
  }

  , render: function () {
    return (
      <div>
        <Experiment onChoice={this.choice} name="tagline">
          <Variant name="normal">
            <h1> A A/B testing component for React </h1>
          </Variant>
          <Variant name="enterprise">
            <h1> A vertically integrated React component </h1>
          </Variant>
          <Variant name="lies">
            <h1> One weird React component that will increase your metrics by 100%! </h1>
          </Variant>
        </Experiment>
        <a onClick={this.click} href="//github.com/olahol/react-ab">React AB component</a>
      </div>
    );
  }
});

Using Google Universal Analytics. Requires a Custom Dimension.

var Experiment = require("react-ab").Experiment
  , Variant = require("react-ab").Variant;

var randomGoogle = function () {
  // base randomness off analytics.js client id.
  // https://developers.google.com/analytics/devguides/platform/user-id#clientid-userid
  var clientId = tracker.get("clientId");
  return (parseFloat(clientId, 10) % 100) / 100;
};

var App = React.createClass({
  choice: function (experiment, variant) {
    var dimension = 1; // Index of your custom dimension.
    ga("set", "dimension" + dimension, experiment + ": " + variant);
  }

  , click: function (e) {
    ga("send", "event", "click", "link");
  }

  , render: function () {
    return (
      <div>
        <Experiment onChoice={this.choice} random={randomGoogle} name="tagline">
          <Variant name="normal">
            <h1> A A/B testing component for React </h1>
          </Variant>
          <Variant name="enterprise">
            <h1> A vertically integrated React component </h1>
          </Variant>
          <Variant name="lies">
            <h1> One weird React component that will increase your metrics by 100%! </h1>
          </Variant>
        </Experiment>
        <a onClick={this.click} href="//github.com/olahol/react-ab">React AB component</a>
      </div>
    );
  }
});

Universality is achieved by setting get, set, clear. Here is an example server side with Express.js and using ES6:

import express from "express";
import cookieParser from "cookie-parser";

import React from "react/addons";
import { Experiment, Variant } from "react-ab";

var App = React.createClass({
  choice: function (experiment, variant, index) {
    console.log(experiment, variant, index);
  }

  , render: function () {
    return (
      <div>
        <Experiment {...this.props} onChoice={this.choice} name="tagline">
          <Variant name="normal">
            <h1> A A/B testing component for React </h1>
          </Variant>
          <Variant name="enterprise">
            <h1> A vertically integrated React component </h1>
          </Variant>
          <Variant name="lies">
            <h1> One weird React component that will increase your metrics by 100%! </h1>
          </Variant>
        </Experiment>
      </div>
    );
  }
});

var app = express();

app.use(cookieParser());

app.get("/", function (req, res) {
  res.send(React.renderToString(<App
    get={(x) => req.cookies[x]}
    set={(x, y) => res.cookie(x, y)}
    clear={res.clearCookie}
  />));
});

app.listen(3000);

API

Experiment

Props

name

Name of experiment, this prop is required. Should be something that describes the category being tested like color or title.

onChoice

Callback that fires when a variant is chosen. Gets arguments experiment name, variant name, variant index and was retrieved?. was retrieved? is true if the variant was retrieved using the get prop usually from a cookie.

random

Random function, should return a number in the range [0, 1). The default uses crypto.getRandomValues() when available and falls back on Math.random.

get

A function that takes an experiment and returns a variant. By default uses browser cookies.

set

A function that takes an experiment and variant and stores it. By default uses browser cookies.

clear

A function that clears/unsets an experiment. By default uses browser cookies.

Context

get, set, clear, random can also be set from context. If these props exists they overwrite context.

randomExperiment

random function taken from context.

getExperiment

get function taken from context.

setExperiment

set function taken from context.

clearExperiment

clear function taken from context.

Methods

getVariant()

Returns the name of the current variant.

chooseVariant()

Choose a new variant.

clearCookie()

Clear the experiment cookie.

Variant

Props

name

Name of variant, this props is required. Should be something descriptive of the attribute the variant represent like red or large.


MIT Licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].