use of com.optimizely.ab.android.sdk.OptimizelyClient in project android-sdk by optimizely.
the class APISamplesInJava method samplesForDoc_InitializeSDK.
public static void samplesForDoc_InitializeSDK(Context context) {
// -- sample starts here
// Build a manager
OptimizelyManager optimizelyManager = OptimizelyManager.builder().withSDKKey("<Your_SDK_Key>").withDatafileDownloadInterval(15, TimeUnit.MINUTES).withEventDispatchInterval(30, TimeUnit.SECONDS).build(context);
// Instantiate a client synchronously with a bundled datafile
String datafile = "REPLACE_WITH_YOUR_DATAFILE";
OptimizelyClient optimizelyClient = optimizelyManager.initialize(context, datafile);
// Or, instantiate it asynchronously with a callback
optimizelyManager.initialize(context, null, (OptimizelyClient client) -> {
// flag decision
OptimizelyUserContext user = client.createUserContext("<User_ID>");
OptimizelyDecision decision = user.decide("<Flag_Key>");
});
}
use of com.optimizely.ab.android.sdk.OptimizelyClient in project android-sdk by optimizely.
the class APISamplesInJava method samplesForDoc_DatafilePolling.
public static void samplesForDoc_DatafilePolling(Context context) {
// -- sample starts here
// Poll every 15 minutes
OptimizelyManager optimizelyManager = OptimizelyManager.builder().withSDKKey("<Your_SDK_Key>").withDatafileDownloadInterval(15, TimeUnit.MINUTES).build(context);
// datafile notifiation
OptimizelyClient optimizelyClient = optimizelyManager.initialize(context, R.raw.datafile);
// -- sample starts here
optimizelyClient.addUpdateConfigNotificationHandler(notification -> {
Log.d("Optimizely", "got datafile change");
});
}
use of com.optimizely.ab.android.sdk.OptimizelyClient in project android-sdk by optimizely.
the class APISamplesInJava method samplesForDoc_EventBatchingDefault.
public static void samplesForDoc_EventBatchingDefault(Context context) {
// -- sample starts here
OptimizelyManager optimizelyManager = OptimizelyManager.builder().withSDKKey("<Your_SDK_Key>").build(context);
OptimizelyClient optimizely = optimizelyManager.initialize(context, R.raw.datafile);
}
use of com.optimizely.ab.android.sdk.OptimizelyClient 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