Rollouts

The Rollouts Developer Hub

Welcome to the Rollouts developer hub. You'll find comprehensive guides and documentation to help you start working with Rollouts as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Android

Quickstart guide for Optimizely Rollouts

Welcome to the quickstart guide for Optimizely's Android SDK. The instructions below will help you implement Rollouts and launch your first feature flag.

This guide will help you:

  1. Install the SDK
  2. Instantiate Optimizely when your app starts
  3. Create a feature flag
  4. Roll out the feature

1. Install the Android SDK

The Android SDK packages are available on Bintray android-sdk using JCenter repository.

To add the android-sdk and all modules to your project, include this line in your app's build.gradle in the dependencies block:

implementation 'com.optimizely.ab:android-sdk:3.0.0'
repositories {
  jcenter()
}

dependencies {
  compile ('com.optimizely.ab:android-sdk:3.0.0') {
      // exclude default implementation of slf4j if you want to provide 
      // your own.  Multidex can fail if you have more than one 
      // implementation present. If you are having a multidex error
      // this is most likely the issue.
      exclude group: 'com.noveogroup.android', module:'android-logger'
  }
}

The full source code is at https://github.com/optimizely/android-sdk.

2. Configure Optimizely when your application starts

  1. Find your SDK Key by navigating to Settings > Environments.
Click to enlarge

Click to enlarge

  1. Create a manager object by supplying your SDK Key to the withSDKKey method as in the sample below. We recommend placing the resulting manager object on the Application Context so it is available throughout your application.
// In your Application#onCreate
import com.optimizely.ab.android.sdk.OptimizelyManager;
import com.optimizely.ab.android.sdk.OptimizelyClient;
import com.optimizely.ab.android.sdk.OptimizelyStartListener;

// Build a manager and place on your Application Context
OptimizelyManager optimizelyManager = OptimizelyManager.builder()
    .withSDKKey("<Your_SDK_Key>")
    .withDatafileDownloadInterval(60L * 10L) // 10 min polling interval
    .build(getApplicationContext());

optimizelyManager.initialize(this, null, new OptimizelyStartListener() {
    @Override
    public void onStart(OptimizelyClient optimizelyClient) {
      Boolean enabled = optimizelyClient.isFeatureEnabled('new_feature', 'user123');
    }
});

The manager handles getting the datafile, which includes all the configuration of your feature flags. The manager also handles instantiating the Optimizely client.

The manager also includes support for datafile polling to automatically update your feature rollout configuration on a regular interval while the application is in the foreground.

The above sample shows an asynchronous initialization of the Optimizely client. You can also initialize Optimizely synchronously as well.

3. Create a feature flag

Choose a feature in your app to turn on and off with a feature flag. For your first flag, consider starting with a link or visual element that's simple to change, show, or hide based on a Boolean.

To set up your first feature flag, navigate to Features > Create New Feature.

Here's how to set it up:

Click to enlarge.

Click to enlarge.

Use the getOptimizely method to return the most updated optimizelyClient instance.

After saving your feature flag, use the Boolean Is Feature Enabled function on the optimizelyClient instance to show, hide, or change some visual part of your application. Note: you should see a value of false from this function because you haven't rolled out the feature yet. You'll turn it on in the next step.

OptimizelyClient optimizelyClient = optimizelyManager.getOptimizely();

// Evaluate a feature flag and a variable
Boolean enabled = optimizelyClient.isFeatureEnabled('new_feature', 'user123');

The UserID enables you to create consistent experiences for a user across multiple visits, but you don't need it for this quickstart. Make the userID any non-null string for now.

4. Roll the feature out

In Optimizely, navigate back to Features and select your feature flag.

You'll return to this feature whenever you want to update the feature flag. For example, roll out your feature incrementally by moving the slider up by 10% per day or show it to a certain group of users. Move it to 100% for a big reveal, or 0% if issues arise in production. No code deployment necessary.

A basic way to confirm that your feature flag is working in development:

Show the feature to yourself

  1. Navigate to your feature.
  2. Toggle it ON and move the slider to 100% traffic. Click Save.
  3. Confirm that you see the feature.

Hide the feature from yourself

  1. Navigate back to the feature.
  2. Toggle it OFF. Click Save.
  3. Confirm that you no longer see the feature.

When you're ready, go ahead and launch your feature in production. Come back and change its configuration any time, without deploying code.



Android


Quickstart guide for Optimizely Rollouts

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.