sigma-js

v1.1.1
JS client for sigma AB testing framework.

sigma-client

Node / Browser library for sigma AB testing framework.

Installation

Include the "sigma.js" script. The sigma object will be added to your environment. In the browser do the following:

<script src="sigma.js"></script>

If you're using sigma-client with node.js start by installing it:

$ npm install sigma-client

then require the "sigma-client" module:

var sigma = require("sigma-client");

Usage

Check out the examples in the examples directory for some quick examples for how to use the library. Here's a very basic example in node:

var sigma = require('sigma-client');

var session = new sigma.Session({
    environment: {
        city: 'bj',
        fr: 'bd_sem',
        server: 'web00',
    },
});

var data = {
    experiment: 'test-exp',
    variants: ['alt-one', 'alt-two'],
    force: 'alt-one',
    traffic: {
        scope: { city: 'bj' },
    },
};
session.participate(data, function (err, res) {
    if (err) throw err;
    var variant = res.variant.name
    if (variant == 'alt-one') {
        console.log('default: ' + variant);
    } else {
        console.log(variant);
    }
});

When instantiating the session object you can pass optional params client, baseUrl, ipAddress, userAgent

var sigma = new sigma.Session({client: 12345, baseUrl: 'http://www.renrenche.com/api/sigma', ipAddress: '1.2.2.1', userAgent: 'ChromeBot'});

Client ID is a previously generated client id that you've previously stored. IP Address and User Agent are used for bot detection.

Forcing an variant

For debugging / design work it can be useful to force a page to load using a specific variant. To force an variant use the force parameter to participate(). If you're using sigma.js in the browser you can also just include a query parameter, e.g. /your-page?sigma-force-EXPERIMENT_NAME=ALTERNATIVE_NAME.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write and run tests with npm test (requires mocha)
  4. Commit your changes (git commit -am 'Added some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

Metadata

  • MIT
  • Whatever
  • wangshijun
  • released 4/12/2016

Downloads

Maintainers