Documentation

Currently Dual Kind only provides a script to be called form the web. The API endpoints can be used to track from any platform but there is no official support yet.

Installing on the web

To install for experiments you just need to include the script and initialize it with setup and your key.

<script src="https://cdn.dualkind.com/spark-v1.js"></script>
<script>dualkind.setup("your-key");</script>

Activating the experiment

To activate the experiment call the activate function with the experiment key and a callback function which will receive the selected variation.

<script>
dualkind.activate("your-experiment", function(variation) {
    console.log(variation);
    // Construct your UI from returned variation.
});
</script>

Parameter variation from the callback function can also be null if there is any error activating the experiment.

The activate function also accepts a variation name as a second parameter instead of a callback function. This allows to specify the variation that was activated in case you use Dual Kind just for storing the events and do the statistical analysis.

<script>
dualkind.activate("your-experiment", "control");
</script>

Additionally you can pass an unique identifier to identify the user if you don't want the API to generate one based on the request information.

<script>
dualkind.activate("your-experiment", "control", {"uniqueId": 2147483647});
</script>

The uniqueId value needs to be a value between -2147483648 and 2147483647 (4 byte, signed integer).

Tracking events

Tracking is done through the track function. If there is only one event to track (ie. using the activation to count how many people see the experiment and using a single convert event) you can call the function as follows:

<script>
dualkind.track("your-experiment");
</script>

Additionally you can pass the event to be tracked as a second parameter.

<script>
dualkind.track("your-experiment", "convert");
</script>

As with the activate function, it is also possible to pass a variation and uniqueId values.

<script>
dualkind.track("your-experiment", "convert", "control", {"uniqueId": 2147483647});
</script>

Helper methods

The Dual Kind JavaScript file also provides two additional helper methods to get started with showing experiments.

The replace function will replace the script tag it is executing in with the node based on the returned variation.

<script>
    function trackedLink(text, location, experiment) {
        var link = document.createElement('a')
        link.innerText = text;
        link.href = location;
        link.addEventListener('click', function () {
            dualkind.track(experiment);
        });
        return link;
    }
    dualkind.activate('experiment', dualkind.replace({
        'control': trackedLink('Buy now', '#', 'experiment'),
        'other': trackedLink('Buy now $', '#', 'experiment'),
    }));
</script>

If the activate were to select the control variation it the whole script tag would be replaced by a link with text "Buy now" that would track every press.

Additionally you can use activateBalanced which will activate with one of the provided variations, in a random way, storing the selected variation in a cookie.

<script>
    var variation = dualkind.activateBalanced('experiment', ['control', 'other']);
    // Use your variation
</script>