Java SDK
Getting Started
Taplytics Universal API allows you to quickly use Taplytics features and functionality at edge.
To get started with the Java 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
First, import the taplytics-java-sdk JAR into your project.
Then, import the API client into the desired class:
import com.taplytics.sdk.APIController;
API client can be then initialized as follows:
APIController taplytics = new APIController('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.
Custom User Data
To set custom user data for the current user, add the key "customData"
with a JSONObject
as the value to the attributes parameter along with any other attributes you may need to set.
String userId = "user_id";
JSONObject customAttributes = new JSONObject();
customAttributes.put("employee", true);
customAttributes.put("purchases", 20);
JSONObject attributes = new JSONObject();
attributes.put("email", "[email protected]");
attributes.put("customData", customAttributes)
Methods
All methods can be handled with a callback, or used as a CompletableFuture, i.e.
try {
JSONObject config = taplytics.getConfig(...).get();
// use config
} catch (ExecutionException e) {
// error e
}
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
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getBucketing(userId, attributes)
.handle((bucketing, err) -> {
// your code here
}).join();
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
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getVariables(userId, attributes)
.handle((variables, err) -> {
// your code here
}).join();
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
String userId = "user_id";
String experimentName = "experimentName";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getVariationForExperiment(userId, experimentName, attributes)
.handle((variation, err) -> {
// your code here
}).join();
getVariableValue
Value for given Taplytics Dynamic Variable. If a user is not in an experiment containing the variable, the response is 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
String userId = "user_id";
String varName = "varName";
String defaultValue = "defaultValue";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getVariableValue(userId, varName, defaultValue, attributes)
.handle((value, err) -> {
// your code here
}).join();
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
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getConfig(userId, attributes)
.handle((config, err) -> {
// your code here
}).join();
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
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getFeatureFlags(userId, attributes)
.handle((featureFlags, err) -> {
// your code here
}).join();
isFeatureFlagEnabled
Returns true or false depending on 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
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.isFeatureFlagEnabled(userId, keyName, attributes)
.handle((enabled, err) -> {
if ((Boolean) enabled) {
enableFeature();
}
}).join();
Updated almost 3 years ago