# fe-monitor-sdk **Repository Path**: fe-hl/fe-monitor-sdk ## Basic Information - **Project Name**: fe-monitor-sdk - **Description**: 前端监控SDK,轻量级 - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2019-08-28 - **Last Updated**: 2025-07-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: SDK, monitor, TypeScript ## README # 前端监控 SDK ## 安装 ```npm npm i @fe-hl/monitor-sdk -S ``` ## 参数说明 | 参数 | 是否必传 | 默认值 | 说明 | | :--------------------------- | :------: | :----: | :------------------------------: | | pId | true | - | 产品 ID | | reportUrl | true | - | 上报接口地址 | | reportInterval | false | 30 | 上报间隔`默认30秒` | | batchSize | false | 20 | 每次上报的最大条数`默认20条` | | debug | false | false | debug 模式打印控制台,不上报接口 | | jsErrorLog | false | false | js 异常 | | promiseErrorLog | false | false | promise 异常 | | resourcesErrorLog | false | false | 资源加载异常 | | exposureLog | false | false | 曝光埋点 | | automaticBurialPointLog | false | false | 自动埋点 | | pageDwellTimeLog | false | false | 页面停留时间 | | pvLog | false | false | pv | | xhrLog | false | false | 接口监控 | | resourcesPerfLog | false | false | 资源加载性能 | | perfLog | false | false | 页面渲染性能 | | longTaskLog | false | false | 长任务 | | behaviorRecorderLog`(1.3.0)` | false | false | 用户行为录制 | | sampleRate | false | 如下 | 抽样上报比例 | ## sampleRate 抽样上报比例 - 默认值:`0.5`,即上报 50%,`1` 即上报 100% | 参数 | 默认值 | 说明 | | :------------------- | :----: | :----------: | | exposure | 1 | 曝光埋点 | | automaticBurialPoint | 1 | 自动埋点 | | pageDwellTime | 1 | 页面停留时间 | | pv | 1 | pv | | behaviorRecorder | 1 | 用户行为录制 | | xhr | 0.5 | 接口监控 | | resourcesPerf | 0.5 | 资源加载性能 | | perf | 0.5 | 页面渲染性能 | ## 使用 ```js import MonitorSdk from '@fe-hl/monitor-sdk'; const monitorSdk = MonitorSdk({ pId: '1000', // 产品ID reportUrl: 'http://127.0.0.1:9001/report', // 上报的地址 debug: false, // 是否开启debug,开启后打印控制台不上报 jsErrorLog: true, // js异常 promiseErrorLog: true, // promise异常 resourcesErrorLog: true, // 资源加载异常 exposureLog: true, // // 曝光 automaticBurialPointLog: true, // 自动埋点 pageDwellTimeLog: true, // 页面停留时间 pvLog: true, // PV xhrLog: true, // 接口监控 resourcesPerfLog: true, // 资源加载性能 perfLog: true, // 页面渲染性能 longTaskLog: true, // 长任务 behaviorRecorderLog: true, // 用户行为录制 }); ``` ## 手动上报 ```js import { monitorSdk } from '@fe-hl/monitor-sdk'; // 自定义上报 monitorSdk.report({ type: 'click', // 类型必填 message: '下单成功', }); ``` ## 爆光埋点 - 给需要`爆光`的元素加上`data-exposure`属性,当元素在可视区域内,上报接口 ```html