A/B Testing with Firebase and Xamarin

Firebase provides a great way to conduct experiments or “A/B tests” using their Remote Config cloud service.

This allows you to specify a segment of your users (or audience) that should receive different functionality based on configuration key/value pairs.

For the purposes of demonstration, I have created a very basic MVVMCross app with a green button.

Lets say the theory from the product team is that making the botton red will help get more people to click on it! How do we test this?

Step 1 – Create a Firebase project

Go to console.firebase.google.com and “Add a project”

Step 2 – Select remote config

2-1) And add your first parameter, in our case ButtonColor. The default value will be green (#00FF00)

2-2) Click publish changes (top right)

 

Step 3 -Add your app

3-1) Click “Project overview” -> “Project settings”

3-2) Click “Add firebase to your Android app”

3-3) Enter your package name, in our case “com.hotcross.remoteconfigdemo”

3-4) Download the google-services.json file

3-5) Do the same for the IOS project

Step 4 – add the Firebase IOS and/or Android Nuget packages

Step 5) Add Google Service JSON

5-1) Add the google-services.json to your Android project

Step 6) Use the service



using Firebase.RemoteConfig;
using System.Threading.Tasks;

namespace RemoteConfigDemo.Droid
{
    public class RemoteConfigService : IRemoteConfigService
    {
        readonly FirebaseRemoteConfig _firebaseRemoteConfig;

        private int _cacheExpirationSeconds = 3600;

#if !Release
        const bool debugMode = true;
#else
        const bool debugMode = false;
#endif

        public RemoteConfigService()
        {
            _firebaseRemoteConfig = FirebaseRemoteConfig.Instance;

            var configSettings = new FirebaseRemoteConfigSettings.Builder()
                                 .SetDeveloperModeEnabled(debugMode)
                                 .Build();

            _firebaseRemoteConfig.SetConfigSettings(configSettings);

            if (_firebaseRemoteConfig.Info.ConfigSettings.IsDeveloperModeEnabled)
            {
                _cacheExpirationSeconds = 0;
            }
        }

        public bool IsFeatureEnabled(string featureName)
        {
            return _firebaseRemoteConfig.GetBoolean(featureName);
        }

        public string GetStringValue(string key)
        {
            return _firebaseRemoteConfig.GetString(key);
        }

        public async Task Fetch()
        {
            await _firebaseRemoteConfig.FetchAsync(_cacheExpirationSeconds);

            _firebaseRemoteConfig.ActivateFetched();
        }
    }
}

Gotchas

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.