Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

alibaba-archive/abtest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

abtest

NPM version build status Test coverage David deps node version Gittip

an A/B test client for node web

Installation

$ npm install abtest

Feature

  • Random split user into different buckets.
  • Record user's bucket in cookie.
  • Force choose bucket by query.
  • Expire cookie when buckets changed.

Usage

use with koa:

var ABTest = ABTest();
var app = koa();

app.use(function* (next) {
  this.abtest = ABTest({
    getCookie: function () {},  // custom your getCookie method
    setCookie: function () {},  // custom your setCookie method
    query: this.query
  });
});

app.use(function* (next) {
  this.abtest.configure({
    bucket: {
      a: 9,
      b: 1
    },
    enableQuery: true,
    enableCookie: true
  });
});

app.use(function* (next) {
  this.body = this.abtest.bucket; // 10% a, 90% b
});

License

MIT