Skip to main content

Android

Last updated 10/07/2026

Latest version: v1.0.1

Update time: 2026-07-24

Downloads: Download

1. Overview​

Starting from version 6.1, AE adds the experiment suite feature. You can create experiments in the AE backend, set the variable values for the control group and experiment groups, and pull them to your app through the client SDK to show different content to users in different groups.

This article describes how to integrate the client SDK. On the app side, you only need to handle interactions with the ThinkingData SDK and don't need to care about task details in the AE backend.

Note that the experiment SDK must be used together with the Config Center SDK.

2. Integration​

2.1 Integrate the SDK automatically​

  1. Add the following dependency configuration to the build.gradle file at the Project level
buildscript {
repositories {
jcenter()
mavenCentral()
}
}
  1. Add the dependency to the build.gradle file in the module directory:
dependencies {
implementation 'cn.thinkingdata.android:TDExperiment:1.0.1'
}

2.2 Integrate the SDK manually​

Config Center depends on the following ThinkingData SDKs:

SDK nameDescriptionVersion requirement
TDAnalyticsCollects and processes data>= 3.3.6
TDRemoteConfigFetches configuration from the AE backend>= 1.3.0

1. Click the download link at the top of this page to download the SDK, and then unzip it

2. Add TDAnalytics.aar, TDCore.aar, TDRemoteConfig.aar, and TDExperiment.aar to the libs folder

3. Add the following configuration to build.gradle

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
}

3. Initialization​

The experiment SDK must be used together with the analytics SDK. Initialize TDAnalytics first, and then initialize the experiment SDK.

// Initialize the data collection SDK
TDAnalytics.init(context, "APP_ID", "https://YOUR_SERVER_URL");

// Initialize the experiment SDK
TDExperimentConfig config = new TDExperimentConfig("APP_ID", "https://YOUR_SERVER_URL");
config.automaticExposureTracking = true;
config.customBucketId = new HashMap<>();
config.customFetchParams = new JSONObject();
config.initCallback = new TDCallback() {
@Override
public void onFetchSuccess() {
// Experiment configuration fetched successfully
}

@Override
public void onError(int code, String message) {
// Failed to fetch the experiment configuration
}
};
TDExperiment.enableLog(true);
TDExperiment.init(context, config);

Initialization parameters:

  • appId:APP ID
  • serverUrl: the data receiving URL
  • automaticExposureTracking: defaults to true. Exposure events are uploaded automatically when you call get to retrieve experiment parameters
  • customBucketId: the custom bucket key
  • customFetchParams: custom parameters on the client config channel
  • enableLog: whether to enable debug logs (set through TDExperiment.enableLog)
  • initCallback.onFetchSuccess: the experiment configuration is fetched successfully
  • initCallback.onError: the experiment configuration fails to be fetched

4. Usage​

4.1 Get experiment information​

TDExperiment.getValueAsString(key);

TDExperiment.getValueAsDouble(key);

TDExperiment.getValueAsBoolean(key);

TDExperiment.getValueAsJson(key);

If automaticExposureTracking is true, exposure events are uploaded automatically when you call get.

4.2 Upload exposure events​

You can call the exposure method to upload exposure events manually.

TDExperiment.exposure(key);

4.3 Proactively fetch all experiment information​

TDExperiment.fetch();

TDExperiment.fetch().addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess() {
// Success
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(int code, String msg) {
// Failure
}
});

4.4 Custom bucket key​

Map<String, String> bucketId = new HashMap<>();
bucketId.put("bucket_id", "account_id");
TDExperiment.setCustomBucketId(bucketId);

4.5 Custom request parameters​

JSONObject params = new JSONObject();
params.put("key", "value");
TDExperiment.setCustomFetchParams(params);
Was this page helpful?