@fle-sdk/event-tracking-web 1.2.0-beta.1 → 1.2.1

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