🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

monitor-track

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Potential malware was recently detected in this package.

Affected versions:

1.12.01.12.1

monitor-track

前端监控及埋点SDK工具javascript版本

latest
npmnpm
Version
1.15.0
Version published
Weekly downloads
178
178.13%
Maintainers
1
Weekly downloads
 
Created
Source

前端监控及埋点 SDK 工具

使用

# using npm
$ npm install monitor-track -S

import Track from 'monitor-track';

const track = new Track();

track.init({
  projectID: 'IuggBOP==',   // 由监控平台后台管理系统创建项目时生成
  reportUrl: 'https://api-track.zhoushoujian.com/monitor-service/s/r', //上报地址
  spa: true,
  hash: true, // 不是hash模式的项目一定要改成false,否则不能统计到pv的类型
  enable: true,
  customPayload,
  ignore: {
    errors: [
      'ResizeObserver loop limit exceeded',
      'ResizeObserver loop completed with undelivered notifications.',
    ],
  },

});

// 注意:sdk默认取localStorage.getItem('username')作为uuid,所以如果要将用户名作为用户标识,请将username存到localStorage中
// 如果localStorage.getItem('username')取不到值,则会使用uuid作为用户标识,这时用户标识是匿名的,有可能会出现一个用户统计为两个或多个用户的情况

配置项

配置项类型必填默认值注释
reportUrlstring''上报地址,后台地址
projectIDstring''项目 ID
spabooleanfalse是否为单页面应用,主要区别页面性能,及路由切换行为
hashbooleanfalse路由是否为 hash 模式
enableBehaviorbooleantrue启用用户行为上报
enableErrorbooleantrue启用异常信息上报
enableErrorScreenshotbooleanfalse启用异常时的截图上报
enableErrorEventbooleanfalse启用异常时的录像上报
enableVisualTrackbooleanfalse启用可视化埋点上报
enableLagTrackbooleanfalse启用页面卡顿信息上报
lagTimeoutnumber400页面卡顿上报的阈值时间(毫秒)
enableRecordbooleanfalse启用页面录制
enableOnlinePersonsbooleantrue显示在线人数
ignore见下方 ignorefalse忽略上报的信息
customPayloadstringfalse自定义 payload
enablebooleanfalse是否开启日志收集,默认关闭
maxLengthnumber1000最长上报数据长度
XMLHttpRequestTimeoutnumber1000上报 xhr 请求超过指定时间

ignore

参数类型必填默认值注释
urlsstring[][]忽略的 url
errorsstring[][]忽略的异常信息
apisstring[][]忽略的接口

全局方法

//注意:以下window上的方法,如果没有enable埋点,那么这些window上的方法都不存在

//手动上报视频录像, 视频时间应当在30秒到60秒之间
if (typeof window.getRRWebUserEventsCaptureFunc !== 'undefined') {
  window.getRRWebUserEventsCaptureFunc()
} else {
  //console.log('getRRWebUserEventsCaptureFunc is undefined, check monitor-track version!)
}

//手动截图, 图片内容包含整个页面内容,注意getFullScreenShootFunc返回一个Promise
if (typeof window.getFullScreenShootFunc !== 'undefined') {
  window.getFullScreenShootFunc().catch((err) => { console.error('截图失败', err) })
} else {
  //console.log('getFullScreenShootFunc is undefined, check monitor-track version!)
}

//手动上报,data必须是一个对象
if (typeof window.manualReportTrackFunc !== 'undefined') {
  window.manualReportTrackFunc(data)
} else {
  //console.log('manualReportTrackFunc is undefined, check monitor-track version!)
}

项目引入时,定义环境变量,防止开发环境中上报信息

// webpack中配置环境变量

new webpack.DefinePlugin({
  isDev: 'development',
});
const isDevEnv = typeof isDev !== 'undefined';

if (isDevEnv) {
  track.init({
    // 由监控平台后台管理系统创建项目时生成
    projectID: '123',
    reportUrl: 'http://localhost:3008/report',
    spa: true,
    // 不是hash模式的项目一定要改成false,否则不能统计到pv的类型
    hash: true,
  });
}

Keywords

monitor

FAQs

Package last updated on 16 Jun 2026

Did you know?

Socket

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.

Install

Related posts