Got this basic Firebase RemoteConfig A/B-Test running on Android. I want to get the title/name and description of the A/B-Test configurated in Firebase. Also it would be nice to get the name of the variations (Control, Variation A, ...)
How do I get these data?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// bind XML elements into variables
bindWidgets();
// Only for debugging: get Instance ID token from device
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
String deviceToken = task.getResult().getToken();
Log.wtf("Instance ID", deviceToken);
}
});
// Remote Config Setting
FirebaseRemoteConfigSettings mFirebaseRemoteConfigSettings = new FirebaseRemoteConfigSettings
.Builder()
.setDeveloperModeEnabled(BuildConfig.DEBUG)
.build();
mFirebaseRemoteConfig.setConfigSettings(mFirebaseRemoteConfigSettings);
// Remote Config with HashMap
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("buttonColor", "#999999");
mFirebaseRemoteConfig.setDefaults(hashMap);
final Task<Void> fetch = mFirebaseRemoteConfig.fetch(FirebaseRemoteConfig.VALUE_SOURCE_STATIC);
fetch.addOnSuccessListener(this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
mFirebaseRemoteConfig.activateFetched();
// get value of key buttonColor from HashMap
String buttonColor = mFirebaseRemoteConfig.getString("buttonColor");
button.setBackgroundColor(Color.parseColor(buttonColor));
}
});
}
There is no official API to retrieve any information about your A/B test, besides the variant selected.
It's going to be much, much easier to just hardcode the values inside your app, or manually add them on Firebase Hosting / Cloud Firestore.
That being said, here's 2 vague ideas for more automatic solutions, but I really don't recommend trying either!
You could link your project to BigQuery, it will then contain your Analytics data. Specifically:
In this query, your experiment is encoded as a user property with the experiment name in the key and the experiment variant in the value.
Once your data is in BigQuery, you could then retrieve it using the SDKs. You will of course need to handle permissions and access control, and this is almost certainly extremely overkill.
Another solution is to just store the data you need elsewhere, and retrieve it. Firebase Cloud Functions have the ability to react to a new remote config (A/B tests use these under the hood). So you could create a function that:
parameter key
to name
etc in Cloud Firestore or similar.Your app could then query this Cloud Firestore / hosted file / wherever you hosted it.
Note: I couldn't actually figure out how to get any info about the remote config in Cloud Functions. Things like version name, update time etc are available, but description
seems suspiciously vague.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With