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

@xnsk/weblogger

v0.0.9

Published

先农数科前端业务日志组件

Downloads

6

Readme


category: LOG

@xnsk/weblogger

用于业务日志上报,支持自动上报pvuv,支持上报自定义事件,支持客户端webview和浏览器。

安装

// yarn 
yarn add @xnsk/weblogger
// npm
npm i @xnsk/weblogger
// pnpm
pnpm add @xnsk/weblogger

使用

import { WebLogger } from '@xnsk/weblogger';

// 初始化weblogger
const logger = new WebLogger({
  env: process.env.VUE_APP_TYPE,
  enableErrorCatch: true,
  userId: 'xxx'
}, router);

参数说明

option [env]:required

当前环境,非生产环境开启debug模式

// 初始化的时候传入
const logger = new WebLogger({
  env: process.env.VUE_APP_TYPE,
  enableErrorCatch: true,
});

option [enableErrorCatch]:required

开启错误收集

// 初始化的时候传入
const logger = new WebLogger({
  env: process.env.VUE_APP_TYPE,
  enableErrorCatch: true,
});

option [userId]

userid会属于公共参数,上报事件时会自动带上

// 1. 初始化时传入
const logger = new WebLogger({
  env: process.env.VUE_APP_TYPE,
  enableErrorCatch: true,
  userId: 'xxx'
});

// 2. 或手动注入
logger.setUserId('xxx');

[router]

用于做路由跳转时上报page事件

import router from './router';
const logger = new WebLogger({
  env: process.env.VUE_APP_TYPE,
  enableErrorCatch: true,
  userId: 'xxx'
}, router);

基础用法

上报自定义事件,自定义事件需要在数据平台注册后才能使用

  • 华为分析->管理->事件管理->新建
// onEvent(eventName: string, options?: {[key: string]: any})
logger.onEvent('checkButtonClick', {
  btnType: 'success',
  // ...
})

手动上报进入页面pageStart和离开页面pageEnd事件,如果初始化时传入router参数,这两个事件在页面跳转时会自动上报

logger.pageStart('pageName');
logger.pageEnd('pageName');

// 返回值是Promise类型,可以在then方法处理后续操作
logger.pageStart('页面A').then(() => {
  // 进入页面A了...
})

手动设置当前App版本号,如果在App端,版本号会自动上传

logger.setAppVersion('1.0.0');

获取当前设备标识id

logger.getAAID();