首页 文章

我的屏幕名称未显示在Firebase Analytics信息中心中

提问于
浏览
1

我正在尝试跟踪react-native-firebase上的屏幕名称以及react-navigation .

这是我的代码 .

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 .

1 回答

  • 1

    上面的代码是可靠的 . 事实证明,在填充数据之前,您必须等待半天左右 . 不确定我是否错过了文档中的内容 . 如果您正在使用react-navigation和firebase,则此代码可以正常运行!

相关问题