{
"$type": "site.standard.document",
"canonicalUrl": "https://segunfamisa.com/posts/firebase-remote-config",
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreigfuxxplao2z6ecegphpahur7gvhd2vkhrxqoqvf3pxydbt3gqm7u"
},
"mimeType": "image/png",
"size": 8373
},
"description": "Update your app without updating your app",
"path": "/posts/firebase-remote-config",
"publishedAt": "2016-06-13T04:05:30.000Z",
"site": "at://did:plc:a5mekodp4afxadlpr4hp2wci/site.standard.publication/3mm2oa7vz5327",
"tags": [
"android",
"firebase",
"remote config"
],
"textContent": "I've probably said this countless times, that Firebase is one of the most exciting\nannouncements for me at this year's I/O and I'm yet to fully\nexplore it. Recently, I tried out the crash reporting and it was smooth. Check out this\npost to catch up on that.\n\nAnother really interesting part of Firebase is Remote config. Remote config allows you\nupdate your app without necessarily deploying a new version of your app. The biggest challenge\nas app developers is getting your users to update their apps. Firebase remote config\nseems to solve the problem of configuring and updating your app without having to redeploy an update\nof your app.\n\nI first observed this behaviour on Twitter's Android app. The app changes right there even when you're on it\nwithout you updating.\n\n<blockquote class=\"twitter-tweet\" data-lang=\"en\"><p lang=\"en\" dir=\"ltr\">\n My twitter app just changed without updating 😳</p>— SF (@segunfamisa) <a href=\"https://twitter.com/segunfamisa/status/698549713352658944\">February 13, 2016</a></blockquote>\n<script async src=\"//platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n\nIn this post, I would show how you can use Firebase's remote config feature to achieve this behaviour.\n\nWhy should I use remote config?\n\nThe major benefit of remote config is delivering the right experience to your users,\n the right users as fast as possible. Adapting to user feedback is very important to the success of your app. Testing out new\nfeatures is equally important. There is where remote config comes in handy.\n\nYou can change the look and feel of your app remotely with remote config, allowing you to run experiments\nall geared towards providing a premium experience for your app.\n\nFor example, you want to determine how well a green button attracts users to click, compared to how a black button does. Remote config is your go to.\n\nYou want to run a campaign for Christmas, so you want your app to have that Green,\nWhite and Red feel, you should not have to redeploy a new app solely for that purpose,\nand even if you do, what's the guarantee that half of your users will update their app? Remote config has to be your buddy.\n\nRemote config is superb for A/B testing.\n\nTL;DR, remote config allows you:\n\n Modify your app without a new production deployment\n Customize content for different Firebase Analytics audiences and measure results\n Roll out features gradually and monitor the impact\n\nHow to use?\n\n1. Setup Firebase\n\nFirst thing to do is to setup Firebase. This step is very much similar as covered in the\nFirebase Crash Reporting.\nPlease check here for how to setup Firebase.\n\n2. Add Remote config\n\nNext step is to add the Firebase Remote Config Library to your app. This is done by adding this line to\nyour app-module's build.gradle file.\n\nAt the end of this step, your build.gradle file should look like this:\n\n3. Implementing Remote Config\nTo implement remote config, we need to setup the parameters we wish to configure as well as\nbuild our app to fetch and use these parameters.\n\nSetting up the parameter values on the server.\n\nAdd parameters\nAn important step in using remote config is setting up the parameters we wish to configure on the server.\n\nTo do this, we need to navigate to the Remote Config page from the left pane of the console dashboard.\nIt should look like this:\n\nNext is to actually determine what values you want to remotely configure. It could range from theme colors,\nto messages and texts and discounts or whatsoever.\n\nPlease note that these policies exist concerning the kind of information you should put:\n\n Don't use Remote Config to make app updates that should require a user's authorization. This could cause your app to be perceived as untrustworthy.\n Don't store confidential data in Remote Config parameter keys or parameter values. It is possible to decode any parameter keys or values stored in the Remote Config settings for your project.\n Don't attempt to circumvent the requirements of your app's target platform using Remote Config.\n\nOnce that's done, we just need to click on ADD YOUR FIRST PARAMETER as seen above.\n\nBe sure to click publish changes when you're done adding parameters.\nAt the end of this step, you should have a dashboard that looks like this.\n\nAdd conditions\nAfter adding your first parameter, you can now add conditions. Adding conditions allow you to\napply different server parameter values based on various conditions such as Country, AppId,\nOS Version, random percentile of users, App version etc.\n\nAdding conditions is easy:\n\nYou can also remove or modify your conditions by navigating to the conditions tab\n\nAfter adding conditions, you can now specify the values to return if the conditions specified checks as true.\n\nWhen you apply conditions to some values, your dashboard would look like this:\n\nYou should note that there's a limit of 2000 parameters and up to 100 conditions and parameter keys can be\n256 characters long.\n\nImplement remote config on your app.\nTo use the remote config library on your app, you need to get a remote config object\nthat will be used to cache your local values and get remote values as well.\n\nTo do this, you will be doing something like this:\n\nWe basically retrieved an instance of the FirebaseRemoteConfig object and we enable the developer mode\nso that the cache gets refreshed often.\n\nNext is, to set the in-app default values of the parameters we wish to configure remotely.\nWe can do this using the mRemoteConfig.setDefaults() method. This typically takes in an xml resource\nor a Map. For example:\n\nWhat's up with the XML defaults file.\nThe XML defaults file is just a description of the key and the default value of the parameters you wish to configure remotely. Within your app-module's ../res directory, you need to create an xml directory.\nIt is within this directory that the file should be placed. Note that the keys have to be\nthe same as you used on the Firebase Console.\n\nA typical file looks like this:\n\nThis is basically entries of keys and values for the default files. The values\n are retrieved as either Long, double, boolean, or String.\n\nThis is also possible through code. You can build the default values as a Map\n with Strings as keys and the respective objects (Long, double, boolean, String, int) as values.\nFor example:\n\nFetch remote values.\nNow that we've set default values, we need to fetch the remote values and activate them.\n\nThis block of code does that:\n\nWhat we've done here is, fetch the latest remote config values and to do that, we first\nset the cache to 12hours and 0 if developer mode is enabled. If the values in the cache are older than the desired cache expiration, Remote Config will request fresh config values from the server.\nSetting the cache expiration to 0 for developer mode enables easy debugging.\n\nNote that on successful fetch task, we call mRemoteConfig.activateFetched(). This is important\nbecause the values fetched are only cached and not activated without that.\n\nUse fetched values.\n\nNow that we've fetched the values, we need to use them. We need to retrieve the values from the\nFirebaseRemoteConfig object using the same keys specified. For example,\nto set the toolbar color when our promo is on, we do something like:\n\nWe also want to show a \"Signup coupon code\" field if our promo is running. We do something like:\n\nMore?\nIf you want to see more code, please checkout this sample on Github.\n\nIn the app, we have a signup screen with the sign up message configurable remotely because we plan to change the sign up prompt depending on whether we're having a promo or not.\n\nThe demo app looks like this:\n\nBe sure you checkout the firebase-remote-config branch.\n\nThere is more to do with Firebase remote config . There's a whole section on how to use it with\nFirebase Analytics to achieve good A/B testing and experiments. Please check here for more.\n\nReferences and further reading\n\n https://firebase.googleblog.com/2016/06/introducing-firebase-remote-config.html\n https://firebase.google.com/docs/remote-config/android\n https://firebase.google.com/docs/reference/android/com/google/firebase/remoteconfig/package-summary\n https://firebase.google.com/docs/remote-config/config-analytics\n\nIf you found this post useful, kindly share. Comments, corrections and questions are welcome.\n\nYou can now set that AppConstants file free :)\n\nCheers.",
"title": "Remote config with Firebase"
}