Remote Config and A/B Testing

This integration guide includes selected snippets from the SDK spec documentation. For more detail, always check the spec documentation of your specific SDK.

Remote Config and A/B Testing are two powerful tools to optimize your app experience without code changes or app updates.

The Remote Config and A/B Testing features are available in Countly Enterprise and as an add-on in Flex.

Web Android iOS Node Flutter HarmonyOS React Native Unity Java C++ API Call

Remote Config

Remote Config lets you update how your app works or looks without requiring a new release by fetching dynamic key-value data from your Countly server. These values can be personalized based on user data, ensuring a tailored experience for every user.

To understand how you can leverage Remote Config in your dashboard, check the guide below:

Downloading Values

To turn on automatic Remote Config value downloads during SDK init and device ID changes:

To download Remote Config values directly:

Asynchronous Synchronous
// Before init
Countly.remote_config = true;
config.enableRemoteConfigAutomaticTriggers();
Objective-CSwift
config.enableRemoteConfigAutomaticTriggers = YES;
Countly.init({
  app_key: "APP_KEY",
  url: "SERVER_URL",
  remote_config: true,
});
config.enableRemoteConfigAutomaticTriggers();
// during init
config.remoteConfig.enableAutomaticTriggers();

// or download manually after init
await Countly.sharedInstance().remoteConfig.downloadAllKeys(null);
await Countly.sharedInstance().remoteConfig.downloadOmittingKeys(['key1'], null);
await Countly.remoteConfig.update();

await Countly.remoteConfig.updateForKeysOnly(["key1", "key2"]);
await Countly.remoteConfig.updateExceptKeys(["key1", "key2"]);
await Countly.Instance.RemoteConfigs.Update();
config.enableRemoteConfigAutomaticTriggers();
cly::Countly.getInstance().updateRemoteConfig();

To fetch remote config values from the server:

curl --request POST \
  --url 'https://YOUR_SERVER/o/sdk' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data 'app_key=APP_KEY' \
  --data 'device_id=DEVICE_ID' \
  --data 'method=rc' \
  --data 'keys=["keys","include"]' \ # Optional
  --data 'omit_keys=["keys", "except"]' \ # Optional
  --data 'timestamp=TIMESTAMP' \
  --data 'hour=HOUR' \
  --data 'dow=DAYOFTHEWEEK'

You should expect the responses to be:

# 200
{
  "key1": "value1",
  "key2": "value2",
  ...
}

# 200 - No remote config values
{}

Accessing Values

To use dowloaded Remote Config values:

Asynchronous Synchronous
Countly.q.push(() => { 
  var remoteConfigValues = Countly.get_remote_config();
});
Map<String, RCData> remoteConfigValues = Countly.sharedInstance().remoteConfig().getAllValues();
Objective-C Swift
NSDictionary<NSString*, CountlyRCData*> *remoteConfigValues = [Countly.sharedInstance.remoteConfig getAllValues];
var remoteConfigValues = Countly.get_remote_config();
Map<String, RCData> remoteConfigValues = await Countly.instance.remoteConfig.getAllValues();
const remoteConfig = Countly.sharedInstance().remoteConfig;

const single: RCData | null = remoteConfig.getValue('KeyName');
const all: Record<string, RCData> = remoteConfig.getValues();
const remoteConfigValue = await Countly.remoteConfig.getValue("KeyName");

await Countly.remoteConfig.clearValues();
Dictionary<string, object> remoteConfigValues = Countly.Instance.RemoteConfigs.Configs;
Map<String,RCData> remoteConfigValues = Countly.instance().remoteConfig().getValues();
nlohmann::json remoteConfigValue = cly::Countly.getInstance().getRemoteConfigValue("KeyName");

Remote Config values can either be cached after download for later access or accessed immediately upon download.

If you want to learn more about the feature integration and settings, have a look at the SDK documentation below:

A/B Testing

Building on Remote Config, A/B Testing empowers you to safely experiment with Remote Config values for running tests and measuring results to make data-driven decisions.

To understand how you can leverage A/B Testing in your dashboard, check the guide below:

SDK will automatically enroll eligible users to A/B tests by default.

To turn on automatic test participation upon Remote Config downloads:

config.enrollABOnRCDownload();
Objective-CSwift
config.enrollABOnRCDownload = YES;
config.enrollABOnRCDownload();
// during init
config.remoteConfig.enrollABonDownload();

// or enroll explicitly post-init
await Countly.sharedInstance().remoteConfig.enrollIntoABTestsForKeys(['key1', 'key2']);
config.enrollABOnRCDownload();

To automatically enroll users in A/B Tests when fetching Remote Config values, add the following line to your fetch request:

  --data 'oi=1' \ 

The expected response format is the same as that of a standard fetch request.

If you want to learn more about the feature integration and settings, have a look at the SDK documentation below:

Was this page helpful?
Reach out to us for any other questions.
Helpful?

Looking For More Help?