Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
tracker-statistics
Advanced tools
简单易用的用户行为埋点工具
window
和 document
对象,所以在 web
和微信小程序中存在较大差异)web
应用、 uni-app
构建的微信小程序和 h5
应用以及原生微信小程序应用tracker statistics
作为一个代码埋点的工具,能够适用于任何基于 web
的用户行为埋点工具,该工具抽象出了多种行为类型,每种类型对应一个处理函数。
在行为方法的固定参数无法满足较为复杂的业务需求,为此我们提供了自定义业务数据的功能。
# yarn
yarn add tracker-statistics
# npm
npm install tracker-statistics
在需要进行埋点的页面进行引入,如有大量页面需要使用埋点时,可以使用全局挂载的形式。
该 sdk
在 web
端依赖于浏览器的 sessionStorge
或 localStorage
进行缓存数据的处理,因此会具有某些 sessionStorge
或 localStorage
的特性。
在原生微信小程序和基于 uni-app
构建的微信小程序中使用原生的 setStorage
方法。
import trackerStatistics from 'tracker-statistics'
初始化方法允许用户在私有化过程中传递服务器接口信息以及 sdk
中的一些配置。
interface InitProps {
url: string // 接口服务的地址
method: Method // 接口的请求类型, Method 类型为 request 支持的请求类型
webStorage?: 'localStorage' | 'sessionStorage' // web 缓存数据存储位置,默认 sessionStorage
helpImprove?: boolean // 是否帮助我们改进和完善 sdk ,开启后会对行为类型和命名空间信息进行上传
usage?: 'code' | 'visualization' // 使用方式,目前只支持 code
platform?: 'web' | 'wx' // 平台类型,不建议手动更改
}
trackerStatistics.init({
url: 'http://xxx.com/send',
method: 'post'
})
曝光行为通常用于列表页面针对某一项是否被完全的展示(即列表中的某一项是否在父级容器中完全显示),并提供针对这一项的浏览时长统计。
值得注意的是该行为需要在 dom
渲染完成后执行。
由于微信小程序生态缺乏对 window
和 document
的支持,所以针对曝光行为会有一定的差别。
// web
interface WebExposeProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
containerId: string // 页面列表中的容器 ID
name: string // 对应列表名称
}
// wx
interface WxExposeProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
itemId: string // 内容项 ID
userId: string // 用户 ID
name: string // 对应列表名称
}
// web
trackerStatistics.expose({
name: 'shop',
containerId: 'shopListContainer',
userId: '1'
})
// wx
trackerStatistics.expose({
name: 'shop',
itemId: '1',
userId: '1'
})
点击行为常常用于追踪用户的点击事件。
interface ClickProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
name: string // 对应点击名称
}
trackerStatistics.click({
name: '首页',
userId: '1'
})
加入购物车行为是对商城类行为埋点的抽象。
interface CartProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
itemId: string // 内容项 ID
}
trackerStatistics.cart({
itemId: '1',
userId: '1'
})
购买行为是对商城类行为埋点的抽象。
interface BuyProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
itemId: string // 内容项 ID
}
trackerStatistics.buy({
itemId: '1',
userId: '1'
})
收藏行为通常用于文章和商品等。
interface CollectProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
itemId: string // 内容项 ID
name: string // 对应收藏名称
}
trackerStatistics.collect({
name: 'shop',
itemId: '1',
userId: '1'
})
点赞行为通常用于对文章和评论等。
interface LikeProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
itemId: string // 内容项 ID
name: string // 对应点赞名称
}
trackerStatistics.like({
name: 'comment',
itemId: '1',
userId: '1'
})
点衰行为通常用于对文章和评论等执行差评的操作。
interface UnlikeProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
itemId: string // 内容项 ID
name: string // 对应点衰名称
}
trackerStatistics.unlike({
name: 'comment',
itemId: '1',
userId: '1'
})
用于对商品和文章等发布评论的埋点。
interface CommentProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
itemId: string // 内容项 ID
content: string // 评论的内容
name: string // 对应评论名称
}
trackerStatistics.comment({
name: 'comment',
content: 'content',
itemId: '1',
userId: '1'
})
用于对商品和文章等分享事件的埋点。
interface ShareProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
itemId: string // 内容项 ID
name: string // 对应分享名称
}
trackerStatistics.share({
name: 'shop',
itemId: '1',
userId: '1'
})
用于对消息通知的订阅。
interface SubscribeProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
name: string // 对应订阅名称
}
trackerStatistics.subscribe({
name: 'notification',
userId: '1'
})
停留行为通常用于获取用户在某一个页面停留了多长时间。 该行为包含两个方法,需要在页面挂载和卸载的生命周期里进行调用。
interface BaseProps {
data?: DataProps // 自定义业务数据
isPrefab?: boolean // 是否显示预制体
userId: string // 用户 ID
}
// 页面加载时使用
trackerStatistics.stay.entry()
// 页面卸载时使用
trackerStatistics.stay.leave({
userId: '1'
})
FAQs
The npm package tracker-statistics receives a total of 43 weekly downloads. As such, tracker-statistics popularity was classified as not popular.
We found that tracker-statistics demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.