use of com.optimizely.ab.android.sdk.OptimizelyManager 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.OptimizelyManager 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.OptimizelyManager 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.OptimizelyManager 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)
});
}
use of com.optimizely.ab.android.sdk.OptimizelyManager in project android-oss by kickstarter.
the class ApplicationModule method provideOptimizely.
@Provides
@Singleton
@NonNull
ExperimentsClientType provideOptimizely(@ApplicationContext @NonNull final Context context, @NonNull final ApiEndpoint apiEndpoint, @NonNull final Build build) {
final OptimizelyEnvironment optimizelyEnvironment;
if (apiEndpoint == ApiEndpoint.PRODUCTION) {
optimizelyEnvironment = OptimizelyEnvironment.PRODUCTION;
} else if (apiEndpoint == ApiEndpoint.STAGING) {
optimizelyEnvironment = OptimizelyEnvironment.STAGING;
} else {
optimizelyEnvironment = OptimizelyEnvironment.DEVELOPMENT;
}
final OptimizelyManager optimizelyManager = OptimizelyManager.builder().withSDKKey(optimizelyEnvironment.getSdkKey()).withDatafileDownloadInterval(15, TimeUnit.MINUTES).withEventDispatchInterval(2L, TimeUnit.MILLISECONDS).build(context);
optimizelyManager.initialize(context, null, optimizely -> {
if (!optimizely.isValid()) {
FirebaseCrashlytics.getInstance().recordException(new Throwable("Optimizely failed to initialize."));
} else {
if (build.isDebug()) {
Timber.d(ApplicationModule.class.getSimpleName(), "🔮 Optimizely successfully initialized.");
}
context.sendBroadcast(new Intent(ExperimentsClientTypeKt.EXPERIMENTS_CLIENT_READY));
}
});
return new OptimizelyExperimentsClient(optimizelyManager, optimizelyEnvironment);
}
Aggregations