Node.js SDK

Getting Started

Taplytics Universal API allows you to quickly use Taplytics features and functionality at edge.

To get started with the Node.js SDK, your project will need to be re-configured to support User Based Bucketing. Please contact the Taplytics support team or your CSM to confirm if UBB is correctly set up within your projects.

Note: Without UBB, bucketing across devices may be inconsistent.

Initialization

API client can be initialized as follows:

First, install the SDK to your project

npm install taplytics

Then import it

var taplytics = require('taplytics')('SDK_KEY');

Identification

All method calls to Taplytics require a user id. This is to ensure that the user will always receive the correct experiments and variations across all platforms.

Methods

All methods can use either a callback as a param or used as a promise, i.e.


taplytics.getConfig(...).then(val => {
	// use val
}).catch(err => {
	// error err
})

If a callback is provided, the function will not return a promise.

getBucketing

Returns a key/value pairing of all experiments that the user has been segmented into, as well as the variation the users are assigned.

Parameters

ParameterTagsDescription
userIdRequiredID for current user
attributesOptionalProvide all relevant attributes associated with the user
callbackOptionalProvide a callback if you don't want to use a promise

Example Usage

var userId = user_id
var body = { attributes:{ key:'value', key2:'value2' } }

taplytics.getBucketing(userId, body, (err, bucketing) => {
	// your code here
})

getVariables

All variables and their values for the given user

Parameters

ParameterTagsDescription
userIdRequiredID for given user
attributesOptionalAll relevant attributes associated with the user
callbackOptionalProvide a callback if you don't want to use a promise

Example Usage

var userId = user_id
var attributes = { attributes:{ key:'value', key2:'value2' } }

taplytics.getVariables(userId, attributes, (err, variables) => {
	// your code here
})

getVariationForExperiment

For a given experiment, determine whether or not a user is in the experiment, and in which variation

Parameters

ParameterTagsDescription
userIdRequiredID for given user
experimentNameRequiredName of an Experiment
attributesOptionalAll relevant attributes associated with the user
callbackOptionalProvide a callback if you don't want to use a promise

Example Usage

var userId = 'user_id'
var experimentName = 'experimentName';
var attributes = { attributes:{ key:'value', key2:'value2' } }

taplytics.getVariationForExperiment(userId, experimentName, attributes,(error, variation) => {
	// your code here
})

getVariableValue

Value for given Taplytics Dynamic Variable. If a user is not in an experiment containing the variable, the response be the provided default value in the query params.

Parameters

ParameterTagsDescription
userIdRequiredID for given user
varNameRequiredname of variable
defaultValueRequireddefault value to be used if user does not have variable available.
attributesOptionalAll relevant attributes associated with the user
callbackOptionalProvide a callback if you don't want to use a promise

Example Usage

var userId = user_id;
var varName = 'varName';
var defaultValue = 'defaultValue';
var attributes = { attributes:{ key:'value', key2:'value2' } }

taplytics.getVariableValue(userId, varName, defaultValue, attributes, (err, value) => {
	// your code here
});

getConfig

Returns the entire configuration for the project. This is the document that informs the experiment information such as segmentation. Extremely verbose and should be used for debugging.

Parameters

ParameterTagsDescription
userIdRequiredID for given user
attributesOptionalAll relevant attributes associated with the user
callbackOptionalProvide a callback if you don't want to use a promise

Example Usage

var userId = user_id
var attributes = { attributes:{ key:'value', key2:'value2' } }

taplytics.getConfig(userId, attributes, (error, config) => {
	// your code here
})

getFeatureFlags

Returns array of all the enabled feature flags for this project. Each object in the array has name for the name of the feature flag and keyName for the feature flag's key to be used in your code

Parameters

ParameterTagsDescription
userIdRequiredID for given user
attributesOptionalAll relevant attributes associated with the user
callbackOptionalProvide a callback if you don't want to use a promise

Example Usage

var userId = user_id
var attributes = { attributes:{ key:'value', key2:'value2' } }

taplytics.getFeatureFlags(userId, attributes, (error, featureFlags) => {
	// your code here
})

isFeatureFlagEnabled

Returns true or false depending on if the keyName provided corresponds to an enabled featureFlag in your Taplytics project

Parameters

ParameterTagsDescription
userIdRequiredID for given user
keyNameRequiredKey name for the feature flag
attributesOptionalAll relevant attributes associated with the user
callbackOptionalProvide a callback if you don't want to use a promise

Example Usage

var userId = user_id
var attributes = { attributes:{ key:'value', key2:'value2' } }

taplytics.isFeatureFlagEnabled(userId, attributes, (error, enabled) => {
	if (enabled) {
		enableFeature();
	}
})