Search in sources :

Example 1 with OptimizelyVariable

use of com.optimizely.ab.optimizelyconfig.OptimizelyVariable 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();
        });
    });
}
Also used : OptimizelyExperiment(com.optimizely.ab.optimizelyconfig.OptimizelyExperiment) OptimizelyVariable(com.optimizely.ab.optimizelyconfig.OptimizelyVariable) OptimizelyConfig(com.optimizely.ab.optimizelyconfig.OptimizelyConfig) OptimizelyAttribute(com.optimizely.ab.optimizelyconfig.OptimizelyAttribute) OptimizelyFeature(com.optimizely.ab.optimizelyconfig.OptimizelyFeature) OptimizelyVariation(com.optimizely.ab.optimizelyconfig.OptimizelyVariation) OptimizelyEvent(com.optimizely.ab.optimizelyconfig.OptimizelyEvent) OptimizelyAudience(com.optimizely.ab.optimizelyconfig.OptimizelyAudience) OptimizelyManager(com.optimizely.ab.android.sdk.OptimizelyManager)

Aggregations

OptimizelyManager (com.optimizely.ab.android.sdk.OptimizelyManager)1 OptimizelyAttribute (com.optimizely.ab.optimizelyconfig.OptimizelyAttribute)1 OptimizelyAudience (com.optimizely.ab.optimizelyconfig.OptimizelyAudience)1 OptimizelyConfig (com.optimizely.ab.optimizelyconfig.OptimizelyConfig)1 OptimizelyEvent (com.optimizely.ab.optimizelyconfig.OptimizelyEvent)1 OptimizelyExperiment (com.optimizely.ab.optimizelyconfig.OptimizelyExperiment)1 OptimizelyFeature (com.optimizely.ab.optimizelyconfig.OptimizelyFeature)1 OptimizelyVariable (com.optimizely.ab.optimizelyconfig.OptimizelyVariable)1 OptimizelyVariation (com.optimizely.ab.optimizelyconfig.OptimizelyVariation)1