我正在尝试结合 react-navigation 在 react-native-firebase 上跟踪屏幕名称。
这是我的代码。
const tracker = firebase.analytics()
function getCurrentRouteName(navigationState) {
if (!navigationState) {
return null;
}
const route = navigationState.routes[navigationState.index];
// dive into nested navigators
if (route.routes) {
return getCurrentRouteName(route);
}
return route.routeName;
}
export default class AppNavigation extends Component {
render() {
StatusBar.setBarStyle('light-content');
return (
<MainScreenNavigator
onNavigationStateChange={(prevState, currentState) => {
const currentScreen = getCurrentRouteName(currentState);
const prevScreen = getCurrentRouteName(prevState);
if (prevScreen !== currentScreen) {
// the line below uses the Google Analytics tracker
// change the tracker here to use other Mobile analytics SDK.
tracker.setCurrentScreen(currentScreen);
}
}}
/>
);
}
}
当我控制台记录屏幕名称时,它们会按需要显示。但是,我没有在 Firebase 控制台中看到结果。当我按名称过滤屏幕时,它只是说(未设置)。我的代码做错了吗?我也在从“react-native-firebase”导入 firebase。
最佳答案
上面的代码是可靠的。事实证明,您必须等待半天左右才能填充数据。不确定我是否在文档中遗漏了这一点。如果您使用的是 react-navigation 和 firebase,则此代码有效!
关于react-native - 我的屏幕名称未出现在 Firebase Analytics 仪表板中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49393287/