Subscribe to our list to receive the latest updates on Node on Fire

Class: Tests


new Tests()

A/B split testing module.

This modules allows you to easily creates A/B tests. Tests optionally belong to one or multiple controllers.

The below creates a test with two variants: A and B.

app.test(function ColorOfHeaderTest() {
    return {
        controller: 'TestController',
        variants: ['A', 'B']

This creates a test named ColorOfHeaderTest which is a client-side service available through dependecy injection. The test exposes two public methods:

  1. ColorOfHeaderTest#participate makes the current user, either signed-in or not, participate to the test. The user automatically gets assigned to the variant with the least amount of participants. Users get distributed equally among all the different variants.
  2. ColorOfHeaderTest#getVariant returns the variant the user belongs to. If a user is not participating the test and this method is called, an error is thrown.

If you assign a test to one or more controllers, a user automatically participates the test when the controller is loaded. This is because Node on Fire in the $routeProvider resolves the test dependency only after having called the participate method.

app.controller(function TestController(ColorOfHeaderTest) {
    if(ColorOfHeaderTest.getVariant() == 'A') {
        // Show something in green
    else {
        // Show something in blue.

Because you generally want to know which test a user participates to, you can set a delegate to the TestsService to subscribe to participation events. The below registers a super property to Mixpanel whenever a user participates an event. This allows you to easily track conversion, retention and whatnot per test variant in Mixpanel.['TestsService', function(TestsService) {
    TestsService.delegate = {
        participate: function(test, variant) {
            console.log('Join test ' + test + ' with variant ' + variant);

            var properties = {};
            properties[test] = variant;

Do you have any questions or comments on this page? Start a discussion below.

comments powered by Disqus
Subscribe to our list to receive the latest updates on Node on Fire