Search in sources :

Example 16 with OptimizelyClient

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>");
    });
}
Also used : OptimizelyDecision(com.optimizely.ab.optimizelydecision.OptimizelyDecision) OptimizelyClient(com.optimizely.ab.android.sdk.OptimizelyClient) OptimizelyUserContext(com.optimizely.ab.OptimizelyUserContext) OptimizelyManager(com.optimizely.ab.android.sdk.OptimizelyManager)

Example 17 with OptimizelyClient

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");
    });
}
Also used : OptimizelyClient(com.optimizely.ab.android.sdk.OptimizelyClient) OptimizelyManager(com.optimizely.ab.android.sdk.OptimizelyManager)

Example 18 with OptimizelyClient

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);
}
Also used : OptimizelyClient(com.optimizely.ab.android.sdk.OptimizelyClient) OptimizelyManager(com.optimizely.ab.android.sdk.OptimizelyManager)

Example 19 with OptimizelyClient

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)
    });
}
Also used : OptimizelyConfig(com.optimizely.ab.optimizelyconfig.OptimizelyConfig) OptimizelyClient(com.optimizely.ab.android.sdk.OptimizelyClient) OptimizelyManager(com.optimizely.ab.android.sdk.OptimizelyManager)

Aggregations

OptimizelyClient (com.optimizely.ab.android.sdk.OptimizelyClient)19 OptimizelyManager (com.optimizely.ab.android.sdk.OptimizelyManager)19 OptimizelyUserContext (com.optimizely.ab.OptimizelyUserContext)14 OptimizelyDecision (com.optimizely.ab.optimizelydecision.OptimizelyDecision)12 HashMap (java.util.HashMap)8 OptimizelyJSON (com.optimizely.ab.optimizelyjson.OptimizelyJSON)4 JsonParseException (com.optimizely.ab.config.parser.JsonParseException)3 OptimizelyDecideOption (com.optimizely.ab.optimizelydecision.OptimizelyDecideOption)3 OptimizelyDecisionContext (com.optimizely.ab.OptimizelyDecisionContext)1 OptimizelyForcedDecision (com.optimizely.ab.OptimizelyForcedDecision)1 DefaultEventHandler (com.optimizely.ab.android.event_handler.DefaultEventHandler)1 Variation (com.optimizely.ab.config.Variation)1 BatchEventProcessor (com.optimizely.ab.event.BatchEventProcessor)1 EventHandler (com.optimizely.ab.event.EventHandler)1 OptimizelyConfig (com.optimizely.ab.optimizelyconfig.OptimizelyConfig)1 OptimizelyVariation (com.optimizely.ab.optimizelyconfig.OptimizelyVariation)1