monitor-track 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +101 -0
  3. package/dist/CHANGELOG.md +21 -0
  4. package/dist/README.md +101 -0
  5. package/dist/cjs/config/global.d.ts +17 -0
  6. package/dist/cjs/config/index.d.ts +33 -0
  7. package/dist/cjs/constant.d.ts +2 -0
  8. package/dist/cjs/handlers/error.d.ts +23 -0
  9. package/dist/cjs/handlers/index.d.ts +3 -0
  10. package/dist/cjs/handlers/pv.d.ts +24 -0
  11. package/dist/cjs/handlers/user-activity.d.ts +9 -0
  12. package/dist/cjs/index.d.ts +30 -0
  13. package/dist/cjs/index.js +1485 -0
  14. package/dist/cjs/main.d.ts +1 -0
  15. package/dist/cjs/reporter.d.ts +198 -0
  16. package/dist/cjs/types/config.d.ts +59 -0
  17. package/dist/cjs/types/global.d.ts +70 -0
  18. package/dist/cjs/types/index.d.ts +189 -0
  19. package/dist/cjs/utils/index.d.ts +45 -0
  20. package/dist/esm/_virtual/_tslib.js +26 -0
  21. package/dist/esm/config/global.d.ts +17 -0
  22. package/dist/esm/config/global.js +271 -0
  23. package/dist/esm/config/index.d.ts +33 -0
  24. package/dist/esm/config/index.js +32 -0
  25. package/dist/esm/constant.d.ts +2 -0
  26. package/dist/esm/constant.js +4 -0
  27. package/dist/esm/handlers/error.d.ts +23 -0
  28. package/dist/esm/handlers/error.js +181 -0
  29. package/dist/esm/handlers/index.d.ts +3 -0
  30. package/dist/esm/handlers/pv.d.ts +24 -0
  31. package/dist/esm/handlers/pv.js +99 -0
  32. package/dist/esm/handlers/user-activity.d.ts +9 -0
  33. package/dist/esm/handlers/user-activity.js +66 -0
  34. package/dist/esm/index.d.ts +30 -0
  35. package/dist/esm/index.js +115 -0
  36. package/dist/esm/main.d.ts +1 -0
  37. package/dist/esm/package.json.js +3 -0
  38. package/dist/esm/reporter.d.ts +198 -0
  39. package/dist/esm/reporter.js +359 -0
  40. package/dist/esm/types/config.d.ts +59 -0
  41. package/dist/esm/types/global.d.ts +70 -0
  42. package/dist/esm/types/index.d.ts +189 -0
  43. package/dist/esm/utils/index.d.ts +45 -0
  44. package/dist/esm/utils/index.js +354 -0
  45. package/dist/index.js +1534 -0
  46. package/dist/package.json +41 -0
  47. package/package.json +42 -0
  48. package/rollup.config.js +66 -0
  49. package/scripts/cp.js +11 -0
  50. package/src/config/global.ts +309 -0
  51. package/src/config/index.ts +53 -0
  52. package/src/constant.ts +2 -0
  53. package/src/handlers/error.ts +187 -0
  54. package/src/handlers/index.ts +3 -0
  55. package/src/handlers/pv.ts +124 -0
  56. package/src/handlers/user-activity.ts +69 -0
  57. package/src/index.ts +127 -0
  58. package/src/main.ts +8 -0
  59. package/src/reporter.ts +372 -0
  60. package/src/types/config.ts +58 -0
  61. package/src/types/global.ts +73 -0
  62. package/src/types/index.ts +227 -0
  63. package/src/typing.d.ts +15 -0
  64. package/src/utils/index.ts +371 -0
  65. package/tsconfig.esm.json +14 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.10.0 (2023-08-25)
