# frontend-monitor-sdk **Repository Path**: JustTwo/frontend-monitor-sdk ## Basic Information - **Project Name**: frontend-monitor-sdk - **Description**: 前端监控 - **Primary Language**: JavaScript - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-09 - **Last Updated**: 2025-09-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # justwo-frontend-monitor-sdk 轻量级前端监控SDK,支持错误监控、性能监控、用户行为监控。 src/ ├── index.ts # SDK入口(导出核心类) ├── core/ │ ├── reporter.ts # 上报核心模块(批量、重试) │ ├── errorMonitor.ts # 错误监控模块 │ ├── performanceMonitor.ts # 性能监控模块 │ └── behaviorMonitor.ts # 行为监控模块 ├── types/ # 类型定义(TypeScript) │ └── index.ts └── utils/ # 工具函数 ├── helper.ts # 通用工具 └── validator.ts # 数据校验 ## 安装 ```bash npm install justwo-frontend-monitor-sdk --save # 或 yarn add justwo-frontend-monitor-sdk ``` ## 使用 ``` import MonitorSDK from 'justwo-frontend-monitor-sdk'; // 初始化SDK const monitor = new MonitorSDK({ reportUrl: 'https://your-api.com/report', // 你的上报接口 appKey: 'your_app_key' // 应用标识(可选) }); // 手动上报行为 monitor.track('user_login', { username: 'test' }); // 上报HTTP错误 monitor.reportHttpError('https://api.example.com', 'GET', 500, 'Server Error'); ``` ### API 文档 参数 类型 说明 默认值 reportUrl string 上报接口 URL(必填) - appKey string 应用标识 - batchSize number 批量上报阈值 10 batchInterval number 批量上报间隔(ms) 30000 enableError boolean 是否开启错误监控 true enablePerformance boolean 是否开启性能监控 true enableBehavior boolean 是否开启行为监控 true ### 实例方法 track(action: string, data?: object):手动上报自定义行为 reportError(error: Error | string):手动上报错误 reportHttpError(url: string, method: string, status: number, error: string):上报 HTTP 错误 enableAutoTrackClick():开启点击行为自动追踪 ### npm 包管理 #### 1. 修复代码后,本地测试通过 ##### 1.1 修复 bug,更新补丁版本(如 1.0.0 → 1.0.1) npm version patch ##### 1.2 新增功能,更新次版本(如 1.0.1 → 1.1.0) npm version minor ##### 1.3 重大变更,更新主版本(如 1.1.0 → 2.0.0) npm version major #### 2. 更新补丁版本(假设当前版本是 1.0.0) npm version patch # 版本变为 1.0.1 #### 3. 重新打包 npm run build #### 4. 发布新版本 npm publish