【问题标题】:How can I track screen time of user when a user navigate to specific screen in react native?当用户导航到本机反应的特定屏幕时,如何跟踪用户的屏幕时间?
【发布时间】:2021-12-14 15:31:46
【问题描述】:

我想跟踪用户浏览屏幕和离开屏幕的时间。我还想设置状态,然后将这些数据发送到 API。

const Stack = createStackNavigator();
const Tab = createMaterialTopTabNavigator();
export default function BootcampWeeksScreen(props){
    const { navigation } = props;
const pathway_id=navigation.getParam('pathway_id');
  return (


    <NavigationContainer>
      <Tab.Navigator tabBarOptions={{ scrollEnabled: true }}>
      <Tab.Screen name="Course" component={Courses} initialParams={{pathway_id:pathway_id}} />
        <Tab.Screen name="Roadmap" component={Roadmap} />
      </Tab.Navigator>
    </NavigationContainer>
  );
}

当用户导航到Course 屏幕时,我想跟踪用户离开屏幕的时间。

我该怎么做?

【问题讨论】:

    标签: javascript reactjs react-native react-navigation time-tracking


    【解决方案1】:

    您可以通过将时间存储在可在整个组件中访问的全局变量中来做到这一点。您可以为此使用 react context 或 redux。

    当用户导航到您可能使用的其他页面时

    useEffect(()=>{
    
    return ()=>{
      //  when the user navigated to another page this gets execute
      // setting of new date will be from here
     }
    },[])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-24
      • 1970-01-01
      相关资源
      最近更新 更多