7
+
8
+
9
+ ### ✨ Features
10
+
11
+ * monitor ([23011cb](https://github.com/zhoushoujian/monitor/commit/23011cb1b2c15adf4de96c481f3b11347673b715))
12
+ * update ([3c21c91](https://github.com/zhoushoujian/monitor/commit/3c21c91afc136333145c3512576051f4e915f15c))
13
+
14
+
15
+
16
+ ## 1.10.0 (2023-08-25)
17
+
18
+
19
+ ### ✨ Features
20
+
21
+ * monitor ([23011cb](https://github.com/zhoushoujian/monitor/commit/23011cb1b2c15adf4de96c481f3b11347673b715))
22
+ * update ([22968bc](https://github.com/zhoushoujian/monitor/commit/22968bc7aaef009637b91ff01ca0a07a441d652b))
23
+
24
+
25
+
26
+ ## 1.10.0 (2023-08-25)
27
+
28
+
29
+ ### ✨ Features
30
+
31
+ * monitor ([23011cb](https://github.com/zhoushoujian/monitor/commit/23011cb1b2c15adf4de96c481f3b11347673b715))
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # 前端监控及埋点 SDK 工具
2
+
3
+ ## 使用
4
+
5
+ ```shell
6
+ # using npm
7
+ $ npm install monitor-track -S
8
+
9
+ ```
10
+
11
+ ```typescript
12
+ import Track from 'monitor-track';
13
+
14
+ const track = new Track();
15
+
16
+ track.init({
17
+ // 由监控平台后台管理系统创建项目时生成
18
+ projectID: '123',
19
+ reportUrl: 'http://localhost:3008/report',
20
+ spa: true,
21
+ // 不是hash模式的项目一定要改成false,否则不能统计到pv的类型
22
+ hash: true,
23
+ });
24
+ ```
25
+
26
+ ## 配置项
27
+
28
+ | 配置项 | 类型 | 必填 | 默认值 | 注释 |
29
+ | --------------------- | ------------- | ---- | ------ | -------------------------------------------------- |
30
+ | reportUrl | string | 是 | '' | 上报地址,后台地址 |
31
+ | projectID | string | 是 | '' | 项目 ID |
32
+ | spa | boolean | 否 | false | 是否为单页面应用,主要区别页面性能,及路由切换行为 |
33
+ | hash | boolean | 否 | false | 路由是否为 hash 模式 |
34
+ | enableBehavior | boolean | 否 | true | 启用用户行为上报 |
35
+ | enableError | boolean | 否 | true | 启用异常信息上报 |
36
+ | enableVisualTrack | boolean | 否 | false | 启用可视化埋点上报 |
37
+ | ignore | 见下方 ignore | 否 | false | 忽略上报的信息 |
38
+ | customPayload | string | 否 | false | 自定义 payload |
39
+ | enable | boolean | 否 | false | 是否开启日志收集,默认关闭 |
40
+ | maxLength | number | 否 | 1000 | 最长上报数据长度 |
41
+ | XMLHttpRequestTimeout | number | 否 | 1000 | 上报 xhr 请求超过指定时间 |
42
+
43
+ ### ignore
44
+
45
+ | 参数 | 类型 | 必填 | 默认值 | 注释 |
46
+ | ------ | -------- | ---- | ------ | -------------- |
47
+ | urls | string[] | 否 | [] | 忽略的 url |
48
+ | errors | string[] | 否 | [] | 忽略的异常信息 |
49
+ | apis | string[] | 否 | [] | 忽略的接口 |
50
+
51
+ ## 全局方法
52
+
53
+ ```typescript
54
+ //注意:以下window上的方法,如果没有enable埋点,那么这些window上的方法都不存在
55
+
56
+ //手动上报视频录像, 视频时间应当在30秒到60秒之间
57
+ if (typeof window.getRRWebUserEventsCaptureFunc !== 'undefined') {
58
+ window.getRRWebUserEventsCaptureFunc()
59
+ } else {
60
+ //console.log('getRRWebUserEventsCaptureFunc is undefined, check monitor-track version!)
61
+ }
62
+
63
+ //手动截图, 图片内容包含整个页面内容,注意getFullScreenShootFunc返回一个Promise
64
+ if (typeof window.getFullScreenShootFunc !== 'undefined') {
65
+ window.getFullScreenShootFunc().catch((err) => { console.error('截图失败', err) })
66
+ } else {
67
+ //console.log('getFullScreenShootFunc is undefined, check monitor-track version!)
68
+ }
69
+
70
+ //手动上报,data必须是一个对象
71
+ if (typeof window.manualReportTrackFunc !== 'undefined') {
72
+ window.manualReportTrackFunc(data)
73
+ } else {
74
+ //console.log('manualReportTrackFunc is undefined, check monitor-track version!)
75
+ }
76
+ ```
77
+
78
+ ## 项目引入时,定义环境变量,防止开发环境中上报信息
79
+
80
+ ```javascript
81
+ // webpack中配置环境变量
82
+
83
+ new webpack.DefinePlugin({
84
+ isDev: 'development',
85
+ });
86
+ ```
87
+
88
+ ```typescript
89
+ const isDevEnv = typeof isDev !== 'undefined';
90
+
91
+ if (isDevEnv) {
92
+ track.init({
93
+ // 由监控平台后台管理系统创建项目时生成
94
+ projectID: '123',
95
+ reportUrl: 'http://localhost:3008/report',
96
+ spa: true,
97
+ // 不是hash模式的项目一定要改成false,否则不能统计到pv的类型
98
+ hash: true,
99
+ });
100
+ }
101
+ ```
@@ -0,0 +1,21 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.10.0 (2023-08-25)
7
+
8
+
9
+ ### ✨ Features
10
+
11
+ * monitor ([23011cb](https://github.com/zhoushoujian/monitor/commit/23011cb1b2c15adf4de96c481f3b11347673b715))
12
+ * update ([22968bc](https://github.com/zhoushoujian/monitor/commit/22968bc7aaef009637b91ff01ca0a07a441d652b))
13
+
14
+
15
+
16
+ ## 1.10.0 (2023-08-25)
17
+
18
+
19
+ ### ✨ Features
20
+
21
+ * monitor ([23011cb](https://github.com/zhoushoujian/monitor/commit/23011cb1b2c15adf4de96c481f3b11347673b715))
package/dist/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # 前端监控及埋点 SDK 工具
2
+
3
+ ## 使用
4
+
5
+ ```shell
6
+ # using npm
7
+ $ npm install monitor-track -S
8
+
9
+ ```
10
+
11
+ ```typescript
12
+ import Track from 'monitor-track';
13
+
14
+ const track = new Track();
15
+
16
+ track.init({
17
+ // 由监控平台后台管理系统创建项目时生成
18
+ projectID: '123',
19
+ reportUrl: 'http://localhost:3008/report',
20
+ spa: true,
21
+ // 不是hash模式的项目一定要改成false,否则不能统计到pv的类型
22
+ hash: true,
23
+ });
24
+ ```
25
+
26
+ ## 配置项
27
+
28
+ | 配置项 | 类型 | 必填 | 默认值 | 注释 |
29
+ | --------------------- | ------------- | ---- | ------ | -------------------------------------------------- |
30
+ | reportUrl | string | 是 | '' | 上报地址,后台地址 |
31
+ | projectID | string | 是 | '' | 项目 ID |
32
+ | spa | boolean | 否 | false | 是否为单页面应用,主要区别页面性能,及路由切换行为 |
33
+ | hash | boolean | 否 | false | 路由是否为 hash 模式 |
34
+ | enableBehavior | boolean | 否 | true | 启用用户行为上报 |
35
+ | enableError | boolean | 否 | true | 启用异常信息上报 |
36
+ | enableVisualTrack | boolean | 否 | false | 启用可视化埋点上报 |
37
+ | ignore | 见下方 ignore | 否 | false | 忽略上报的信息 |
38
+ | customPayload | string | 否 | false | 自定义 payload |
39
+ | enable | boolean | 否 | false | 是否开启日志收集,默认关闭 |
40
+ | maxLength | number | 否 | 1000 | 最长上报数据长度 |
41
+ | XMLHttpRequestTimeout | number | 否 | 1000 | 上报 xhr 请求超过指定时间 |
42
+
43
+ ### ignore
44
+
45
+ | 参数 | 类型 | 必填 | 默认值 | 注释 |
46
+ | ------ | -------- | ---- | ------ | -------------- |
47
+ | urls | string[] | 否 | [] | 忽略的 url |
48
+ | errors | string[] | 否 | [] | 忽略的异常信息 |
49
+ | apis | string[] | 否 | [] | 忽略的接口 |
50
+
51
+ ## 全局方法
52
+
53
+ ```typescript
54
+ //注意:以下window上的方法,如果没有enable埋点,那么这些window上的方法都不存在
55
+
56
+ //手动上报视频录像, 视频时间应当在30秒到60秒之间
57
+ if (typeof window.getRRWebUserEventsCaptureFunc !== 'undefined') {
58
+ window.getRRWebUserEventsCaptureFunc()
59
+ } else {
60
+ //console.log('getRRWebUserEventsCaptureFunc is undefined, check monitor-track version!)
61
+ }
62
+
63
+ //手动截图, 图片内容包含整个页面内容,注意getFullScreenShootFunc返回一个Promise
64
+ if (typeof window.getFullScreenShootFunc !== 'undefined') {
65
+ window.getFullScreenShootFunc().catch((err) => { console.error('截图失败', err) })
66
+ } else {
67
+ //console.log('getFullScreenShootFunc is undefined, check monitor-track version!)
68
+ }
69
+
70
+ //手动上报,data必须是一个对象
71
+ if (typeof window.manualReportTrackFunc !== 'undefined') {
72
+ window.manualReportTrackFunc(data)
73
+ } else {
74
+ //console.log('manualReportTrackFunc is undefined, check monitor-track version!)
75
+ }
76
+ ```
77
+
78
+ ## 项目引入时,定义环境变量,防止开发环境中上报信息
79
+
80
+ ```javascript
81
+ // webpack中配置环境变量
82
+
83
+ new webpack.DefinePlugin({
84
+ isDev: 'development',
85
+ });
86
+ ```
87
+
88
+ ```typescript
89
+ const isDevEnv = typeof isDev !== 'undefined';
90
+
91
+ if (isDevEnv) {
92
+ track.init({
93
+ // 由监控平台后台管理系统创建项目时生成
94
+ projectID: '123',
95
+ reportUrl: 'http://localhost:3008/report',
96
+ spa: true,
97
+ // 不是hash模式的项目一定要改成false,否则不能统计到pv的类型
98
+ hash: true,
99
+ });
100
+ }
101
+ ```
@@ -0,0 +1,17 @@
1
+ import { IReport } from '../types/global';
2
+ /**
3
+ * @description 初始化上报数据并上报
4
+ */
5
+ export declare function initReport(): void;
6
+ /**
7
+ * @description 设置Report的值
8
+ * @param key Report key
9
+ * @param value Report 值
10
+ */
11
+ export declare function setReportValue<T extends IReport, K extends keyof T>(key: K, value: T[K]): void;
12
+ /**
13
+ * @description 获取上报数据
14
+ */
15
+ export declare function getReport(): IReport;
16
+ export declare const recordXMLHttpRequestLog: (XMLHttpRequestTimeout?: number) => void;
17
+ export declare const hackFetch: (XMLHttpRequestTimeout?: number) => void;
@@ -0,0 +1,33 @@
1
+ import { IConfig } from '../types/config';
2
+ /** */
3
+ /**
4
+ * @description config配置项默认值
5
+ */
6
+ export declare const Config: IConfig;
7
+ /**
8
+ * @description 设置config配置项
9
+ * @param config 配置项
10
+ */
11
+ export declare function setConfig(config: IConfig): void;
12
+ /**
13
+ * @description 设置config配置项
14
+ * @param config 配置项
15
+ */
16
+ export declare function setConfigValue<T extends IConfig, K extends keyof T>(key: K, value: T[K]): void;
17
+ /**
18
+ * @description 获取通过key值获取配置项value
19
+ * @param key
20
+ * @returns value的值
21
+ */
22
+ export declare function getConfigValue(key: keyof IConfig): string | number | boolean | {
23
+ urls?: string[] | undefined;
24
+ errors?: (string | {
25
+ regExp: boolean;
26
+ /**
27
+ * @description 设置config配置项
28
+ * @param config 配置项
29
+ */
30
+ input: string;
31
+ })[] | undefined;
32
+ apis?: string[] | undefined;
33
+ } | undefined;
@@ -0,0 +1,2 @@
1
+ export declare const shuyunTrackId = "shuyun-track-id";
2
+ export declare const shuyunTrackSessionId = "shuyun-track-session-id";
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @description 错误事件触发后的操作
3
+ */
4
+ export declare function handleError(event: ErrorEvent | Event | PromiseRejectionEvent): void;
5
+ /**
6
+ * @description 设置错误信息
7
+ */
8
+ export declare function setCaughtError(event: ErrorEvent): void;
9
+ /**
10
+ * @description 设置异步错误信息
11
+ */
12
+ export declare function setPromiseError(event: PromiseRejectionEvent): void;
13
+ /**
14
+ * @description 设置资源错误信息
15
+ */
16
+ export declare function setResourceError(event: Event): void;
17
+ /**
18
+ * 忽略的error
19
+ * @param errorMsg 错误信息
20
+ */
21
+ export declare function ignoreError(errorMsg: string): boolean;
22
+ export declare function getUserEvents(notUseCache: boolean): string | undefined;
23
+ export declare function getFullScreenShoot(filename: string | undefined): Promise<File>;
@@ -0,0 +1,3 @@
1
+ export * as pv from './pv';
2
+ export * as error from './error';
3
+ export * as userActivity from './user-activity';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @description 派发pushState, replaceState 的监听
3
+ * @param type
4
+ */
5
+ export declare function _history(type: 'pushState' | 'replaceState'): () => void;
6
+ /**
7
+ * @description 处理hash变化
8
+ * @param e hash事件
9
+ */
10
+ export declare function handleHashChange(__e: Event): void;
11
+ /**
12
+ * @description 处理history变化
13
+ * @param e history事件
14
+ */
15
+ export declare function handleHistoryChange(__e: Event): void;
16
+ export declare function setPVTime(): void;
17
+ /**
18
+ * @description 添加路由栈信息
19
+ * @param page 页面信息
20
+ */
21
+ export declare function setRouteStack(page: string | string[]): {
22
+ originPage: string;
23
+ page: string;
24
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description 点击事件触发后的操作
3
+ */
4
+ export declare function handleClick(event: Event): void;
5
+ /**
6
+ * @description 点击触发失焦后的操作
7
+ */
8
+ export declare function handleBlur(event: Event): void;
9
+ export declare function handleScroll(_event: Event): void;
@@ -0,0 +1,30 @@
1
+ import { IConfig } from './types/config';
2
+ export default class Track {
3
+ init(config: IConfig): void;
4
+ visualTrack: () => void;
5
+ /**
6
+ * @description 监听错误异常
7
+ */
8
+ addListenJSUncaught(): void;
9
+ /**
10
+ * @description 监听行为
11
+ */
12
+ addListenUserActivity(): void;
13
+ /**
14
+ * @description 监听路由变化
15
+ */
16
+ addListenRouterChange(): void;
17
+ /**
18
+ * @description 页面将要关闭
19
+ */
20
+ addListenUnload(): void;
21
+ /**
22
+ * 忽略的url
23
+ * @param urls
24
+ */
25
+ ignoreUrl(urls: string[]): boolean;
26
+ /**
27
+ * @description 销毁监听器
28
+ */
29
+ destroy(): void;
30
+ }