Skip to content

donato/this-or-that

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This Or That

ThisOrThat is a helper to make a/b/n testing a little easiers. Given an array of objects, it will choose an index into that array, and persist it across user sessions. In cases where it cannot store locally, it will exclude the user from A/B testing.

    let {thisorthat} = require ('thisorthat.js');

    let config_a = {
        min: 1,
        max: 100,
        image: false
    };
    let config_b = {
        min: 1,
        max: 100,
        image: true
    };
    
    // Given an array of objects, choose one and persist that choice across sessions
    chosen_config = thisorthat('my_app', [config_a, config_b]);
    
    console.log(chosen_config.image);      // either true or false
    console.log(chosen_config.thisorthat); // the index of the chosen config

Advanced Use-Case

If you would like to change how the chosen object is modified, supply a "modify" function.

    let overwriteModifer(obj, index) => {
        obj["ab_test_index"] = (index == 1 ? "A" : "B");
    }
    chosen_config = thisorthat('my_app', [config_a, config_b], overwriteModifer);
    
    console.log(chosen_config.ab_test_index);      // either "A" or "B"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published