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を使用している場合、このコードは機能します!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加