use of com.optimizely.ab.optimizelyconfig.OptimizelyVariation in project android-sdk by optimizely.
the class APISamplesInJava method samplesForOptimizelyConfig.
public static void samplesForOptimizelyConfig(Context context) {
OptimizelyManager optimizelyManager = OptimizelyManager.builder().withSDKKey("FCnSegiEkRry9rhVMroit4").build(context);
optimizelyManager.initialize(context, R.raw.datafile, optimizelyClient -> {
// -- sample starts here
OptimizelyConfig config = optimizelyClient.getOptimizelyConfig();
Log.d("Optimizely", "[OptimizelyConfig] revision = " + config.getRevision());
Log.d("Optimizely", "[OptimizelyConfig] sdkKey = " + config.getSdkKey());
Log.d("Optimizely", "[OptimizelyConfig] environmentKey = " + config.getEnvironmentKey());
Log.d("Optimizely", "[OptimizelyConfig] attributes:");
for (OptimizelyAttribute attribute : config.getAttributes()) {
Log.d("Optimizely", "[OptimizelyAttribute] -- (id, key) = " + attribute.getId() + ", " + attribute.getKey());
}
Log.d("Optimizely", "[OptimizelyConfig] audiences:");
for (OptimizelyAudience audience : config.getAudiences()) {
Log.d("Optimizely", "[OptimizelyAudience] -- (id, name, conditions) = " + audience.getId() + ", " + audience.getName() + ", " + audience.getConditions());
}
Log.d("Optimizely", "[OptimizelyConfig] events:");
for (OptimizelyEvent event : config.getEvents()) {
Log.d("Optimizely", "[OptimizelyEvent] -- (id, key, experimentIds) = " + event.getId() + ", " + event.getKey() + ", " + Arrays.toString(event.getExperimentIds().toArray()));
}
// all features
for (String flagKey : config.getFeaturesMap().keySet()) {
OptimizelyFeature flag = config.getFeaturesMap().get(flagKey);
for (OptimizelyExperiment experiment : flag.getExperimentRules()) {
Log.d("Optimizely", "[OptimizelyExperiment] -- Experiment Rule Key: " + experiment.getKey());
Log.d("Optimizely", "[OptimizelyExperiment] -- Experiment Audiences: " + experiment.getAudiences());
Map<String, OptimizelyVariation> variationsMap = experiment.getVariationsMap();
for (String variationKey : variationsMap.keySet()) {
OptimizelyVariation variation = variationsMap.get(variationKey);
Log.d("Optimizely", "[OptimizelyVariation] -- variation = { key: " + variationKey + ", id: " + variation.getId() + ", featureEnabled: " + variation.getFeatureEnabled() + " }");
// use variation data here...
Map<String, OptimizelyVariable> optimizelyVariableMap = variation.getVariablesMap();
for (String variableKey : optimizelyVariableMap.keySet()) {
OptimizelyVariable variable = optimizelyVariableMap.get(variableKey);
Log.d("Optimizely", "[OptimizelyVariable] -- variable = key: " + variableKey + ", value: " + variable.getValue());
// use variable data here...
}
}
}
for (OptimizelyExperiment delivery : flag.getDeliveryRules()) {
Log.d("Optimizely", "[OptimizelyExperiment] -- Delivery Rule Key: " + delivery.getKey());
Log.d("Optimizely", "[OptimizelyExperiment] -- Delivery Audiences: " + delivery.getAudiences());
}
// use experiments and other feature flag data here...
}
// listen to OPTIMIZELY_CONFIG_UPDATE to get updated data
optimizelyClient.getNotificationCenter().addNotificationHandler(UpdateConfigNotification.class, handler -> {
OptimizelyConfig newConfig = optimizelyClient.getOptimizelyConfig();
});
});
}
Aggregations