taplytics
v1.2.0
Published
Taplytics Node.js SDK for fast A/B testing and Feature Flagging
Downloads
360
Readme
Getting started
Taplytics decisions is an API to quickly use Taplytics features and functionality at edge.
Initialization
API client can be initialized as following:
First install the SDK to your project
npm install taplytics
Then import it
var taplytics = require('taplytics')('API_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
| Parameter | Tags | Description |
|-----------|------|-------------|
| userId | Required
| ID for current user |
| attributes | Optional
| Provide all relevant attributes associated with the user |
| callback | Optional
| Provide 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
| Parameter | Tags | Description |
|-----------|------|-------------|
| userId | Required
| ID for given user |
| attributes | Optional
| All relevant attributes associated with the user |
| callback | Optional
| Provide 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
| Parameter | Tags | Description |
|-----------|------|-------------|
| userId | Required
| ID for given user |
| experimentName | Required
| Name of an Experiment |
| attributes | Optional
| All relevant attributes associated with the user |
| callback | Optional
| Provide 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
| Parameter | Tags | Description |
|-----------|------|-------------|
| userId | Required
| ID for given user |
| varName | Required
| name of variable |
| defaultValue | Required
| default value to be used if user does not have variable available. |
| attributes | Optional
| All relevant attributes associated with the user |
| callback | Optional
| Provide 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
});
postEvent
Send an event to Taplytics. These events are then used to compare against an experiment's goals to determine the success of an A/B test.
Parameters
| Parameter | Tags | Description |
|-----------|------|-------------|
| userId | Required
| ID for given user |
| body | Optional
| Provide an array of events, as well as all additional relevant user attributes. |
| callback | Optional
| Provide a callback if you don't want to use a promise|
Example Usage
var userId = user_id
var body = {
attributes: {key: 'value'},
events: [
{ eventName: 'event 1', eventValue: 3 },
{ eventName: 'event 2' }
]
}
taplytics.postEvent(userId, body, (error, response) => {
// 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
| Parameter | Tags | Description |
|-----------|------|-------------|
| userId | Required
| ID for given user |
| attributes | Optional
| All relevant attributes associated with the user |
| callback | Optional
| Provide 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 andkeyName
for the feature flag's key to be used in your code
Parameters
| Parameter | Tags | Description |
|-----------|------|-------------|
| userId | Required
| ID for given user |
| attributes | Optional
| All relevant attributes associated with the user |
| callback | Optional
| Provide 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 if the
keyName
provided corresponds to an enabled featureFlag in your Taplytics project
Parameters
| Parameter | Tags | Description |
|-----------|------|-------------|
| userId | Required
| ID for given user |
| keyName | Required
| Key name for the feature flag |
| attributes | Optional
| All relevant attributes associated with the user |
| callback | Optional
| Provide 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();
}
})