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

@hyext/hyext-reporter-ext

v1.2.3

Published

小程序上报日志统一小程序版本

Downloads

80

Readme

小程序统一日志上报

  • @hyext/hyext-reporter-ext
  • 负责统一小程序日志数据及上报
  • 可自动获取部分基础数据,需申请【自定义统计上报 】权限
  • 支持主动上报日志,并规定了一些行为的关键词
  • 提供全局心跳,默认 30 秒心跳一次
  • 日志延迟 500ms 上报,前端上报接口有调用频率限制;
  • 单次上报最多 25KB(数据量大会导致数据丢失)
  • 过于频繁或大量的数据上报推荐使用后端上报,前端上报不保险

安装

npm i -save @hyext/hyext-reporter-ext

引入

import { HYExtReporter, LogEvents } from '@hyext/hyext-reporter-ext'

示例

const extReporter = new HYExtReporter({
  Debug: true
})

extReporter.reportBusiMetric(LogEvents.GAME_CREATE);
extReporter.reportBusiMetric(LogEvents.USER_ACTIVE);
extReporter.startHeartBeat()

初始化 - new HYExtReporter(config)

config

  • 实例化配置信息

| 参数 | 类型 | 必填 | 默认 | 说明 | | ------------------------- | ------- | ---- | ----- | ------------------------------ | | CommonInfo | Object | 否 | -- | 日志公用信息 | | OpenReport | boolean | 否 | true | 是否开启上报 | | Debug | boolean | 否 | false | 是否开启 debug | | UseHighFreqPcReport | boolean | 否 | false | PC 端开启高频上报 | | ReportDelay | number | 否 | 500 | 延迟上报时差(ms),0 不延迟 | | ReportSizeLimit | number | 否 | 25 | 每次上报大小上限(KB),0 不限制 |

CommonInfo

  • 日志公共数据,每条日志的基础信息,可覆盖

| 参数 | 类型 | 必填 | 说明 | | ----------- | ------ | ---- | ------------------------------------------------------------------------- | | ext_id | string | 否 | 小程序 ID,默认获取 | | uid | string | 否 | 用户 ID,授权后获取 | | pid | string | 否 | 主播 ID,授权后获取 | | game_id | string | 否 | 品类 ID,授权后获取 | | env | string | 否 | 环境信息,默认当前构建环境 |

env

  • 环境信息

| 取值 | 说明 | | ------- | -------- | | unknown | 未知环境 | | online | 正式环境 | | test | 测试环境 | | dev | 开发环境 |

示例

  • 实例化
const extReporter = new HYExtReporter({
  Debug: true
});

开始心跳 - extReporter.startHeartBeat(fields);

  • 只有一个全局的心跳
  • 默认 30s 一次心跳
  • 心跳用于统计用户在线时长,用户进入即开始心跳即可

参数

| 参数 | 类型 | 必填 | 默认 | 说明 | | ----------------- | ------ | ---- | ---- | -------------- | | fields | Object | 否 | -- | 日志自定义数据 |

示例

extReporter.startHeartBeat();

停止心跳 - extReporter.endHeartBeat()

  • 停止全局的心跳
  • 用户退出时调用

示例

extReporter.endHeartBeat();

普通上报 - extReporter.reportBusiMetric(info, fields)

参数

| 参数 | 类型 | 必填 | 默认 | 说明 | | ----------------- | ------ | ---- | ---- | ---------------------------- | | info | Object | 是 | -- | 日志描述,不会被 fields 覆盖 | | fields | Object | 否 | -- | 日志自定义数据 |

info

  • 日志描述信息,不会被 fields 覆盖
  • 系统预制了一些日志描述信息 LogEvents 方便使用
  • 也可定义自己日志描述信息

| 参数 | 类型 | 必填 | 说明 | | ---- | ------ | ---- | ---------- | | key | string | 是 | 业务关键词 | | desc | string | 是 | 业务描述 |

LogEvents

  • 预制日志描述信息
  • 均为与 info 同构变量
  • 按需上报即可

| 变量 | 描述 | | ------------------------ | ---------------------- | | LogEvents.USER_ACTIVE | 用户互动 | | LogEvents.USER_SEND_GIFT | 用户送礼 | | LogEvents.USER_SEND_WORD | 用户发言 | | LogEvents.USER_SUBSCRIBE | 用户订阅 | | LogEvents.USER_SHARE | 用户分享 | | LogEvents.GAME_CREATE | 游戏开局,某轮游戏开始 | | LogEvents.GAME_FINISH | 游戏结束,某轮游戏结束 |

fields

  • 自定义上报数据
  • 键值不能与以下取值重复,否则会被覆盖

| 敏感键值 | 类型 | 说明 | 数据源 | | ----------- | ------ | -------------- | ----------- | | key | string | 业务关键词 | info | | desc | string | 业务描述 | info | | type | number | 日志类型 | info/默认值 | | client_time | number | 日志创建时间戳 | 系统生成 |

示例

  • 自定义上报
extReporter.reportBusiMetric({
  key: 'ext_diy/my_action'
  desc: '自定义事件描述'
}, {
  data : 'your_data'
});
  • 上报用户交互
extReporter.reportBusiMetric(LogEvents.USER_ACTIVE, {
  act: '啥交互?'
});
  • 上报用户送礼
extReporter.reportBusiMetric(LogEvents.USER_SEND_GIFT, {
  gift_id: 2222,
  gift_count: 1,
  gift_amount: 100,
  total_pay: 0,
});
  • 上报用户发言
extReporter.reportBusiMetric(LogEvents.USER_SEND_WORD, {
  word: '你说啥?'
});
  • 上报订阅主播
extReporter.reportBusiMetric(LogEvents.USER_SUBSCRIBE);
  • 上报用户分享
extReporter.reportBusiMetric(LogEvents.USER_SHARE, {
  share_type: 1
});
  • 上报开始游戏
extReporter.reportBusiMetric(LogEvents.GAME_CREATE);
  • 上报游戏结束
extReporter.reportBusiMetric(LogEvents.GAME_FINISH);