Mandatory for using QuickTracking Windows(A/B Testing).
1. Reference and initialize the SDK
Integration Code Details
Before you use the /B Testing SDK, make sure that you have successfully integrated the Windows C++ SDK and initialized the SDK. For more information, see Import and Configure 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.
Offline import method
For more information, see Import and Configure SDK Quick Integration introduction.
2.2 Initialize ABTest SDK
API functions
// Initialize ABTest.
QTFORPC_API QT_VOID initABTest(QT_CSTR serverUrl, QT_MAP options);
Parameter
Header | Data type | Full description | Required |
serverUrl | const char * | Server IP address | Yes |
options | const char * | The property parameter. The parameter must be a JSON literal template string.
| Yes |
Example
std::string abOptions = R"({
"experiment_file_path": "D:\\xxxx\\abcache\\ab_cache.txt",
"update_interval_seconds": 10
})";
qtInterface->initABTest("http://xxxxx", abOptions.c_str());Enable Log Collection
For more information, see Basic Integration.
2.3 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
Description
API name | Scenarios |
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.4 API introduction
ABTest Request Cache Experiment
API functions: fetchABTestFromCache
//ABTest request cache experiment
QTFORPC_API QT_VOID fetchABTestFromCache(QT_CSTR paramName, QT_CSTR valueType, QT_MAP defaultValue, QT_AB_CB handler);Parameter
Header | Data type | Full description | Required |
paramName | const char * | Parameter | Yes |
valueType | const char * | Type
| Yes |
defaultValue | const char * | Default value
| Yes |
handler | void | The callback method, and note that the result returned by result is judged by the normal business logic in the business. | Yes |
Example
qtInterface->fetchABTestFromCache("y_number", "NUMBER", "1", [](const string &result){
std::cout << result << std::endl;
});Note: Make sure that the default values used in the /B offload API are processed properly.
ABTest request server-side experiment
API functions: fetchABTestFromServer
//ABTest Request server-side experiment
QTFORPC_API QT_VOID fetchABTestFromServer(QT_CSTR paramName, QT_CSTR valueType, QT_MAP defaultValue, QT_AB_CB handler, QT_INT timeout_seconds);Parameter
Header | Data type | Full description | Required |
paramName | const char * | Parameter name, non-empty string | Yes |
valueType | const char * | Type
| Yes |
defaultValue | const char * | Default value
| Yes |
handler | void | The callback method, and note that the result returned by result is judged by the normal business logic in the business. | Yes |
timeout_seconds | int | The timeout period. The default timeout period is 3 seconds. | No |
Example
qtInterface->fetchABTestFromServer("y_json", "JSON", R"({"a":1})", [](const string &result){
std::cout << result << std::endl;
}, 3);Note: Make sure that the default values used in the /B offload API are processed properly.
ABTest first requests the local cache experiment results, and then requests the server experiment results if no more
API functions: fetchABTestFromCacheThenServer
//ABTest First request the local cache experiment results, if no more request the server experiment results
QTFORPC_API QT_VOID fetchABTestFromCacheThenServer(QT_CSTR paramName, QT_CSTR valueType, QT_MAP defaultValue, QT_AB_CB handler, QT_INT timeout_seconds);Parameter
Header | Data type | Full description | Required |
paramName | const char * | Parameter | Yes |
valueType | const char * | Type
| Yes |
defaultValue | const char * | Default value
| Yes |
handler | void | The callback method, and note that the result returned by result is judged by the normal business logic in the business. | Yes |
timeout_seconds | int | The timeout period. The default timeout period is 3 seconds. | No |
Example
qtInterface->fetchABTestFromServerThenCache("y_boolean", "BOOLEAN", "false", [](const string &result){
std::cout << result << std::endl;
}, 3);Note: Make sure that the default values used in the /B offload API are processed properly.
3. Commissioning test
After opening the experiment
