在 Android 上运行此基本 Firebase RemoteConfig A/B 测试。我想获取 Firebase 中配置的 A/B 测试的标题/名称和描述。另外,最好能获得变体的名称(Control、Variation A,...)
如何获取这些数据?
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));
}
});
}
最佳答案
除了所选的变体之外,没有官方 API 可以检索有关 A/B 测试的任何信息。
只需对应用内的值进行硬编码,或在 Firebase 托管/Cloud Firestore 上手动添加它们,将会变得非常非常容易。
话虽这么说,这里有 2 个关于更自动化解决方案的模糊想法,但我真的不建议尝试!
<小时/>BigQuery
你可以link your project to BigQuery ,它将包含您的 Analytics 数据。具体来说:
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.
一旦您的数据进入 BigQuery,您就可以 retrieve it using the SDKs 。您当然需要处理 permissions and access control ,这几乎肯定是极其矫枉过正的。
<小时/>云函数(和托管)
另一个解决方案是将您需要的数据存储在其他地方,然后检索它。 Firebase Cloud Functions 能够 react to a new remote config (A/B 测试在幕后使用这些)。所以你可以创建一个函数:
- 在创建新的远程配置时触发。
- 将
参数键
到名称
等的映射存储在Cloud Firestore或类似设备中。
然后,您的应用可以查询此 Cloud Firestore/托管文件/无论您在何处托管它。
注意:我实际上无法弄清楚如何获取有关 Cloud Functions 中远程配置的任何信息。版本名称、更新时间等信息 are available ,但描述
似乎含糊不清。
关于android - 我可以将 A/B 测试的标题/名称或描述以及变体名称从 Firebase 获取到 Activity 中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56111355/