Split Testing Android Apps with Firebase Remote Config

Ryan Burnsworth
4 min readOct 3, 2018

Recently, in my role as an Android software engineer at WriteADay, I was tasked with learning to implement A/B Testing with Firebase Remote Config and Firebase Analytics. I have some experience with split testing website changes using Google Analytics and this is not much different.

With Firebase RemoteConfig we can store configuration values in the cloud and control which of our app users these affect. Along with Analytics data this allows us to test changes in our apps.

Setting Up Firebase RemoteConfig

To get started we must first add Firebase to our project. If you haven’t done this yet and need a walk-through on this process visit https://firebase.google.com/docs/android/setup

Once Firebase has been added to the project you can implement Remote Config in your app module’s build.gradle.

implementation 'com.google.firebase:firebase-config:16.0.0'

Define Your Variants

Decide on what feature or features you want to experiment with. It can be a message, a font size, a color change, a different image, etc. In this example we will setup 3 configurations. One to decide whether or not to display an image, one to set the background color of our container and another to change the message in a text view.

To get started we will declare a new xml file called remote_config.xml. This key/value map style format will hold the default local configuration. We will store this file in the res/xml directory. If you don’t have an xml directory, feel free to create one under res.

remote_config.xml

The Use Of Consistent Key Naming

When using Firebase Remote Config we must use consistent naming for our keys. In the above remote_config.xml file we set key names: message, display_image, and bgcolor. These key names must be the same in Firebase and we will use them when setting configuration changes in the app. So let’s use a RemoteConfigKeys class to store these names.

RemoteConfigKeys.java

Using a RemoteConfig POJO

For this example I am using a POJO class to get and set the remote config values for the app. Firebase RemoteConfig returns types: boolean, long, double, String and byteArray. So try not to look for Integer values when using Remote Config unless you plan to use a conversion method.

RemoteConfig.java

Create Your RemoteConfigClient class

The RemoteConfigClient class will be used to call Firebase RemoteConfig and set our configuration values.

RemoteConfigClient.java

Using Remote Config Data In Your Activity

In this sample case I am setting the background color of the container, the text within the textview and setting the visibility of the image remotely.

MainActivity.java

Running The App With Only Default Local Configuration

When running the app with only local configuration setup the values from the remote_config.xml are used. This is the same for users that are not chosen to be in the experimental group. To test your local configuration simply comment out the line firebaseRemoteConfig.activateFetched().

Setting Up Remote Config on Firebase

On the Firebase website in the left-hand column under the Grow section will be Remote Config. Here is where the remote configuration can be set. Remember that the keys must have a matching naming convention as the app.

Running the app and using the remote config shows this:

Setting Up Firebase A/B Experiments

You can setup an experiment from the Remote Config menu options in Firebase Console. Click on the edit icon for the configuration value you want to experiment with.

Here you will setup the number or percentage of users that will be in your control group and your variation group. You will also setup what variations these users will see and what your goals are for these changes.

Split testing can have a profoundly positive impact on your business. It gives insight into what your users truly enjoy and don’t enjoy. I hope this article helps you get started. You can view the complete project on GitHub.

--

--

Ryan Burnsworth

Senior Software Engineer currently adding AI/ML skills to my toolkit. I enjoy things all things engineering.