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

@ztocwst/tracker

v0.0.17

Published

埋点SDK

Downloads

10

Readme

埋点 SDK

NPM version NPM version NPM downloads

用于中通云仓系统页面埋点统计的前端 sdk,统计页面访问量、加载时间,按钮点击次数等

文档说明

该文档部署采用 @ztocwst/deploy工具部署

Install

npm i @ztocwst/tracker --save

Usage

不同场景不同使用方式

默认,常规

import Tracker from '@ztocwst/tracker'

// 初始化
const t = new Tracker({
  appCode: 'OMP',
  source: 'PC',
  eventInfo: {
    eventCode: 'user_search',
    eventType: `加载`,
    eventStart: 1631175747283,
    eventEnd: 1631175775502,
    eventCategory: '0',
    eventName: '首页',
  },
  userInfo: {
    userId: 'zhangsan',
    userName: '张三',
    // ...
  },
})

// 触发埋点,事件执行时间自己控制
t.trace({
  eventInfo: {
    eventCode: 'user_search',
    eventType: '点击',
    eventStart: 1631175747283,
    eventEnd: 1631175775502,
    eventCategory: '1',
    eventName: '用户查询',
  },
  // ...
})

记录页面打开时间

const t = new Tracker({
  appCode: 'OMP',
  source: 'PC',
  // userInfo一般通过setOptions方法动态设置
  userInfo: {
    userId: 'zhangsan',
    userName: '张三',
    // ...
  },
})

// 设置用户信息
t.setOptions({
  userInfo: {
    userId: ret.code,
    userName: ret.name,
    warehouseCode: ret.defaultWarehouseCode,
    warehouseName: ret.defaultWarehouseName,
  },
})

// 点击菜单打开页面时,执行时间sdk会去处理
t.add({
  eventCode: 'user-center',
  eventName: `用户中心`,
  eventType: `加载`,
  eventCategory: '0',
})

// 特殊情况下需要销毁,或者取消埋点,可以在put之前中断
// t.abort('user-center') // or t.destroy()

// 当页面加载完成,手动执行out即可,执行结束时间sdk处理
t.put('user-center')

记录页面停留时间

通过 eventType="停留"来做记录页面停留时长

⚠️ 注意调用put方法时最后一个参数需要为 true,表示记录停留时长,否则默认为页面加载时长

t.add({
  eventCode: 'user-center',
  eventName: `用户中心`,
  eventType: `停留`,
  eventCategory: '0',
})

t.put('user-center', false, false, true)

还可以这样用

// 直接调用
Tracker.of({
  // ...
}).trace({
  // ...
})

Note

环境配置:

  • 仅支持developmentproduction 两种环境配置,默认development,各项目不同环境自行配置 Tracker 环境
  • 建议开发和测试环境都设置为development,线上或者预发才使用production
const t = new Tracker({
  // ...
})
if (process.env.NODE_ENV === 'production') {
  t.setEnv(`production`)
}
if (process.env.BUILD_ENV === 'test') {
  t.setEnv(`development`)
}
// ...

Docs

npm run doc

git commitlint

git add .
git cz
git push

部署

deploy --domain=tracker.ztoyc.zt --output=doc

或者

npm run deploy