npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fruits-chain/chushu-native

v1.1.2

Published

react-native埋点项目

Downloads

28

Readme

Chushu ReactNative APP 埋点脚本

  1. 错误信息的收集和上报
  2. 设备信息的收集和上报
  3. 路由信息的收集和上报

初始化埋点

1、使用该脚本需要在根节点使用【initTracking】初始化脚本实例。

示例:

import { initTracking } from '@fruits-chain/chushu-native'

const App: React.FC = () => {
  // accessKey可以通过在埋点平台创建应用后获取
  // uploadUrl为埋点数据上传地址
  // pv是否记录页面方位记录 默认false
  initTracking({
    accesskey: '$2b$10$YNQRLqrAQLoIvDSl2pXAQ.1A7sPQykoglzQDmk9goMrpgl7XjXOYi',
    uploadUrl: 'http://192.168.10.84:4000/upload',
    pv: true,
  })
  return <div>测试</div>
}

2、收集和上报需要用户 id 作为分析依据,需在外部调用【trackingInstance.setUserHash】,获取 userId

示例:

import { initTracking } from '@fruits-chain/chushu-native'

getUserInfo: async () => {
  const trackingInstance = initTracking()
  try {
    const res: Result<Partial<IUserInfo>> = await getLoginUserInfo()
    const userInfo = res.data
    trackingInstance.setUserHash(`${userInfo?.userId}`)
    set({ userInfo })
  } catch (error) {}
},

错误信息

1、其他错误信息收集已在内部集成,接口报错需在外部调用【trackingLink】

示例:

// graphql接口
import { ApolloClient, HttpLink, concat } from '@apollo/client'
import { trackingLink } from 'app-tracker@fruits-chain/chushu-native'

export function createClient(httpUri?: string) {
  const httpLink = new HttpLink({})
  return {
    client: new ApolloClient({
      link: concat(trackingLink, httpLink),
    }),
  }
}

// restful接口
import { trackingInterceptors } from '@fruits-chain/chushu-native'
/**
 * 响应拦截器
 */
axios.interceptors.response.use(
  (response: AxiosResponse<RestfulResult | RestfulUploadResult>) => {
    trackingInterceptors(response)
  },
  error => {},
)

路由信息

路由信息的收集需要在路由配置处调用【trackingInstance.setRouteInfo】

示例:

import { initTracking } from 'app-tracker'
import type { NavigationContainerRef } from '@react-navigation/native'
const navigationRef = useRef<NavigationContainerRef<ReactNavigation.RootParamList>>()
const trackingInstance = initTracking()

<NavigationContainer
  ref={navigationRef}
  onReady={() => {
    const rootState = navigationRef.current?.getRootState?.()
    trackingInstance.setRouteInfo(rootState)
  }}
  onStateChange={state => {
    trackingInstance.setRouteInfo(state)
  }}>
  <Stack.Navigator>
    <Stack.Screen
      name={route.name}
      component={route.component}
      options={{ ...defaultStackRouteOptions, ...route.options }}
    />
  </Stack.Navigator>
</NavigationContainer>