Skip to main content

How do I get resource A/B test information from the Swrve SDK?

It is now possible to get the resource A/B test and variant IDs directly from the Resource Manager in the Swrve SDK in real-time for use in your third-party reporting systems.

To have this feature enabled for your app, contact your CSM at support@messagegears.com, and then use the following code to get the resource A/B test information from the Resource Manager in the Swrve SDK.

Step 1: Configure the SDK to obtain the AB Test details when initializing.

SwrveConfig config = new SwrveConfig();
config.setABTestDetailsEnabled(true);

Step 2: Obtain the details from the Resource Manager.

List<SwrveABTestDetails> abTestDetailsList = SwrveSDK.getResourceManager().getABTestDetails();
for(SwrveABTestDetails abTestDetails : abTestDetailsList) {
String id = abTestDetails.getId();
String name = abTestDetails.getName();
int caseIndex = abTestDetails.getCaseIndex();
// Your code here
}

Example output​

{
"campaigns" : {
...
"ab_test_details": {
...
"102": {
"name": "AB Test Example",
"case_index": 3
}
}
},
}

Output values​

The highlighted lines in the above example are the exposed A/B test information and include the following details:

  • name - displays the A/B test ID and name that was given to the A/B test when it was created.
  • case_index - displays the A/B test case index. The case index indicates the A/B test treatment the user has been exposed to, with a number from 0 to N-1, where N is the total number of variants in the test. For example, in a test with three variants, the possible values would be 0, 1, 2.