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

@monsterooo/tracker

v1.4.2

Published

tracker

Downloads

1

Readme


title: Http 数据请求 sidemenu: false nav: title: 埋点 path: /tracker order: 4

Tracker 埋点

前端日志文档

使用方式

yarn add @monsterooo/tracker

常规使用

自动上报埋点

自动埋点功能,通过监听全局 event,当产生 click 事件的节点具有 data-track 属性的时候会自动对该事件进行上报;

使用方式

  1. 初始化 tracker 时, autoTrack 设置为 true;
  2. 在发生点击事件的的元素上设置 data-track 属性;

demo 如下

小程序接入

目前已经内置小程序(微信小程序,飞书小程序)的埋点上报,只是暂时不支持自动埋点上报共功能,其他使用方法一样的;

接口

Tracker options

| key | 说明 | 类型 | 默认值 | | --------- | ---------------------------------- | ----------- | ------ | | client | 项目 id,比如 web, h5, | string | 必填 | | env | 上报环境 | qa,dev,prod | 必填 | | uid | 用户唯一标示 | string | 非必填 | | pageName | 页面名称 | string | 非必填 | | autoTrack | 是否自动上报, 目前暂时只支持浏览器 | boolean | false |

如果 options 中还有其他参数,则这些参数会默认放在请求的content字段中

Tracker instance

| 方法 | 说明 | 类型 | | --- | --- | --- | | sendPV | 上报 PV | (data: any) => any | | sendEvent | 上报事件 | (eventId: string, data?: any) => any | | sendLogData | 上报日志。_level_ 日志级别,枚举值(Verbose、Debug、Info、Warn、Error),必填。_msg_ 日志内容,必填。_tag_ 日志标签,必填。更多信息参考文档,log 类型 | (data: { level, msg, tag }) => any | | setCommonData | 设置 commonData,放置在请求中的common字段, 对应在日志中_common_字段 | (data: Record<string, any>) => void | | setParams | 设置 params, 放置在请求content中的字段,对应在日志中_content_字段 | (data: Record<string, any>) => void |

Tracker Defaults 配置

| 方法 | 说明 | 类型 | | --- | --- | --- | | apis | 日志上报接口 | { qa: string, dev: string, prod: string } | | request | 请求发送方式 | (params:{url: string, data: any, method: string, header}) => Promise | | getCommonData | 设置获取默认 CommonData | () => Record<string, any> |

FAQ

  • defaults 中 request 中的 header 字段必须要包含在请求头中,阿里云那边需要;