Taplytics Java SDK is an sdk to enable features such as Experimentation and Feature Flag functionality.
Get started with Taplytics | View the Javadoc | Commercial License / Terms
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 following:
APIController taplytics = new APIController('API_KEY');
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.
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.
Returns a key/value pairing of all experiments that the user has been segmented into, as well as the variation the users are assigned.
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 |
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getBucketing(userId, attributes)
.handle((bucketing, err) -> {
// your code here
}).join();
All variables and their values for the given user
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 |
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getVariables(userId, attributes)
.handle((variables, err) -> {
// your code here
}).join();
For a given experiment, determine whether or not a user is in the experiment, and in which variation
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 |
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();
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.
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 |
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();
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.
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 |
String userId = "user_id";
JSONObject body = new JSONObject();
JSONObject event = new JSONObject();
event.put("eventName", "event1");
event.put("eventValue", 3);
JSONArray events = new JSONArray();
events.put(event);
body.put("events", events);
taplytics.sendEvent(userId, body)
.handle((response, err) -> {
// your code here
}).join();
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.
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 |
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getConfig(userId, attributes)
.handle((config, err) -> {
// your code here
}).join();
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
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 |
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.getFeatureFlags(userId, attributes
.handle((featureFlags, err) -> {
// your code here
}).join();
Returns true or false depending if the
keyName
provided corresponds to an enabled featureFlag in your Taplytics project
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 |
String userId = "user_id";
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
taplytics.isFeatureFlagEnabled(userId, attributes)
.handle((enabled, err) -> {
if ((Boolean) enabled) {
enableFeature();
}
}).join();