Unity
Latest version: v1.0.0
Update time: 2026-08-04
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 Unity 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
Unity Package Manager doesn't support declaring Git dependencies in a package's package.json, so you need to add the analytics SDK, the Config Center SDK, and the experiment SDK together in the Packages/manifest.json of the host project:
- Add the following dependencies to
Packages/manifest.json
{
"dependencies": {
"com.thinkingdata.analytics": "https://github.com/ThinkingDataAnalytics/unity-sdk.git",
"com.thinkingdata.remoteconfig": "https://github.com/ThinkingDataAnalytics/tdremoteconfig-unity.git",
"com.thinkingdata.experiment": "https://github.com/ThinkingDataAnalytics/tdexperiment-unity.git"
}
}
You can also add them one by one in Package Manager → Add package from git URL.
2.2 Integrate the SDK manually
The experiment SDK depends on the following ThinkingData SDKs:
| SDK name | Overview | Version requirement |
|---|---|---|
| TDAnalytics | Collects and processes data | >= 3.5.0 |
| TDRemoteConfig | Fetches configuration from the AE backend | >= 1.2.4 |
- Click the download link at the top of this page to download the SDK, and then unzip it
- First import the unitypackages for the analytics SDK and the Config Center SDK
- Then import
ta_experiment_sdk.unitypackageandta_core_sdk.unitypackage
3. Initialization
The experiment SDK must be used together with the analytics SDK. Initialize TDAnalytics first, and then initialize the experiment SDK.
using System.Collections.Generic;
using ThinkingData.Analytics;
using ThinkingData.Experiment;
// Initialize the data collection SDK
TDAnalytics.Init("APP_ID", "https://YOUR_SERVER_URL");
// Initialize the Experiment SDK
TDExperimentSettings settings = new TDExperimentSettings();
settings.appId = "APP_ID";
settings.serverUrl = "https://YOUR_SERVER_URL";
settings.automaticExposureTracking = true;
settings.customBucketId = new Dictionary<string, string>();
settings.customFetchParams = new Dictionary<string, object>();
settings.initCallback = new MyInitCallback();
TDExperiment.EnableLog(true);
TDExperiment.Init(settings);
// You can also use the simplified initialization
// TDExperiment.Init("APP_ID", "https://YOUR_SERVER_URL");
class MyInitCallback : TDExperimentFetchListener
{
public void OnFetchSuccess()
{
// Experiment configuration fetched successfully
}
public void OnError(int code, string message)
{
// Failed to fetch the experiment configuration
}
}
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);
All of the methods above provide overloads with default values, for example TDExperiment.GetValueAsString(key, "default").
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(new MyFetchCallback());
class MyFetchCallback : TDExperimentFetchListener
{
public void OnFetchSuccess()
{
// Success
}
public void OnError(int code, string message)
{
// Failure
}
}
4.4 Custom bucket key
Dictionary<string, string> bucketId = new Dictionary<string, string>();
bucketId["bucket_id"] = "account_id";
TDExperiment.SetCustomBucketId(bucketId);
4.5 Custom request parameters
Dictionary<string, object> fetchParams = new Dictionary<string, object>();
fetchParams["key"] = "value";
TDExperiment.SetCustomFetchParams(fetchParams);

