Grow

How to Perform A/B Test Using Firebase with Remote Config

Pinterest LinkedIn Tumblr



Have you ever wished you could have done A/B testing with your life as your girlfriend A is better than girlfriend B? ๐Ÿ˜‚

Apologies ladies and gentlemen, but the good news is that you can perform A/B testing using Firebase with Remote Config on your app. ๐Ÿค–

With the feature, you can test any tiny changes like the placement of a button, whether you have to send notification or not, the flow of an application, etc.

Related: How to Send Push Notifications With Firebase in Android (Visual Guide)

But it’s hard to know whether you are doing good or bad?

Right?

Of course, you can ask your girlfriend to ask about the changes you’ve made, that’s pretty time-consuming.

But the best way to find is to run the A/B test with Firebase Remote Config.

How Does It Work?

Basically, Firebase Testing runs on Remote Config which is a cloud service that lets you change the behavior and appearance of your app without requiring users to download an app update.

Decide user’s from the console. Firebase split your app into different groups and make sure that they are seeing the right version of your app.

Afterward, Firebase analyzes your app data you get back using some sophisticated Bayesian statistics, so you can be confident that the data you are seeing is not just a random chance.
Mobile Apps Category (English)300x250
Once the A/B test determines the winner you can you can roll out your app changes to the rest of the app users and send a notification to the users.

All done through Firebase console. In this way, your growth team can create an experiment that they like without wasting the time of your engineering team.

How to Perform A/B Test Using Firebase with Remote Config (Step by Step)

1. Setup Remote Config on Project

You may have noticed that it’s very painful to build, test and publish a new version of the app just to change some hard code value on it.

But with firebase remote config you could change that value in the firebase console and that affects your app without republishing it.

Remote config gives you the ability to define a set of named parameters and assign the value in the console.

Then in your app, you can fetch those values and use them according to your needs. Any time you change a parameter value in the console, it will be made available to your app.

In this portion, I will be showing you how you can read some values from Firebase Remote Config!

Step A: Create a New project

First of all, create a new Android Studio project.

Step B: Add Firebase remote config to your app

  • Now click on Tools -> Firebase.
  • Afterward, a new window appears. Click on Remote Config -> Set up Firebase Remote Config

Add remote config to app

  • Now Connect your app to Firebase & Add Dependenciesย 

app connected

  • Similarly, you need to add Analytics to your project because for remote config you need to add analytics to your app

google analytics

Step C: Design your layout

activity_main.xml

It looks like the below image:

design layout

Step D: Implements codes

Here you implement code in four-steps

1. First of all initializing RemoteConfig and get the instance

2. Get a singleton object of remote config

Singleton object is used to store in-app default parameter values, fetch updated parameter values from the Firebase backend, and control them when fetched values are made available to your app.

During development, it’s recommended to set a low fetch value but in production, you should increase this value otherwise app gets throttle. Want to know more about it? Go throttling.

3. set app default parameters values

You can set in-app default parameter values in the remote_config_default.xml file (which we implement in the next steps) so that your app behaves as intended before it connects to the Firebase Remote Config backend, and so that default values are always available if none are set in the Firebase backend system.

4. Fetch & activate values

If you want to only fetch values from Firebase backend call fetch()ย method. Similarly, if you want to activate values from Firebase backend call activate()ย method. Here you implement fetchAndActivate()ย method to fetch and activate values in just only one code.

And you can also handle the callbacks when the process finishes!

Here is the complete code of MainActivity.java

Step D: Setup default parameters value in the app

  • Now create a new resource directory by right click on res -> New -> android resource directory
  • Afterward, a popup box appears then enter xmlย as directory name & resource type and click on OK

Draw xml layout

  • Now create new xml resource by right click on xml -> new -> xml resource fileย and paste below code.

These values are basically key-value pairs.

It looks like the below image.

xml resource layout

Step E: Set parameters value in remote config Firebase console.

Now go to the console and Enter key-values and make it publish and run the app.

remote config values

Step F: How remote config works (video)

For better understanding watch the video.

Here is the official source code by the Firebase team.

For better understand you can read the documentation about remote config.

If you are curious about what you can do with Firebase remote config Read: what can I do with Remote Config?

Here is the complete code on GitHub

2. Creating an Experiment

  • First of all, go to the console and Select your project.
  • Next click on A/B Testing -> Create Experiment

start AB Test new

  • Now here you are going to work with remote config Click on it.

remote config

Remote config experiment has four major parts

1. Basic:

