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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
type TagNames = string;
|
|
2
|
+
interface TrackerConfig {
|
|
3
|
+
serverUrl: string;
|
|
4
|
+
appId: string;
|
|
5
|
+
userId?: string;
|
|
6
|
+
autoTrack?: boolean;
|
|
7
|
+
enableAutoClickTagNameList?: Array<TagNames>;
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
batchSize?: number;
|
|
10
|
+
batchInterval?: number;
|
|
11
|
+
}
|
|
12
|
+
interface TrackProperties {
|
|
13
|
+
[propName: string]: string | number | boolean | null | undefined;
|
|
14
|
+
}
|
|
15
|
+
type TrackerEventType = "custom" | "click" | "pv" | "uv" | "error" | "performance";
|
|
16
|
+
interface TrackEvent {
|
|
17
|
+
eventType: TrackerEventType;
|
|
18
|
+
properties?: TrackProperties;
|
|
19
|
+
event?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare class TrackerSDK {
|
|
23
|
+
private config;
|
|
24
|
+
private autoTrackClickHandler;
|
|
25
|
+
private eventQueue;
|
|
26
|
+
private batchTimer;
|
|
27
|
+
private hasSentBeforeUnload;
|
|
28
|
+
constructor();
|
|
29
|
+
init(config: TrackerConfig): void;
|
|
30
|
+
/**
|
|
31
|
+
* @description 重试批量上报之前上报失败的数据
|
|
32
|
+
* @returns Promise<void>
|
|
33
|
+
*/
|
|
34
|
+
private retryFailedBatches;
|
|
35
|
+
/**
|
|
36
|
+
* @description 监听页面卸载事件,确保数据上报
|
|
37
|
+
* @returns void
|
|
38
|
+
*/
|
|
39
|
+
private setupPageUnloadHandler;
|
|
40
|
+
/**
|
|
41
|
+
* @description 获取设备id
|
|
42
|
+
*/
|
|
43
|
+
private getDeviceId;
|
|
44
|
+
/**
|
|
45
|
+
* @description navigator.sendBeacon 和 fetch 双通道实现数据上报
|
|
46
|
+
* @param data 上报的负载
|
|
47
|
+
*/
|
|
48
|
+
private send;
|
|
49
|
+
/**
|
|
50
|
+
* @description 入队列
|
|
51
|
+
* @param payload 上报的负载
|
|
52
|
+
*/
|
|
53
|
+
private enqueue;
|
|
54
|
+
/**
|
|
55
|
+
* @description 刷新队列,批量上报
|
|
56
|
+
* @return void
|
|
57
|
+
*/
|
|
58
|
+
private flush;
|
|
59
|
+
/**
|
|
60
|
+
* @description navigator.sendBeacon单条错误上报失败的fetch回退方案
|
|
61
|
+
* @param payload any
|
|
62
|
+
* */
|
|
63
|
+
private fallbackSend;
|
|
64
|
+
/**
|
|
65
|
+
* @description 错误事件立即上报
|
|
66
|
+
* @param data 上报的负载
|
|
67
|
+
* @returns void
|
|
68
|
+
*/
|
|
69
|
+
sendImmediately(payload: TrackEvent): void;
|
|
70
|
+
/**
|
|
71
|
+
* @description 批量上报
|
|
72
|
+
* @param events 上报的事件数组
|
|
73
|
+
* @returns Promise<void>
|
|
74
|
+
*/
|
|
75
|
+
private sendBatch;
|
|
76
|
+
/**
|
|
77
|
+
* @description 批量上报的fetch回退方案
|
|
78
|
+
* @param payload 上报的负载
|
|
79
|
+
* @returns Promise<void>
|
|
80
|
+
*/
|
|
81
|
+
private fallbackSendBatch;
|
|
82
|
+
private saveFailedBatch;
|
|
83
|
+
/**
|
|
84
|
+
* @description 自定义点击事件
|
|
85
|
+
*/
|
|
86
|
+
track(event: string, properties?: Record<string, any>): void;
|
|
87
|
+
/**
|
|
88
|
+
* @description 用于自动点击埋点
|
|
89
|
+
*
|
|
90
|
+
* @param element 点击的DOM元素
|
|
91
|
+
*/
|
|
92
|
+
trackClick(element: Element): void;
|
|
93
|
+
/**
|
|
94
|
+
* @description 自动pv
|
|
95
|
+
*
|
|
96
|
+
* @param path pv的页面路径
|
|
97
|
+
* @param properties 上报数据
|
|
98
|
+
*/
|
|
99
|
+
trackPV(path: string, properties?: Record<string, any>): void;
|
|
100
|
+
/**
|
|
101
|
+
* @description 统计uv(每天每个设备只上报一次)
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
trackUV(): void;
|
|
105
|
+
/** @description 初始化错误事件监听
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
setupErrorTracking(): void;
|
|
109
|
+
/**
|
|
110
|
+
* @description vue3 全局错误处理器
|
|
111
|
+
*/
|
|
112
|
+
setupVueErrorHandlder(app: any): void;
|
|
113
|
+
private setupPerformanceTracking;
|
|
114
|
+
/**
|
|
115
|
+
* @description 监控FCP
|
|
116
|
+
* @returns void
|
|
117
|
+
*/
|
|
118
|
+
private observeFCP;
|
|
119
|
+
/**
|
|
120
|
+
* @description 监控LCP
|
|
121
|
+
* @returns void
|
|
122
|
+
*/
|
|
123
|
+
private observeLCP;
|
|
124
|
+
/**
|
|
125
|
+
* @description 监控CLS
|
|
126
|
+
* @returns void
|
|
127
|
+
*/
|
|
128
|
+
private observeCLS;
|
|
129
|
+
/**
|
|
130
|
+
* @description 监控TTFB
|
|
131
|
+
* @returns void
|
|
132
|
+
*/
|
|
133
|
+
private observeTTFB;
|
|
134
|
+
/**
|
|
135
|
+
* @description 全埋点(谨慎使用,存在性能问题)
|
|
136
|
+
*/
|
|
137
|
+
enableAutoTracking(): void;
|
|
138
|
+
/**
|
|
139
|
+
* @description: 设置可触发自动埋点的DOM元素标签名称白名单
|
|
140
|
+
*/
|
|
141
|
+
setEnableAutoClickTagNameList(tagNameList: Array<TagNames>): void;
|
|
142
|
+
}
|
|
143
|
+
declare const tracker: TrackerSDK;
|
|
144
|
+
|
|
145
|
+
declare const _default: {
|
|
146
|
+
install(app: any, options: TrackerConfig): void;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
declare function useTracker(): TrackerSDK;
|
|
150
|
+
|
|
151
|
+
export { _default as default, tracker, useTracker };
|