use of com.optimizely.ab.optimizelyconfig.OptimizelyConfig 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();
});
});
}
use of com.optimizely.ab.optimizelyconfig.OptimizelyConfig in project android-sdk by optimizely.
the class OptimizelyClientTest method testGetOptimizelyConfig.
@Test
public void testGetOptimizelyConfig() {
assumeTrue(datafileVersion == Integer.parseInt(ProjectConfig.Version.V4.toString()));
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
OptimizelyConfig optimizelyConfig = optimizelyClient.getOptimizelyConfig();
assertNotNull(optimizelyConfig.getExperimentsMap());
assertNotNull(optimizelyConfig.getFeaturesMap());
assertNotNull(optimizelyConfig.getRevision());
assertNotNull(optimizelyConfig.getSdkKey());
assertNotNull(optimizelyConfig.getEnvironmentKey());
assertNotNull(optimizelyConfig.getAttributes());
assertNotNull(optimizelyConfig.getAudiences());
assertNotNull(optimizelyConfig.getEvents());
}
use of com.optimizely.ab.optimizelyconfig.OptimizelyConfig in project android-sdk by optimizely.
the class OptimizelyClientTest method testGetOptimizelyConfigReturnNullWhenConfigIsNull.
@Test
public void testGetOptimizelyConfigReturnNullWhenConfigIsNull() {
assumeTrue(datafileVersion == Integer.parseInt(ProjectConfig.Version.V4.toString()));
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
OptimizelyConfig optimizelyConfig = optimizelyClient.getOptimizelyConfig();
assertNull(optimizelyConfig);
}
use of com.optimizely.ab.optimizelyconfig.OptimizelyConfig in project android-sdk by optimizely.
the class APISamplesInJava method samplesForDoc_NotificatonListener.
public static void samplesForDoc_NotificatonListener(Context context) {
OptimizelyManager optimizelyManager = OptimizelyManager.builder().withSDKKey("FCnSegiEkRry9rhVMroit4").build(context);
OptimizelyClient optimizelyClient = optimizelyManager.initialize(context, R.raw.datafile);
// -- sample starts here
// Add Notification Listener (LogEvent)
int notificationId = optimizelyClient.addLogEventNotificationHandler(logEvent -> {
Log.d("Optimizely", "event dispatched: " + logEvent);
});
// Remove Notification Listener
optimizelyClient.getNotificationCenter().removeNotificationListener(notificationId);
// Remove all Notification Listeners
optimizelyClient.getNotificationCenter().clearAllNotificationListeners();
// Remove all Notification Listeners of a certain type
optimizelyClient.getNotificationCenter().clearNotificationListeners(DecisionNotification.class);
// notification listener types
// -- sample starts here
// SET UP DECISION NOTIFICATION LISTENER
int notificationId1 = optimizelyClient.addDecisionNotificationHandler(notification -> {
// Access type on decisionObject to get type of decision
String decisionType = notification.getType();
if (decisionType == "flag") {
Map<String, ?> flagDecisionInfo = notification.getDecisionInfo();
String flagKey = (String) flagDecisionInfo.get("flagKey");
Boolean enabled = (Boolean) flagDecisionInfo.get("enabled");
Boolean decisionEventDispatched = (Boolean) flagDecisionInfo.get("decisionEventDispatched");
// Send data to analytics provider here
}
});
// SET UP LOG EVENT NOTIFICATION LISTENER
int notificationId2 = optimizelyClient.addLogEventNotificationHandler(notification -> {
// process the logEvent object here (send to analytics provider, audit/inspect data)
});
// SET UP OPTIMIZELY CONFIG NOTIFICATION LISTENER
int notificationId3 = optimizelyClient.addUpdateConfigNotificationHandler(notification -> {
OptimizelyConfig optimizelyConfig = optimizelyClient.getOptimizelyConfig();
});
// SET UP TRACK LISTENER
int notificationId4 = optimizelyClient.addTrackNotificationHandler(notification -> {
// process the event here (send to analytics provider, audit/inspect data)
});
}
Aggregations