npm-ab-testing

express js module for split ab testing using cookies based on user traffic

Usage no npm install needed!

<script type="module">
  import npmAbTesting from 'https://cdn.skypack.dev/npm-ab-testing';
</script>

README

npm-ab-testing

==========

Stabe version

A/B testing made easy.

Install

npm install npm-ab-testing

Initialize

var ABTesting = require('npm-ab-testing');

Set Configuration

ABTesting.setABConfig({
    cookieName: <cookieName-which-you-want-to-give>,
    weightage: {
        'traffic-for-blue-button': .1,
        'traffic -for-bold-text' : .05
    },
    expireTimeInHours: 24
});

* "cookieName" will be set on customer browser
* weightage represents percent of traffic you want to display ab-testing of a component.

ex :  for a button color chnage you want to consider 24% of your customers then weightage section would look like

weightage: {
        'traffic-for-button': .24,
    }

* expireTimeInHours ex: 24 , for 24 hours this user will be shown your a/b test cases.

USE in express.js / route.js

    app.use(cookieParser());
    
    app.use('/',function(req,res,next){
        var array-of-cookie-names=ABTesting.getABTestCases(req,res,next);
        next();
    });

for button change cookie was set with name of "traffic-for-button"

if(array-of-cookie-names.indexOf("traffic-for-button")>=0){
    // display your new button
    //or
    // route to new url
}else{
    // display old button 
    //or
    // use old page url.
}