4

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));
            }
        });

    }

2 Answers2

1

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!


BigQuery

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.


Cloud Functions (and hosting)

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:

  • Is triggered on new remote config creation.
  • Stores a mapping of 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.

Jake Lee
  • 7,549
  • 8
  • 45
  • 86
1

We wanted to get these informations for our Tracking/Analyzing Tools. So we implemented a workaround and added an additional Remote Config variable abTestName_variantInfo where we set a short info in the A/B-Testing configuration about the name of the A/B-Test and the variant we are running in. With this we can use the main Remote Config variable for the variant changes (e.g layout or functionality) without being dependent of our own naming-convention for tracking.

For example we used the two Remote Config variables ratingTest_variant (values: emojis or stars) and added the variable ratingTest_variantInfo (values: abTest_rating_emojis and abTest_rating_stars).