Skip to main content

iOS

Last updated 10/02/2026

Latest version: v1.0.2

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 automatically with CocoaPods​

  1. Add the dependency to your project's Podfile:
platform :ios, '9.0'
use_frameworks!

target 'YourApp' do
pod 'TDExperiment', '1.0.2'
end
  1. Run the installation command:
pod install

After the installation completes, open the project with the .xcworkspace file.

2.2 Integrate the SDK manually​

The experiment SDK depends on the following ThinkingData SDKs:

SDK nameOverviewVersion requirement
ThinkingSDKCollects and processes data>= 3.1.6
TDRemoteConfigFetches configuration from the AE backend>= 1.3.1
  1. Click the download link at the top of this page to download the SDK, and then unzip it
  2. Drag ThinkingSDK.xcframework, ThinkingDataCore.xcframework, TDRemoteConfig.xcframework, and TDExperiment.xcframework into your project, and select Embed & Sign (or configure them according to your project's static library strategy)
  3. In Build Settings, make sure that Framework Search Paths includes the paths of the xcframeworks above

3. Initialization​

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

#import <ThinkingSDK/ThinkingSDK.h>
#import <TDExperiment/TDExperiment.h>

// Initialize the data collection SDK
[TDAnalytics startAnalyticsWithAppId:@"APP_ID" serverUrl:@"https://YOUR_SERVER_URL"];

// Initialize the experiment SDK
TDExperimentConfig *config = [[TDExperimentConfig alloc] initWithAppId:@"APP_ID"
serverUrl:@"https://YOUR_SERVER_URL"];
config.automaticExposureTracking = YES;
config.customBucketId = @{ @"bucket_id": @"account_id" };
config.customFetchParams = @{ @"key": @"value" };

TDExperimentTask *startupTask = [[TDExperimentTask alloc] init];
[startupTask addOnSuccessListener:^{
// Experiment configuration fetched successfully
}];
[startupTask addOnFailureListener:^(NSInteger code, NSString *message) {
// Failed to fetch the experiment configuration
}];
config.startupTask = startupTask;

[TDExperiment enableLog:YES];
[TDExperiment startWithConfig:config];

You can also use the simplified startup method:

[TDExperiment startWithAppId:@"APP_ID" serverUrl:@"https://YOUR_SERVER_URL"];

Initialization parameters:

  • appId:APP ID
  • serverUrl: the data receiving URL
  • automaticExposureTracking: defaults to YES. 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
  • startupTask: the callback task for the first fetch of the experiment configuration at startup (registered through addOnSuccessListener / addOnFailureListener)
  • enableLog: whether to enable debug logs (set through TDExperiment.enableLog)

4. Usage​

4.1 Get experiment information​

[TDExperiment getValueAsString:key];
[TDExperiment getValueAsString:key defaultValue:@"default"];

[TDExperiment getValueAsNumber:key];
[TDExperiment getValueAsNumber:key defaultValue:@0];

[TDExperiment getValueAsBoolean:key];
[TDExperiment getValueAsBoolean:key defaultValue:NO];

[TDExperiment getValueAsJson:key];
[TDExperiment getValueAsJson:key defaultValue:@{}];

If automaticExposureTracking is YES, 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:^{
// Success
}]
addOnFailureListener:^(NSInteger code, NSString *message) {
// Failure
}];

4.4 Custom bucket key​

NSDictionary<NSString *, NSString *> *bucketId = @{ @"bucket_id": @"account_id" };
[TDExperiment setCustomBucketId:bucketId];

4.5 Custom request parameters​

NSDictionary<NSString *, NSObject *> *params = @{ @"key": @"value" };
[TDExperiment setCustomFetchParams:params];
Was this page helpful?