{"id":20839120,"url":"https://github.com/sbdavid/react-native-page-analytics","last_synced_at":"2026-04-24T10:33:46.359Z","repository":{"id":56855847,"uuid":"409503271","full_name":"SBDavid/react-native-page-analytics","owner":"SBDavid","description":null,"archived":false,"fork":false,"pushed_at":"2022-08-23T07:51:39.000Z","size":1264,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-01-18T23:44:47.235Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SBDavid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-23T08:06:18.000Z","updated_at":"2021-09-27T05:49:09.000Z","dependencies_parsed_at":"2022-09-21T13:12:43.081Z","dependency_job_id":null,"html_url":"https://github.com/SBDavid/react-native-page-analytics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBDavid%2Freact-native-page-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBDavid%2Freact-native-page-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBDavid%2Freact-native-page-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBDavid%2Freact-native-page-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SBDavid","download_url":"https://codeload.github.com/SBDavid/react-native-page-analytics/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243196663,"owners_count":20251861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T01:12:23.665Z","updated_at":"2025-12-25T10:19:15.318Z","avatar_url":"https://github.com/SBDavid.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-page-analytics\n\nempty\n\n## 安装\n\n  + npm install @xmly/react-native-page-analytics\n\n\u003cbr/\u003e\n\n## 提供了class组件和hooks两种使用方式\n\n\u003cbr /\u003e\n\n## class组件：\n\u003cbr /\u003e\n\n### 使用方式\n  1. 页面继承PageAnalytics.Screen或者PageAnalytics.PureScreen，分别对应普通组件和纯组件\n\n  2. 定义 **customPageView** 和 **customPageExit** 属性，分别在 **页面展示** 和 **页面隐藏** 时执行\n\n  3. 在componentWillUnmount中添加 super.componentWillUnmount(); 移除页面事件监听\n\n\n\u003cbr/\u003e\n\n### 使用示例：\n```js\nimport { View } from 'react-native';\nimport PageAnalytics, { AnalyticProps } from '@xmly/react-native-page-analytics';\n\ninterface CurrentProps {}\ninterface CurrentState {}\n\nclass HomePage extends PageAnalytics.Screen\u003cCurrentProps \u0026 AnalyticProps, CurrentState\u003e {\n\n  constructor(props: CurrentProps \u0026 AnalyticProps) {\n    super(props);\n  }\n\n  componentDidMount() {\n\n  }\n\n  componentWillUnmount() {\n    // 移除监听\n    super.componentWillUnmount();\n  }\n\n  // 页面展示埋点上传\n  customPageView = () =\u003e {\n    console.log(`发送页面pageView埋点 页面名: homePage  metaId: 0`);\n  };\n\n  // 页面隐藏埋点上传\n  customPageExit = () =\u003e {\n    console.log(`发送页面pageExit埋点 页面名: homePage metaId: 0`);\n  };\n\n  render() {\n    return \u003cView /\u003e\n  }\n}\n```\n### API\n\n| 属性             | 类型        | 可选     | 含义               |\n| :---            | :---        | :---    | :---              |\n| customPageView  | () =\u003e void  |   否    | 页面展示埋点方法 |\n| customPageExit  | () =\u003e void  |   否    | 自定义页面隐藏埋点方法 |\n\n\n\u003cbr /\u003e\n\n\n### 注意点\n\n  1. **须在componentWillUnmount中调用super.componentWillUnmount方法去移除页面事件监听**\n\n\u003cbr /\u003e\n\n\n## hooks：\n\u003cbr /\u003e\n\n### 使用方式：\n1. 组件中使用useScreen()，参数中传入 **customPageView**，**customPageExit**，两个必传属性，分别在 **页面展示** 和 **页面隐藏** 时执行，**对于使用了路由的页面，需要将路由对象navigation传入**\n\n\u003cbr /\u003e\n\n### 使用实例：\n```js\nimport { useCallback } from 'react';\nimport { View } from 'react-native';\nimport PageAnalytics, { AnalyticProps } from '@xmly/react-native-page-analytics';\n\ninterface HomePageProps {}\n\nexport default function HomePage(props: HomePageProps \u0026 AnalyticProps) {\n\n  // 页面展示埋点上传\n  const customPageView = useCallback(() =\u003e {\n    console.log(`发送页面pageView埋点 页面名: homePage  metaId: 0`);\n  }, []);\n\n\n  // 页面隐藏埋点上传\n  const customPageExit = useCallback(() =\u003e {\n    console.log(`发送页面pageExit埋点 页面名: homePage metaId: 0`);\n  }, []);\n\n  PageAnalytics.useScreen({\n    customPageView,\n    customPageExit,\n    ...props, // 对于有使用路由的页面，需要将路由对象navigation传入\n  });\n\n  return \u003cView /\u003e\n}\n```\n\n\u003cbr /\u003e\n\n### API\n\nuseScreen\n\n| 方法      | 参数   | 返回值  | 含义    |\n| :--        | :--    | :-- | :-- |\n| useScreen  | {\u003cbr /\u003e // 页面展示埋点上传 \u003cbr /\u003ecustomPageView?: () =\u003e void;\u003cbr /\u003e\u003cbr /\u003e// 页面隐藏埋点上传 \u003cbr /\u003ecustomPageExit?: () =\u003e void;\u003cbr /\u003e\u003cbr /\u003e// 若使用了路由，传入navigation \u003cbr /\u003e [index: string]: any;\u003cbr /\u003e} | -- | hooks\n\n## 实现，特性\n  1. 此工具对页面的navigation跳转、APPstate状态变化、RN页面与Native页面互跳 三种场景都做了处理，同时对ios，安卓两端事件监听的差异做了兼容处理，保证了页面展示/隐藏数据埋点的全面准确\n\n\n  2. 兼容没有使用react-navigation的项目，对于没有使用路由的单RN页面项目，会对APPstate状态变化、RN页面与Native页面互跳 这两种场景做了处理\n\n## Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbdavid%2Freact-native-page-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbdavid%2Freact-native-page-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbdavid%2Freact-native-page-analytics/lists"}