In the basic step, you add the basic things like the experiment name and its description (short and relevant) and click Next.

basic info

2. Targeting:

Afterward, select your targeting user.

Note: You can’t run your experiment on the same Android & iOS app at the same time because these platforms have different use patterns. That’s why it won’t work on another. The best way to make a separate experiment.

You can make a campaign by clicking on andย buttons. In my case, I’m targeting that device which has only the English audience has installed. Moreover, you can select country/region, app version, user audience as well

Percentage of target user:ย In this case, I’m using 5% of the total audience. Keep in mind that don’t put your test to 100% because if your app found some bugs then it may affect your entire audience. It is recommended to use 5-10% depending upon how risky you think your chances are.

Targeting

3. Goal:

Now select Goal retention e.g:- why you want to test your app.

There are a bunch of high-level goals like user engagement, retention rate (amount of time people spent with your app), in-app-purchase revenue, AdMob revenue, total revenue, etc.

There are also analytics events available in the app like a crash-free user, session start, etc.

Click Add metric+ย button to add more goals. You can add 5 metrics to test at the same time.

Goal retention

4. Variants:

In the end, add a variant to your app.

In my case, I’m testing two variants A & B. You can add multiple variants as well. As you know the parameter you already defined inside remote_config_defaults.xml. ย If you didn’t select any value then it means a default value is selected.

Now click on the Review button

Now you can see a summary of your test. Everything looks pretty good. But how do you know that my text should fit in the space and looks good or not?

Manage Tests

Luckily A/B testing makes testing these variants easy.

What you need to do is to grab an instance ID token (which is a unique identifier) of our application and assign to the instance of our app running on a particular device and then we can tell remote config to deliver a specific variation to that specific app instance. So then we can try out each variation before we publish our experiment.

summery

So getting our instance-id token requires a tiny bit of code.

Just copy above code and paste it inside MainActivity.java onCreate() method and run the app. you will get token in the logcat window as shown below

get token

Now go back to the console and scroll down your summary page and click on Manage test devices.ย 

A popup box appears Enter Token Id, Select Variant, clicks add and click save

save token in console

Now you can see “1 test device is receiving this experiment ” at the bottom of the Details portion.

And you can run the app and TextView also showing the details.

textview is showin on test device

Now your Experiment is ready. Click on Start experiment

start experiment

Now the next step is to sit back, feel relax and wait. You need some time for this experiment to run so it can reach the right amount of users and also they need some time to get used to it. Now next step is to analyze your experiment.

Step 3: Understand the Experiment results.

Well, now it’s time to check the results of the A/B test.

It is recommended that not to change anything in your app during the testing phase until the A/B test determines a winner.

See when the user sees something different on your app, they notice and react on it.

But that doesn’t mean this change is good in the long run. What if your changes are bad and people don’t like it?

That’s why Firebase suggest you run your test for at least two weeks in order to get the best and perfect results.

Now go to the console open your project, Go to the A/B testing tab and open your experiment. Here you can see I have 0 results here.

The reason here is that I’m testing this app on a sample app that has a monthly active user of 1. But if I test on some devices then it’s not getting better results.

sample demo

So you need to try this on the actual real app which is already in production which has the actual users.

One more thing if you use the same way as I did and not get any results then you may forget to update remote-config libraries. You have to update the latest libraries on your build.gradle (app) file.

Currently, I did not have access to any production app that why I am using these video screenshots. And try to explain this. Yeah sure, you can watch this video to get a better understanding.

Here you can see improvement overview

after retention

Take a look at another experiment snippet.

2nd snippet

In some cases, you may have seen a graph. As you know that graph always is seen as good when analyzing something.

Now you can see that by removing adds people spent more time on the app. In this way, you can collect information according to your needs.

Well, you may have seen these options below. You can stop the experiment, you can duplicate the experiment, or you can roll out these setting to the entire app.

Roll-out to 100% doesn’t mean you are adding more audience. It means you stopped this experiment, take this setting from one of the variants and make those official new values in the remote config for all your users in the app. It means you determine a winner.

stop test

You may have seen an Increase distribution dialogue at this time. You can increase your distribution level.

Increase distribution

That’s it for this tutorial. Hope you enjoyed it.

Don’t forget to ask a question. I’ll reply to every person.

Advertisements
W3Schools
Author

Hi there! I am Founder at FirebaseTutorials and AndroidBull. My skills include Android App Development. If you have any idea that you would want me to develop? Letโ€™s talk: waqas@firebasetutorials.com