trackersdk2 1.0.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.
- package/LICENSE +21 -0
- package/dist/TrackerSDK.d.ts +123 -0
- package/dist/index.cjs.js +588 -0
- package/dist/index.d.ts +151 -0
- package/dist/index.esm.js +582 -0
- package/dist/index.js +592 -0
- package/dist/types.d.ts +21 -0
- package/package.json +32 -0
- package/rollup.config.js +43 -0
- package/src/core/TrackerSDK.ts +561 -0
- package/src/core/index.ts +16 -0
- package/src/core/types.ts +29 -0
- package/tsconfig.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 黄文杰
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { TrackerConfig, TrackEvent, TagNames } from "./types";
|
|
2
|
+
export declare class TrackerSDK {
|
|
3
|
+
private config;
|
|
4
|
+
private autoTrackClickHandler;
|
|
5
|
+
private eventQueue;
|
|
6
|
+
private batchTimer;
|
|
7
|
+
private hasSentBeforeUnload;
|
|
8
|
+
constructor();
|
|
9
|
+
init(config: TrackerConfig): void;
|
|
10
|
+
/**
|
|
11
|
+
* @description 重试批量上报之前上报失败的数据
|
|
12
|
+
* @returns Promise<void>
|
|
13
|
+
*/
|
|
14
|
+
private retryFailedBatches;
|
|
15
|
+
/**
|
|
16
|
+
* @description 监听页面卸载事件,确保数据上报
|
|
17
|
+
* @returns void
|
|
18
|
+
*/
|
|
19
|
+
private setupPageUnloadHandler;
|
|
20
|
+
/**
|
|
21
|
+
* @description 获取设备id
|
|
22
|
+
*/
|
|
23
|
+
private getDeviceId;
|
|
24
|
+
/**
|
|
25
|
+
* @description navigator.sendBeacon 和 fetch 双通道实现数据上报
|
|
26
|
+
* @param data 上报的负载
|
|
27
|
+
*/
|
|
28
|
+
private send;
|
|
29
|
+
/**
|
|
30
|
+
* @description 入队列
|
|
31
|
+
* @param payload 上报的负载
|
|
32
|
+
*/
|
|
33
|
+
private enqueue;
|
|
34
|
+
/**
|
|
35
|
+
* @description 刷新队列,批量上报
|
|
36
|
+
* @return void
|
|
37
|
+
*/
|
|
38
|
+
private flush;
|
|
39
|
+
/**
|
|
40
|
+
* @description navigator.sendBeacon单条错误上报失败的fetch回退方案
|
|
41
|
+
* @param payload any
|
|
42
|
+
* */
|
|
43
|
+
private fallbackSend;
|
|
44
|
+
/**
|
|
45
|
+
* @description 错误事件立即上报
|
|
46
|
+
* @param data 上报的负载
|
|
47
|
+
* @returns void
|
|
48
|
+
*/
|
|
49
|
+
sendImmediately(payload: TrackEvent): void;
|
|
50
|
+
/**
|
|
51
|
+
* @description 批量上报
|
|
52
|
+
* @param events 上报的事件数组
|
|
53
|
+
* @returns Promise<void>
|
|
54
|
+
*/
|
|
55
|
+
private sendBatch;
|
|
56
|
+
/**
|
|
57
|
+
* @description 批量上报的fetch回退方案
|
|
58
|
+
* @param payload 上报的负载
|
|
59
|
+
* @returns Promise<void>
|
|
60
|
+
*/
|
|
61
|
+
private fallbackSendBatch;
|
|
62
|
+
private saveFailedBatch;
|
|
63
|
+
/**
|
|
64
|
+
* @description 自定义点击事件
|
|
65
|
+
*/
|
|
66
|
+
track(event: string, properties?: Record<string, any>): void;
|
|
67
|
+
/**
|
|
68
|
+
* @description 用于自动点击埋点
|
|
69
|
+
*
|
|
70
|
+
* @param element 点击的DOM元素
|
|
71
|
+
*/
|
|
72
|
+
trackClick(element: Element): void;
|
|
73
|
+
/**
|
|
74
|
+
* @description 自动pv
|
|
75
|
+
*
|
|
76
|
+
* @param path pv的页面路径
|
|
77
|
+
* @param properties 上报数据
|
|
78
|
+
*/
|
|
79
|
+
trackPV(path: string, properties?: Record<string, any>): void;
|
|
80
|
+
/**
|
|
81
|
+
* @description 统计uv(每天每个设备只上报一次)
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
trackUV(): void;
|
|
85
|
+
/** @description 初始化错误事件监听
|
|
86
|
+
*
|
|
87
|
+
*/
|
|
88
|
+
setupErrorTracking(): void;
|
|
89
|
+
/**
|
|
90
|
+
* @description vue3 全局错误处理器
|
|
91
|
+
*/
|
|
92
|
+
setupVueErrorHandlder(app: any): void;
|
|
93
|
+
private setupPerformanceTracking;
|
|
94
|
+
/**
|
|
95
|
+
* @description 监控FCP
|
|
96
|
+
* @returns void
|
|
97
|
+
*/
|
|
98
|
+
private observeFCP;
|
|
99
|
+
/**
|
|
100
|
+
* @description 监控LCP
|
|
101
|
+
* @returns void
|
|
102
|
+
*/
|
|
103
|
+
private observeLCP;
|
|
104
|
+
/**
|
|
105
|
+
* @description 监控CLS
|
|
106
|
+
* @returns void
|
|
107
|
+
*/
|
|
108
|
+
private observeCLS;
|
|
109
|
+
/**
|
|
110
|
+
* @description 监控TTFB
|
|
111
|
+
* @returns void
|
|
112
|
+
*/
|
|
113
|
+
private observeTTFB;
|
|
114
|
+
/**
|
|
115
|
+
* @description 全埋点(谨慎使用,存在性能问题)
|
|
116
|
+
*/
|
|
117
|
+
enableAutoTracking(): void;
|
|
118
|
+
/**
|
|
119
|
+
* @description: 设置可触发自动埋点的DOM元素标签名称白名单
|
|
120
|
+
*/
|
|
121
|
+
setEnableAutoClickTagNameList(tagNameList: Array<TagNames>): void;
|
|
122
|
+
}
|
|
123
|
+
export declare const tracker: TrackerSDK;
|