Essential for using QuickTracking Android(A/B Testing).
Basic SDK information
File Name | Version number | md5 | File Size |
QuickTracking ABTest SDK | 1.1.0 Update logs: SDK for Android | 118558e221e439f429c05d61200037ed | 61KB |
1. Integration code details
The A/B Testing SDK depends on Android SDK V1.6.4 or later. Before you use the Quick Tracking SDK, make sure that you have successfully integrated the Quick Tracking SDK and initialized the SDK. For more information, see Introduction and configuration of the SDK.
2. Programming experiment
2.1 integration and initialization
You must initialize the Quick Tracking SDK in synchronous mode. After you initialize the QuickTracking statistics SDK, initialize the QuickTracking A/B Testing SDK. When you initialize the Quick Tracking A/B Testing SDK, you must specify the URL of the request diversion test. Contact the operation personnel to obtain the URL.
2.1.1 Synchronous introduction method
Add the QT A/B Testing SDK dependency to the build.gradle module in the file:
Online package:
dependencies {
implementation fileTree(include:['*.jar'], dir:'libs')
// QuickTracking statistical analysis SDK
implementation 'com.lydaas.qtsdk:qt-px-common:1.8.6.PX'
// QuickTracking A/B Test SDK
implementation 'com.lydaas.qtsdk:qt-ab-test:1.1.0'
}Local package:
dependencies {
implementation fileTree(include:['*.jar'], dir:'libs')
// QuickTracking statistical analysis SDK
implementation files('libs/qt-px-common-1.8.6.PX.aar')
// QuickTracking A/B Test SDK
implementation files('libs/QTABTest-release.aar')
}2.1.2 SDK initialization
To initialize the dependency ApplicationContext, specify the following parameters when appropriate:
import com.quicktracking.sdk.android.abtest.QTABTest;
import com.quicktracking.sdk.android.abtest.QTABTestConfigOptions;
try {
// Initialize the QT A/B testing SDK --- Completely rely on the collection SDK to report data.
QTABTestConfigOptions config=new QTABTestConfigOptions("Your receiving service address /abtest_results?appkey=xxxxx");
// Initialization of QT A/B Testing SDK --- Incomplete dependency collection SDK reporting data, only AB experiment is used
QTABTestConfigOptions config=new QTABTestConfigOptions("Your receiving service address /abtest_results?appkey=xxxxx",10 * 60 * 1000,"Custom device ID", new IQTABTestPropertyChanged() {
@Override
public void onPropertyChanged(JSONArray abParams) {
Log.d("ABTest", "onPropertyChanged: " + abParams.toString());
}
});
// You must specify the Context parameter for initialization.
QTABTest.startWithConfigOptions(this.getApplicationContext(), config);
} catch (Exception e) {
e.printStackTrace();
}
Configuration method:
public QTABTestConfigOptions(String url,int timeInterval)
public QTABTestConfigOptions(String url)
public QTABTestConfigOptions(String url,int timeInterval, String customDeviceId, IQTABTestPropertyChanged iQTABTestPropertyChanged)Parameters | Type | Default Value | Meaning | Remarks |
url | string | undefined | Experiment Address | Required parameter. You must set a non-empty string. |
timeInterval | int | 10 * 60 *1000 | Cache Update Frequently (ms) Maximum value: 30 * 60 * 1000 Minimum value: 10 * 1000 | Optional |
custom_id | string | undefined | Custom device ID (used when only the AB experiment is connected but not the acquisition module) | Optional |
iQTABTestPropertyChanged | IQTABTestPropertyChanged | undefined | AB parameter change callback | Optional |
import com.quicktracking.sdk.android.abtest;
/**
* Defines an interface IQTABTestPropertyChanged that is used to listen to property change events.
*
* <p> This interface contains a method {@link #onPropertyChanged(JSONArray)}, which will be called when the property changes.
*
* @see JSONArray
*/
public interface IQTABTestPropertyChanged {
/**
* The callback method that is triggered when a property changes.
*
* @param abParams A JSON array that contains information about attribute changes.
* This parameter is usually used to pass the specific data or context information of the property change.
*/
void onPropertyChanged(JSONArray abParams);
}2.1.3 Obfuscation configuration
If your application uses code obfuscation, add the following configurations to prevent the use of the Quick Tracking and A/B Testing SDKs from being incorrectly obfuscated.
-keep class com.umeng.** {*;}
-keep class org.repackage.** {*;}
-keep class com.quick.qt.** {*;}
-keep class rpk.quick.qt.** {*;}
# for AB
-keep class com.quicktracking.sdk.android.abtest.** {*;}
-keepclassmembers class * {
public <init> (org.json.JSONObject);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}2.2 acquisition of experimental variables
Initialize the QuickTracking ABTest SDK, through the API to obtain a specific test variable value, according to the test variable value of the way, can be divided into the following three strategies:
fetchABTestFromCache: Read the local cache. If the cache does not exist, the default value is used.
fetchABTestFromServer: Ignore local cache and get data from server
fetchABTestFromCacheThenServer: First read the local cache, cache does not exist from the server to obtain data
2.2.1 Scenarios
API Name | Scenario description |
fetchABTestFromCache | If you have requirements on query performance, you can use fetchABTestFromCache API to obtain variable values only from the local cache. The disadvantage is that the latest experimental results cannot be hit in time. |
fetchABTestFromServer | If you want to perform a time slice rotation experiment and have requirements on the timeliness of the experiment, you can use fetchABTestFromServer API to obtain the experimental variable values. The disadvantage is that there may be a certain network latency. |
fetchABTestFromCacheThenServer | By default, we recommend that you use this API to take into account the query performance and timeliness. This API preferentially obtains variable values from the local cache. If the local cache does not hit the result, the latest data of the AB experiment server is queried. |
2.3API Introduction
fetchABTestFromCache
/**
* Get test results from the cache
*
* @param paramName The name of the parameter.
* @param defaultValue The default value.
* @param <T> The type of the return value.
* @return the t
*/
<T> T fetchABTestFromCache(String paramName, T defaultValue);request parameters
Parameters | Type | Default Value | Meaning | Remarks |
param_name | string | undefined | Experiment Parameter Name | Required parameter. You must set a non-empty string. |
default_value | String | Boolean | Integer | JSONObject | undefined | Default result values for experiment parameters | Required parameters, which must be consistent with the current experimental value result type. If the experiment value corresponding to the parameter is of the NUMBER type, the input default_value must also be of the number type, and the returned result experiment result is also of the number type. |
Note: Make sure that the default values used in the /B offload interface are processed properly.
Return Result
Parameters | Type | Default Value | Meaning | Remarks |
<T> T | String | Boolean | Integer | JSONObject | undefined | Experimental parameter result value | the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business. |
Usage example
import com.quicktracking.sdk.android.abtest.QTABTest;
// The request returns a String parameter.
String result = QTABTest.shareInstance().fetchABTestFromCache("param_string", "test");
// The Boolean parameter returned for the request.
Boolean result = QTABTest.shareInstance().fetchABTestFromCache(getTextValue(), false);
// The number parameter returned by the request.
Integer result = QTABTest.shareInstance().fetchABTestFromCache(getTextValue(), 1);
// The request returns the JSONObject parameter.
try{
JSONObject result = QTABTest.shareInstance().fetchABTestFromCache(getTextValue(), null);
}catch (Exception e){
}fetchABTestFromServer
/**
* Request test results from the network
*
* @param <T> The default value type.
* @param paramName The name of the parameter.
* @param The timeoutMillSeconds timeout period (in milliseconds).
* @param defaultValue The default value.
* @param callback The callback operation.
*/
<T> void fetchABTestFromServer(String paramName, int timeoutSeconds, T defaultValue, OnABTestResultCallBack<T> callback);Request Parameters
Option | Parameter | Default value: | Description | Remarks |
paramName | string | undefined | Experiment Parameter Name | Required parameter. You must set a non-empty string. |
timeoutSeconds | int | 3000 | The server request timeout period of the shunt experiment. | Required parameters |
defaultValue | String | Boolean | Integer | JSONObject | undefined | Default result values for experiment parameters | Required parameters, which must be consistent with the current experimental value result type. If the experiment value corresponding to the parameter is of the NUMBER type, the input default_value must also be of the number type, and the returned result experiment result is also of the number type. |
<T> T | String | Boolean | Integer | JSONObject | undefined | Experimental parameter result value | the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business. |
callback | Function | None | Shunt experiment result value callback function | Required parameters |
Callback description:
import com.quicktracking.sdk.android.abtest.OnABTestResultCallBack;
public interface OnABTestResultCallBack<T> {
/**
* Request callback
*
* @param result <T> Default value type
*/
void onResult(T result);
}Return parameters:
Parameters | Type | Default Value | Meaning | Remarks |
<T> T | String | Boolean | Integer | JSONObject | undefined | Experimental parameter result value | the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business. |
Note: Make sure that the default values used in the /B offload interface are processed properly.
Return Result
Parameters | Type | Default Value | Meaning | Remarks |
result | String | Boolean | Integer | JSONObject | undefined | Experimental parameter result value | the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business. |
Usage example
import com.quicktracking.sdk.android.abtest.OnABTestResultCallBack;
import com.quicktracking.sdk.android.abtest.QTABTest;
QTABTest.shareInstance().fetchABTestFromServer("", 10 * 1000, null, new OnABTestResultCallBack<JSONObject>() {
@Override
public void onResult(JSONObject result) {
refreshLogView(result.toString());
}
});fetchABTestFromCacheThenServer
/**
* If there is a local cache, the cached data is returned; otherwise, the latest test data is requested from the network, and the timeout period can be customized.
*
* @param <T> The default value type.
* @param paramName The name of the parameter.
* @param timeout The timeout period.
* @param defaultValue The default value.
* @param callback The callback operation.
*/
<T> void fetchABTestFromCacheThenServer(String paramName, int timeout, T defaultValue, OnABTestResultCallBack<T> callback);request parameters
Parameters | Type | Default Value | Meaning | Remarks |
paramName | string | undefined | Experiment Parameter Name | Required parameter. You must set a non-empty string. |
timeoutSeconds | int | 3000 | The server request timeout period of the shunt experiment. | Required parameters |
defaultValue | String | Boolean | Integer | JSONObject | undefined | Default result values for experiment parameters | Required parameters, which must be consistent with the current experimental value result type. If the experiment value corresponding to the parameter is of the NUMBER type, the input default_value must also be of the number type, and the returned result experiment result is also of the number type. |
<T> T | String | Boolean | Integer | JSONObject | undefined | Experimental parameter result value | the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business. |
callback | Function | None | Shunt experiment result value callback function | Required parameters |
Callback description:
import com.quicktracking.sdk.android.abtest.OnABTestResultCallBack;
public interface OnABTestResultCallBack<T> {
/**
* Request callback
*
* @param result <T> Default value type
*/
void onResult(T result);
}Return parameters:
Parameters | Type | Default Value | Meaning | Remarks |
<T> T | String | Boolean | Integer | JSONObject | undefined | Experimental parameter result value | the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business. |
Note: Make sure that the default values used in the /B offload interface are processed properly.
Return Result
Parameters | Type | Default Value | Meaning | Remarks |
result | String | Boolean | Integer | JSONObject | undefined | Experimental parameter result value | the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business. |
Usage example
import com.quicktracking.sdk.android.abtest.OnABTestResultCallBack;
import com.quicktracking.sdk.android.abtest.QTABTest;
QTABTest.shareInstance().fetchABTestFromCacheThenServer("param_json", 10 * 1000, null, new OnABTestResultCallBack<JSONObject>() {
@Override
public void onResult(JSONObject result) {
}
});3. Debug the experiment
After opening the experiment

When log is enabled, the corresponding experiment list will be printed out.
