@fle-sdk/event-tracking-web 1.2.0-beta.0 → 1.2.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.
@@ -1,228 +1,466 @@
1
- export interface Target extends Window {
2
- /**
3
- * @description 自定义扩展取消监听函数
4
- * @default
5
- */
6
- detachEvent?: (type: string, fun: (event: Event) => void, bol: boolean) => void;
7
- /**
8
- * @description 自定义扩展添加监听函数
9
- * @default
10
- */
11
- attachEvent?: (type: string, fun: (event: Event) => void, bol: boolean) => void;
12
- }
13
- export interface EventParams extends Event {
14
- /**
15
- * @description 重写添加 arguments
16
- * @default
17
- */
18
- arguments?: any[];
19
- }
20
- export interface JsonProps {
21
- [key: string]: any;
22
- }
23
- /**
24
- * @description 事件类型
25
- */
26
- export declare type EventTypes = "PageView" | "PageRetained" | "CustomTrack" | "WebClick";
27
- export interface PresetParams {
28
- /**
29
- * @description 应用唯一标识(由接口生成)
30
- */
31
- appKey?: string;
32
- /**
33
- * @description 数据接收地址
34
- */
35
- serverUrl?: string;
36
- /**
37
- * @description 手动指定客户端平台类型(h5、pc、ipad、other)
38
- */
39
- platform?: PlatformType | string;
40
- /**
41
- * @description 是否在网页控制台打印发送的数据
42
- * @default false
43
- */
44
- showLog?: boolean;
45
- /**
46
- * @description 是否开启全埋点 指的是:页面浏览、元素点击事件自动上报
47
- * @default true
48
- */
49
- autoTrack?: boolean;
50
- /**
51
- * @description (是否使用客户端系统时间)注意:客户端系统时间可能会不准确,导致该字段不准确
52
- * @default true
53
- */
54
- useClientTime?: boolean;
55
- /**
56
- * @description 接口发送超时时长,超过该时长未发送成功将强制取消,单位:毫秒
57
- * @default 3000
58
- */
59
- sendTimeout?: number;
60
- /**
61
- * @description 是否采集单页面应用的路由变化
62
- * @default false
63
- */
64
- isTrackSinglePage?: boolean;
65
- /**
66
- * @description 数据类型
67
- * @default "application/x-www-form-urlencoded"
68
- */
69
- contentType?: "application/x-www-form-urlencoded" | "application/json";
70
- /**
71
- * @description 全局自定义业务参数
72
- * @default {}
73
- */
74
- business?: {
75
- [key: string]: any;
76
- };
77
- }
78
- export interface InitParams extends PresetParams {
79
- /**
80
- * @description 应用唯一标识(由接口生成)
81
- */
82
- appKey: string;
83
- /**
84
- * @description 数据接收地址
85
- */
86
- serverUrl: string;
87
- }
88
- export declare type PlatformType = "h5" | "pc" | "ipad" | "other";
89
- export interface SystemsInfoTypes {
90
- language?: string;
91
- /**
92
- * 网络类型
93
- */
94
- network?: string;
95
- ua?: string;
96
- /**
97
- * @description 客户端(Mac/Android/iPhone/iPad/iPod/WeChat)
98
- */
99
- client?: string;
100
- /**
101
- * @description 客户端平台类型(h5、pc、ipad)
102
- */
103
- platform?: PlatformType | string;
104
- }
105
- export interface TrackParams {
106
- /**
107
- * @description 控件/自定义事件的唯一标识
108
- */
109
- partkey: string | number;
110
- /**
111
- * @description 自定义代码埋点描述
112
- * @default "自定义代码埋点上报"
113
- */
114
- desc?: string;
115
- /**
116
- * @description 自定义业务参数
117
- * @default {}
118
- */
119
- business?: {
120
- [key: string]: any;
121
- };
122
- }
123
- export interface TargetEleProps {
124
- /**
125
- * @description dom节点名称
126
- */
127
- nodeName?: string;
128
- /**
129
- * @description id类名
130
- */
131
- id?: string;
132
- /**
133
- * @description class类名
134
- */
135
- className?: string;
136
- /**
137
- * @description 元素触发位置:[x, y]
138
- */
139
- position?: [number, number];
140
- }
141
- /**
142
- * @description 基础系统信息
143
- */
144
- export interface PrivateParamProps {
145
- /**
146
- * @description 当前URL
147
- */
148
- currentUrl?: string;
149
- /**
150
- * @description 目标URL
151
- */
152
- targetUrl?: string;
153
- /**
154
- * @description 手动埋点参数
155
- */
156
- business?: JsonProps;
157
- /**
158
- * @description 触发元素属性
159
- */
160
- targetEle?: TargetEleProps;
161
- /**
162
- * @description 页面可视区宽度
163
- */
164
- pageWidth?: number;
165
- /**
166
- * @description 页面可视区高度
167
- */
168
- pageHeight?: number;
169
- /**
170
- * @description 显示屏宽度
171
- */
172
- screenWidth?: number;
173
- /**
174
- * @description 显示屏高度
175
- */
176
- screenHeight?: number;
177
- /**
178
- * @description 手动触发的指针类型
179
- */
180
- pointerType?: "mouse" | "touch" | "pen";
181
- /**
182
- * @description 触发元素链路
183
- */
184
- elementSelector?: string;
185
- /**
186
- * @description 用户信息
187
- */
188
- userInfo?: JsonProps;
189
- /**
190
- * @description 路由参数
191
- */
192
- urlParams?: JsonProps;
193
- /**
194
- * @description 系统信息
195
- */
196
- systemsInfo?: SystemsInfoTypes;
197
- /**
198
- * @description SDk版本
199
- */
200
- sdkVersion?: string;
201
- /**
202
- * @description 页面停留时长(毫秒)
203
- */
204
- retainedDuration?: number;
205
- }
206
- export interface TrackingPostParams {
207
- /**
208
- * @description 事件类型
209
- */
210
- event: EventTypes;
211
- /**
212
- * @description 埋点事件描述
213
- */
214
- desc: string;
215
- /**
216
- * @description 当前埋点事件Key
217
- */
218
- itemKey?: string;
219
- /**
220
- * @description 发送请求事件
221
- */
222
- requestTime?: number;
223
- /**
224
- * @description 私有参数
225
- */
226
- privateParamMap?: PrivateParamProps;
227
- }
228
- export declare type HistoryType = "load" | "beforeunload" | "pushState" | "replaceState" | "popstate" | "hashchange";
1
+ export interface Target extends Window {
2
+ /**
3
+ * @description 自定义扩展取消监听函数
4
+ * @default
5
+ */
6
+ detachEvent?: (type: string, fun: (event: Event) => void, bol: boolean) => void;
7
+ /**
8
+ * @description 自定义扩展添加监听函数
9
+ * @default
10
+ */
11
+ attachEvent?: (type: string, fun: (event: Event) => void, bol: boolean) => void;
12
+ }
13
+ export declare type ContentType = "application/x-www-form-urlencoded" | "application/json";
14
+ export interface EventParams extends Event {
15
+ /**
16
+ * @description 重写添加 arguments
17
+ * @default
18
+ */
19
+ arguments?: IArguments | unknown[];
20
+ }
21
+ /**
22
+ * @description JSON对象类型,支持嵌套对象和基本类型
23
+ * 使用 Record 类型以支持更灵活的值类型
24
+ * 先定义 JsonProps,避免在 JsonValue 中直接循环引用
25
+ */
26
+ export interface JsonProps extends Record<string, JsonValue | unknown> {
27
+ }
28
+ /**
29
+ * @description JSON值类型,支持所有可序列化的值
30
+ * 包含基本类型、JsonProps 对象和 JsonValue 数组
31
+ */
32
+ export declare type JsonValue = string | number | boolean | null | undefined | JsonProps | JsonValue[];
33
+ /**
34
+ * @description 事件类型
35
+ */
36
+ export declare type EventTypes = "PageView" | "PageRetained" | "CustomTrack" | "WebClick";
37
+ export interface PresetParams {
38
+ /**
39
+ * @description 应用唯一标识(由接口生成)
40
+ */
41
+ appKey?: string;
42
+ /**
43
+ * @description 数据接收地址
44
+ */
45
+ serverUrl?: string;
46
+ /**
47
+ * @description 手动指定客户端平台类型(h5、pc、ipad、other)
48
+ */
49
+ platform?: PlatformType | string;
50
+ /**
51
+ * @description 是否在网页控制台打印发送的数据
52
+ * @default false
53
+ */
54
+ showLog?: boolean;
55
+ /**
56
+ * @description 是否开启全埋点 指的是:页面浏览、元素点击事件自动上报
57
+ * @default false
58
+ */
59
+ autoTrack?: boolean;
60
+ /**
61
+ * @description (是否使用客户端系统时间)注意:客户端系统时间可能会不准确,导致该字段不准确
62
+ * @default true
63
+ */
64
+ useClientTime?: boolean;
65
+ /**
66
+ * @description 接口发送超时时长,超过该时长未发送成功将强制取消,单位:毫秒
67
+ * @default 3000
68
+ */
69
+ sendTimeout?: number;
70
+ /**
71
+ * @description 是否采集单页面应用的路由变化
72
+ * @default false
73
+ */
74
+ isTrackSinglePage?: boolean;
75
+ /**
76
+ * @description 数据类型
77
+ * @default "application/json"
78
+ */
79
+ contentType?: ContentType;
80
+ /**
81
+ * @description 全局自定义业务参数
82
+ * @default {}
83
+ */
84
+ business?: JsonProps;
85
+ /**
86
+ * @description 请求头
87
+ * @default {}
88
+ */
89
+ header?: JsonProps;
90
+ /**
91
+ * @description 数据采样率,0-1之间,1表示100%采样
92
+ * @default 1
93
+ */
94
+ sampleRate?: number;
95
+ /**
96
+ * @description 是否启用批量发送
97
+ * @default false
98
+ */
99
+ batchSend?: boolean;
100
+ /**
101
+ * @description 批量发送间隔时间(ms)
102
+ * @default 5000
103
+ */
104
+ batchInterval?: number;
105
+ /**
106
+ * @description 批量发送最大数量
107
+ * @default 10
108
+ */
109
+ batchMaxSize?: number;
110
+ }
111
+ export interface InitParams extends PresetParams {
112
+ /**
113
+ * @description 应用唯一标识(由接口生成)
114
+ */
115
+ appKey: string;
116
+ /**
117
+ * @description 数据接收地址
118
+ */
119
+ serverUrl: string;
120
+ }
121
+ export declare type PlatformType = "h5" | "pc" | "ipad" | "other";
122
+ export interface SystemsInfoTypes {
123
+ language?: string;
124
+ /**
125
+ * 网络类型
126
+ */
127
+ network?: string;
128
+ ua?: string;
129
+ /**
130
+ * @description 客户端(Mac/Android/iPhone/iPad/iPod/WeChat)
131
+ */
132
+ client?: string;
133
+ /**
134
+ * @description 客户端平台类型(h5、pc、ipad)
135
+ */
136
+ platform?: PlatformType | string;
137
+ }
138
+ export interface TrackParams {
139
+ /**
140
+ * @description 控件/自定义事件的唯一标识
141
+ */
142
+ partkey: string | number;
143
+ /**
144
+ * @description 自定义代码埋点描述
145
+ * @default "自定义代码埋点上报"
146
+ */
147
+ desc?: string;
148
+ /**
149
+ * @description 自定义业务参数
150
+ * @default {}
151
+ */
152
+ business?: JsonProps;
153
+ /**
154
+ * @description 请求头
155
+ * @default {}
156
+ */
157
+ header?: JsonProps;
158
+ }
159
+ export interface TargetEleProps {
160
+ /**
161
+ * @description dom节点名称
162
+ */
163
+ nodeName?: string;
164
+ /**
165
+ * @description id类名
166
+ */
167
+ id?: string;
168
+ /**
169
+ * @description class类名
170
+ */
171
+ className?: string;
172
+ /**
173
+ * @description 元素触发位置:[x, y]
174
+ */
175
+ position?: [number, number];
176
+ }
177
+ /**
178
+ * @description 基础系统信息
179
+ */
180
+ export interface PrivateParamProps {
181
+ /**
182
+ * @description 当前URL
183
+ */
184
+ currentUrl?: string;
185
+ /**
186
+ * @description 目标URL
187
+ */
188
+ targetUrl?: string;
189
+ /**
190
+ * @description 手动埋点参数
191
+ */
192
+ business?: JsonProps;
193
+ /**
194
+ * @description 触发元素属性
195
+ */
196
+ targetEle?: TargetEleProps;
197
+ /**
198
+ * @description 页面可视区宽度
199
+ */
200
+ pageWidth?: number;
201
+ /**
202
+ * @description 页面可视区高度
203
+ */
204
+ pageHeight?: number;
205
+ /**
206
+ * @description 显示屏宽度
207
+ */
208
+ screenWidth?: number;
209
+ /**
210
+ * @description 显示屏高度
211
+ */
212
+ screenHeight?: number;
213
+ /**
214
+ * @description 手动触发的指针类型
215
+ */
216
+ pointerType?: PointerType;
217
+ /**
218
+ * @description 触发元素链路
219
+ */
220
+ elementSelector?: string;
221
+ /**
222
+ * @description 用户信息
223
+ */
224
+ userInfo?: JsonProps;
225
+ /**
226
+ * @description 路由参数
227
+ */
228
+ urlParams?: JsonProps;
229
+ /**
230
+ * @description 系统信息
231
+ */
232
+ systemsInfo?: SystemsInfoTypes;
233
+ /**
234
+ * @description SDk版本
235
+ */
236
+ sdkVersion?: string;
237
+ /**
238
+ * @description 页面停留时长(毫秒)
239
+ */
240
+ retainedDuration?: number;
241
+ /**
242
+ * @description 设备唯一标识
243
+ */
244
+ deviceId?: string;
245
+ }
246
+ export interface TrackingPostParams {
247
+ /**
248
+ * @description 事件类型
249
+ */
250
+ event: EventTypes;
251
+ /**
252
+ * @description 埋点事件描述
253
+ */
254
+ desc: string;
255
+ /**
256
+ * @description 当前埋点事件Key
257
+ */
258
+ itemKey?: string;
259
+ /**
260
+ * @description 发送请求时间戳(毫秒)
261
+ */
262
+ requestTime?: number;
263
+ /**
264
+ * @description 私有参数
265
+ */
266
+ privateParamMap?: PrivateParamProps;
267
+ }
268
+ /**
269
+ * @description 获取参数选项接口
270
+ */
271
+ export interface GetParamsOptions {
272
+ event: EventTypes;
273
+ desc: string;
274
+ privateParamMap?: PrivateParamProps;
275
+ itemKey?: string;
276
+ }
277
+ /**
278
+ * @description Ajax请求参数接口
279
+ */
280
+ export interface AjaxParams {
281
+ type?: HttpMethod;
282
+ url: string;
283
+ data?: string;
284
+ contentType?: ContentType;
285
+ header?: JsonProps;
286
+ success?: (data: JsonProps) => void;
287
+ error?: (err?: Error | JsonProps, status?: number) => void;
288
+ timeout?: number;
289
+ credentials?: boolean;
290
+ cors?: boolean;
291
+ }
292
+ /**
293
+ * @description SendBeacon参数接口
294
+ */
295
+ export interface SendBeaconParams {
296
+ url: string;
297
+ data: TrackingPostParams | JsonProps;
298
+ contentType: ContentType;
299
+ }
300
+ export declare type HistoryType = "load" | "beforeunload" | "pushState" | "replaceState" | "popstate" | "hashchange";
301
+ /**
302
+ * @description HTTP请求方法类型
303
+ */
304
+ export declare type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
305
+ /**
306
+ * @description 指针设备类型
307
+ */
308
+ export declare type PointerType = "mouse" | "touch" | "pen";
309
+ /**
310
+ * @description 网络连接类型
311
+ */
312
+ export declare type NetworkConnectionType = "slow-2g" | "2g" | "3g" | "4g" | "5g";
313
+ /**
314
+ * @description 网络连接信息接口
315
+ */
316
+ export interface NetworkConnection {
317
+ effectiveType?: NetworkConnectionType;
318
+ downlink?: number;
319
+ rtt?: number;
320
+ saveData?: boolean;
321
+ }
322
+ /**
323
+ * @description 浏览器信息接口
324
+ */
325
+ export interface BrowserInfo {
326
+ name: string;
327
+ version: number;
328
+ }
329
+ /**
330
+ * @description 响应结果接口
331
+ */
332
+ export interface TrackingResponse {
333
+ success: boolean;
334
+ message?: string;
335
+ data?: JsonProps;
336
+ code?: number;
337
+ }
338
+ /**
339
+ * @description 批量发送数据格式
340
+ */
341
+ export interface BatchTrackingData {
342
+ events: TrackingPostParams[];
343
+ timestamp?: number;
344
+ deviceId?: string;
345
+ }
346
+ /**
347
+ * @description 工具类型:将对象的所有属性变为必需
348
+ */
349
+ export declare type RequiredFields<T, K extends keyof T> = T & Required<Pick<T, K>>;
350
+ /**
351
+ * @description 工具类型:将对象的所有属性变为可选
352
+ */
353
+ export declare type PartialFields<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
354
+ /**
355
+ * @description 工具类型:深度只读
356
+ */
357
+ export declare type DeepReadonly<T> = {
358
+ readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
359
+ };
360
+ /**
361
+ * @description 工具类型:深度部分
362
+ */
363
+ export declare type DeepPartial<T> = {
364
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
365
+ };
366
+ /**
367
+ * @description 工具类型:提取函数参数类型
368
+ */
369
+ export declare type Parameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never;
370
+ /**
371
+ * @description 工具类型:提取函数返回类型
372
+ */
373
+ export declare type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
374
+ /**
375
+ * @description 设备指纹信息
376
+ */
377
+ export interface DeviceFingerprint {
378
+ /**
379
+ * @description 用户代理字符串
380
+ */
381
+ userAgent?: string;
382
+ /**
383
+ * @description 屏幕宽度
384
+ */
385
+ screenWidth?: number;
386
+ /**
387
+ * @description 屏幕高度
388
+ */
389
+ screenHeight?: number;
390
+ /**
391
+ * @description 颜色深度
392
+ */
393
+ colorDepth?: number;
394
+ /**
395
+ * @description 像素深度
396
+ */
397
+ pixelDepth?: number;
398
+ /**
399
+ * @description 时区
400
+ */
401
+ timezone?: string;
402
+ /**
403
+ * @description 时区偏移
404
+ */
405
+ timezoneOffset?: number;
406
+ /**
407
+ * @description 浏览器语言
408
+ */
409
+ language?: string;
410
+ /**
411
+ * @description 支持的语言列表
412
+ */
413
+ languages?: string[];
414
+ /**
415
+ * @description 平台信息
416
+ */
417
+ platform?: string;
418
+ /**
419
+ * @description WebGL指纹
420
+ */
421
+ webgl?: string;
422
+ /**
423
+ * @description Canvas指纹
424
+ */
425
+ canvas?: string;
426
+ /**
427
+ * @description 音频指纹
428
+ */
429
+ audio?: string;
430
+ /**
431
+ * @description 字体指纹
432
+ */
433
+ fonts?: string;
434
+ /**
435
+ * @description 插件指纹
436
+ */
437
+ plugins?: string;
438
+ /**
439
+ * @description 是否支持localStorage
440
+ */
441
+ localStorage?: boolean;
442
+ /**
443
+ * @description 是否支持sessionStorage
444
+ */
445
+ sessionStorage?: boolean;
446
+ /**
447
+ * @description 是否支持IndexedDB
448
+ */
449
+ indexedDB?: boolean;
450
+ /**
451
+ * @description CPU核心数
452
+ */
453
+ hardwareConcurrency?: number;
454
+ /**
455
+ * @description 设备内存(GB)
456
+ */
457
+ deviceMemory?: number;
458
+ /**
459
+ * @description 最大触摸点数
460
+ */
461
+ maxTouchPoints?: number;
462
+ /**
463
+ * @description 网络连接信息
464
+ */
465
+ connection?: string | NetworkConnection;
466
+ }