A/B Testing using Firebase Remote Config & Firebase Analytics - Exercise
This exercise will attempt to conduct A/B test on an "Add To Cart" UI component in either one of the following forms:
- Button
- FloatingActionButton
using Firebase Remote Config and Firebase Analytics.
-
Download the source code from this repo.
-
Install Firebase SDK.
-
Add Firebase Remote Config dependency into the app.
compile 'com.google.firebase:firebase-core:11.2.2'
compile 'com.google.firebase:firebase-config:11.2.2'
- Create default values for Remote Config locally.
Add
<?xml version="1.0" encoding="utf-8"?>
<defaultsMap>
<entry>
<key>useFAB</key>
<value>true</value>
</entry>
</defaultsMap>
into res/xml/remote_config_defaults.xml
.
- Take a look at
MainActivity.java
andactivity_main.xml
. Some codes are missing in areas labelled with TODO.
Start with TODO: Part 1
Initialise Remote Config. Please refer to guide.
- create Remote Config Singleton object
- set Remote Config settings
- set default values
- Create parameter in Firebase Console.
Set the parameter key as "useFAB" with default value of true.
Then, click on "Add value for condition" and key in these conditions:
- "Use FAB for Add To Cart", with condition: User with random percentile <= 50%
- "Use Button for Add To Cart", with condition: User with random percentile > 50% AND User with random percentile <= 100%
Publish changes.
-
Get parameter values from the Remote Config object. Refer to getBoolean documentation, this guide and this example.
-
Update UI after fetching value from Remote Config.
For more guidance, please refer to this quick start.
-
Add Firebase Analytics dependency to the app.
-
Enable debug mode for Firebase Analytics by sending this command to device
adb shell setprop debug.firebase.analytics.app com.noelchew.remoteconfigsample
Without this, events logged will be batched together over the period of approximately one hour and uploaded together.
For more information (and how to disable this), please refer to this link.
- Locate
TODO: Part 2
and try to calllogEvent(FirebaseAnalytics.Event.ADD_TO_CART, bundle)
with a custom boolean parameter called "usingFAB" to Firebase Analytics.
Refer to this guide.
-
Create user property called "usingFAB" in Firebase Analytics.
-
Uncomment setting of user property inside displayAddToCartUI() function.
Refer to this guide to learn more about setting user property.
-
Run the app and check the events in DebugView (toggle StreamView if you can't find it).
-
To check the user behaviour for different UI, check the Events tab and add filter to show "usingFAB" User Property.
However, data will only be available after 24 hours.
That's it! You have successfully implemented Firebase Remote Config and Firebase Analytics for a simple A/B testing. Note that in this exercise, there's not much sample data for you to tinker with in the Firebase Analytics console. You probably only have 1 sample size to play with. You can install the app into more devices if you wish to see more data (24 hours later).
Please refer to the solution if required.