为 Firebase Analytics 的底部 sheet 屏幕设置自定义屏幕名称

Setting custom screen name for bottom sheet screen for Firebase Analytics

我有一个 activity 带有滑动底部 sheet。我想跟踪用户查看底部 sheet 或主 activity 屏幕的时间。

我正在尝试使用 FirebaseAnalytics#setCurrentScreen(Activity activity, String screenName, String screenClassOverride) 以便在显示底部 sheet 时显示。我用

指定屏幕名称
FirebaseAnalytics.setCurrentScreen(activity, "bottom_sheet", null);

然后当底部sheet关闭时我调用

FirebaseAnalytics.setCurrentScreen(activity, null, null);

恢复主要 activity 的名称。

但是我从 FA 得到了一个日志:

W/FA: setCurrentScreen cannot be called with the same class and name

如果有人能告诉我如何正确设置屏幕名称那就太好了。

screenName 是您要用来识别您的 Activity/Fragment/Dialog...

的任何内容 你应该这样使用 setCurrentScreen

FirebaseAnalytics.setCurrentScreen(activity, "bottom_sheet", this.getClass().getSimpleName());

FirebaseAnalytics.setCurrentScreen(activity, "bottom_sheet", MyActivity.class.getSimpleName());

请记住,Firebase Analytics 会自动记录您的当前 Activity,请查看官方 Firebase 文档中的以下 setCurrentScreen 信息:

Note that screen reporting is enabled automatically and records the class name of the current Activity for you without requiring you to call this function. The class name can optionally be overridden by calling this function in the onResume callback of your Activity and specifying the screenClassOverride parameter.

您可以找到此文档和更多文档 here

现在,您收到了该错误消息

W/FA: setCurrentScreen cannot be called with the same class and name

当您在 setCurrentScreen()

中设置相同的 screenNamescreenClassOverride

在您调用该方法的地方使用 Log.d 可以帮助您查看您是否两次或多次调用同一事物。但我想你不必担心它(这是一个警告)。我在我现在的项目中看到过,一切正常。