【问题标题】:Firebase - RemoteConfig with userProperty returns default valueFirebase - 带有 userProperty 的 RemoteConfig 返回默认值
【发布时间】:2017-10-24 19:52:10
【问题描述】:

首先我为我的英语道歉 :-) 我正在做一个大项目,但在我的 Android 应用程序中使用 Firebase 时遇到了问题。我有条件使用 Analytics 用户属性的 RemoteConfig。当我在应用程序中设置用户属性、获取数据并在成功完成后激活获取的数据时,即使 RemoteConfig 条件为真,我仍然从 RemoteConfig 获取参数的默认值。代码是用 Kotlin 编写的。

这是我的代码示例(此代码在类中的 onCreate() 方法中,它扩展了 Appliaction 类:

FirebaseAnalytics.getInstance(this).setUserProperty("testprop", "a");
FirebaseRemoteConfig.getInstance().fetch(0).addOnCompleteListener {
    if (it.isSuccessful) {
        FirebaseRemoteConfig.getInstance().activateFetched();
            val a = FirebaseRemoteConfig.getInstance().getString("test_param");
            Log.i("TOAPP", "Test param is $a");
        } else {
            Log.i("TOAPP", "Error: ${it.exception?.localizedMessage}");
            it.exception?.printStackTrace();
        }
    }
}

Firebase 中的远程配置:
参数 = test_param
- 我的用户 = 开发
- 默认值:= 生产

条件:
MyUser - 如果 User 属性 testprop 与 a 完全匹配,则适用

当我运行它时,我会在控制台中得到它:
I/TOAPP:测试参数正在生产中

我在 gradle.build 文件中有这些库:

// Play services
implementation "com.google.android.gms:play-services-location:11.4.2"
implementation "com.google.android.gms:play-services-maps:11.4.2"
implementation "com.google.android.gms:play-services-base:11.4.2"
implementation "com.google.android.gms:play-services-identity:11.4.2"
implementation "com.google.android.gms:play-services-places:11.4.2"

// Firebase
implementation "com.google.firebase:firebase-core:11.4.2"
implementation "com.google.firebase:firebase-config:11.4.2"
implementation "com.google.firebase:firebase-messaging:11.4.2"

感谢您的回答。

【问题讨论】:

  • 您的帖子(或代码)中有错字吗?在帖子中,描述条件的文本具有属性名称testprop如果用户属性 testprop 与 a 完全匹配则适用。在发布的代码中,您正在设置属性testparam
  • 是的,有一个错字...我设置了用户property testprop。我修了帖子。但是代码仍然不起作用。

标签: android firebase firebase-analytics firebase-remote-config


【解决方案1】:

问题解决了!

在 Firebase 中,我有两个 Andorid 应用(旧应用版本和新应用版本)。旧应用程序正常工作,但新应用程序出现问题。当我在 Firebase Analytics 和用户属性中打开旧应用程序时,我在远程配置条件中使用了一些参数。当我在 Firebase Analytics 中将应用切换到新版本时,用户属性为空。我在 Firebase Analytics 中将旧应用版本的相同属性添加到新应用版本,新应用可以正常运行。

【讨论】:

    【解决方案2】:

    您的代码看起来正确。问题可能是时机。当您调用 setUserProperty() 时,需要一些时间才能将值报告给 RemoteConfig 可以使用的 Firebase 服务器。我不知道确切的延迟是什么,但可能长达一个小时。 Firebase Analytics 缓冲事件数据并不经常发送以减少电池使用量,如explained here

    通常,您的应用记录的事件在 大约一小时的时间并一起上传。这种方法 节省最终用户设备的电池电量并减少网络数据 用法。

    用户属性的处理方式可能相同。为了测试,您可以启用调试模式以最小延迟上传数据(在上面的链接中描述):

    adb shell setprop debug.firebase.analytics.app <package_name>
    

    我建议你启用调试模式,运行代码到setUserProperty(),等待几分钟,然后运行代码来获取远程配置数据。当我使用该过程并运行与您的代码等效的 Java 版本 11.4.2 时,它起作用了。

    启用调试模式后,您可以在 Firebase 控制台中使用 Analytics debug view 确认您设置的用户属性值已上传到 Firebase 服务器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-02
      • 2013-01-19
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      相关资源
      最近更新 更多