tdem-web-sdk 1.0.1 → 1.0.7
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/README.md +164 -858
- package/lib/packages/core/src/constant/config.d.ts +11 -3
- package/lib/packages/core/src/core.d.ts +36 -70
- package/lib/packages/core/src/index.d.ts +1 -1
- package/lib/packages/core/src/interface/config.d.ts +45 -16
- package/lib/packages/core/src/interface/event.d.ts +55 -2
- package/lib/packages/core/src/interface/index.d.ts +4 -3
- package/lib/packages/core/src/interface/transport.d.ts +48 -0
- package/lib/packages/core/src/pipes/repeat-limit.d.ts +2 -2
- package/lib/packages/web-sdk/src/interface/index.d.ts +55 -30
- package/lib/packages/web-sdk/src/plugins/cgi-speed/utils.d.ts +10 -4
- package/lib/packages/web-sdk/src/plugins/session-replay/click-detector.d.ts +28 -2
- package/lib/packages/web-sdk/src/plugins/session-replay/constants.d.ts +13 -1
- package/lib/packages/web-sdk/src/plugins/session-replay/session-manager.d.ts +12 -22
- package/lib/packages/web-sdk/src/plugins/session-replay/types.d.ts +40 -5
- package/lib/packages/web-sdk/src/plugins/session-replay/uploader.d.ts +8 -4
- package/lib/packages/web-sdk/src/plugins/struggle-monitor.d.ts +10 -0
- package/lib/packages/web-sdk/src/tdem.d.ts +49 -4
- package/lib/packages/web-sdk/src/transport/browser-transport.d.ts +6 -0
- package/lib/packages/web-sdk/src/util/shared-session.d.ts +4 -4
- package/lib/tdem.f.min.js +5 -5
- package/lib/tdem.global.min.js +5 -5
- package/lib/tdem.ie.min.js +5 -5
- package/lib/tdem.min.js +5 -5
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InternalConfig } from '../interface';
|
|
2
2
|
export declare const REPORT_TIMEOUT = 5000;
|
|
3
3
|
export declare const MAX_FAIL_REQUEST_NUM = 60;
|
|
4
4
|
export declare const MAX_LOG_LENGTH: number;
|
|
@@ -10,5 +10,13 @@ export declare const MAX_CUSTOM_TIME = 2147483646;
|
|
|
10
10
|
export declare const MAX_ERROR_COUNT = 5;
|
|
11
11
|
export declare const FORBIDDEN_RESPONSE_DATA = "403 forbidden";
|
|
12
12
|
export declare const MAX_PROMISE_ERROR_MSG_LENGTH = 150;
|
|
13
|
-
export declare const getDefaultConfig: () =>
|
|
14
|
-
|
|
13
|
+
export declare const getDefaultConfig: () => InternalConfig;
|
|
14
|
+
/**
|
|
15
|
+
* 解析并规范化采集入口地址。
|
|
16
|
+
*
|
|
17
|
+
* 优先级:config.url > hostUrl > defaultHostUrl
|
|
18
|
+
*
|
|
19
|
+
* 同时仍为旧的 speedLogPipeline 等遗留管道保留内部 endpoint 拼装,
|
|
20
|
+
* 后续 T4 插件收敛完成后这些内部 endpoint 可以全部删除。
|
|
21
|
+
*/
|
|
22
|
+
export declare const setConfigUrl: (config: InternalConfig, hostUrl?: string) => InternalConfig;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { InterfaceEventEmitter } from './util';
|
|
2
|
-
import {
|
|
2
|
+
import { InternalConfig, Environment, SendOption, SendSuccess, SendFail, SpeedLog, BridgeLog, SendType, TDEMEvent, ReportFormSubmitResultParams, ReportStruggleParams, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, InternalSdkOptions, Transport, TransportRequest, TransportResult, TransportCallbacks, RetrySchedule } from './interface';
|
|
3
3
|
import Plugin from './plugin';
|
|
4
4
|
import { Pipe } from './pipes';
|
|
5
|
-
import { TimeEndLog } from './interface/log';
|
|
6
5
|
/**
|
|
7
6
|
* TDEM 核心逻辑,所有平台的 TDEM 类都继承于 Core
|
|
8
7
|
* 类似 linux 微内核的架构组织代码
|
|
9
8
|
* 所有 TDEM 的功能都是基于 Core 实现
|
|
10
9
|
* 1. 封装了 TDEM 的基本属性和方法
|
|
11
10
|
* 2. 封装了 TDEM 的插件模型,TDEM 中所有数据采集的逻辑均基于插件体系实现
|
|
12
|
-
* 3. 封装了 TDEM 的基础实例方法,包括
|
|
11
|
+
* 3. 封装了 TDEM 的基础实例方法,包括 track / measure / capture / pageView 等能力,平台无需自己重复实现
|
|
13
12
|
* 4. 封装了 TDEM 的生命周期,实现生命周期管理
|
|
14
13
|
*/
|
|
15
14
|
export default class Core {
|
|
@@ -17,6 +16,8 @@ export default class Core {
|
|
|
17
16
|
static instances: Core[];
|
|
18
17
|
static environment: typeof Environment;
|
|
19
18
|
static installedPlugins: Plugin[];
|
|
19
|
+
sdkName: string;
|
|
20
|
+
sdkVersion: string;
|
|
20
21
|
/**
|
|
21
22
|
* 使用插件
|
|
22
23
|
* @param plugin
|
|
@@ -29,13 +30,15 @@ export default class Core {
|
|
|
29
30
|
static unuse(plugin: Plugin): void;
|
|
30
31
|
isGetSample: boolean;
|
|
31
32
|
isHidden: boolean;
|
|
32
|
-
config:
|
|
33
|
+
config: InternalConfig;
|
|
33
34
|
isWhiteList: boolean;
|
|
34
35
|
lifeCycle: InterfaceEventEmitter;
|
|
35
36
|
bean: {
|
|
36
37
|
[key: string]: string | number | boolean;
|
|
37
38
|
};
|
|
38
39
|
sendNow: boolean;
|
|
40
|
+
protected internalTransport?: Transport;
|
|
41
|
+
protected internalRetrySchedule: RetrySchedule;
|
|
39
42
|
_customPageUrl: string | null;
|
|
40
43
|
tdemEventPipeline: import("./pipes").Pipeline<any, any>;
|
|
41
44
|
private timeMap;
|
|
@@ -44,12 +47,17 @@ export default class Core {
|
|
|
44
47
|
* 构造函数
|
|
45
48
|
* @param config
|
|
46
49
|
*/
|
|
47
|
-
constructor(
|
|
50
|
+
constructor(_config: InternalConfig, options?: InternalSdkOptions);
|
|
51
|
+
getInternalTransport(): Transport | undefined;
|
|
52
|
+
setInternalTransport(transport: Transport): void;
|
|
53
|
+
getInternalRetrySchedule(): RetrySchedule;
|
|
54
|
+
transportRequest(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult>;
|
|
55
|
+
transportHandoff(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult>;
|
|
48
56
|
/**
|
|
49
57
|
* 初始化方法,用于记录用户传入参数和初始化 SDK 所有插件
|
|
50
58
|
* @param config
|
|
51
59
|
*/
|
|
52
|
-
init(config:
|
|
60
|
+
init(config: InternalConfig): void;
|
|
53
61
|
/**
|
|
54
62
|
* 销毁 TDEM 实例,清空 TDEM 实例属性和方法,销毁插件
|
|
55
63
|
* @param force
|
|
@@ -60,91 +68,49 @@ export default class Core {
|
|
|
60
68
|
* @param config
|
|
61
69
|
* @returns
|
|
62
70
|
*/
|
|
63
|
-
setConfig(config: Partial<
|
|
71
|
+
setConfig(config: Partial<InternalConfig>): InternalConfig;
|
|
64
72
|
extendBean(key: string, value: string | number): void;
|
|
65
73
|
send(options: SendOption, success?: SendSuccess, fail?: SendFail): any;
|
|
66
74
|
sendSDKError(err: Error): void;
|
|
67
75
|
sendPipeline(pipes: Pipe[], type: SendType): import("./pipes").Pipeline<any, any>;
|
|
68
|
-
|
|
69
|
-
reportEvent(event: string | EventLog): void;
|
|
76
|
+
track(name: string, options?: TrackOptions): void;
|
|
70
77
|
/**
|
|
71
|
-
* 上报 TDEM Event
|
|
72
|
-
*
|
|
78
|
+
* 上报 TDEM Event 标准事件。
|
|
79
|
+
*
|
|
80
|
+
* SDK 会在这里统一补齐 page_url,并将 config.defaultTags 合并进事件 tags。
|
|
73
81
|
*/
|
|
74
82
|
reportTDEMEvent(event: TDEMEvent | TDEMEvent[]): void;
|
|
83
|
+
measure(name: string, duration: number, options?: MeasureOptions): void;
|
|
84
|
+
startMeasure(name: string): void;
|
|
85
|
+
endMeasure(name: string, options?: MeasureOptions): void;
|
|
86
|
+
captureMessage(message: string, options?: CaptureOptions): void;
|
|
87
|
+
captureException(error: Error | string, options?: CaptureOptions): void;
|
|
88
|
+
setTags(tags: Record<string, any>): void;
|
|
89
|
+
removeTags(keys: string | string[]): void;
|
|
90
|
+
clearTags(): void;
|
|
91
|
+
setUser(userId: string): void;
|
|
92
|
+
clearUser(): void;
|
|
75
93
|
reportStruggle(input: ReportStruggleParams): void;
|
|
76
94
|
reportFormSubmitResult(input: ReportFormSubmitResultParams): void;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
*
|
|
80
|
-
* 适用场景:
|
|
81
|
-
* - 非标准路由的 SPA(虚拟页面、弹窗页、Tab 切换等)
|
|
82
|
-
* - 框架路由无法被 spa 插件自动检测的情况
|
|
83
|
-
* - 需要自定义页面标识用于聚合分析
|
|
84
|
-
*
|
|
85
|
-
* 效果:
|
|
86
|
-
* 1. 立即上报一次 PageViewEvent(携带 navigation_type='push')
|
|
87
|
-
* 2. 后续所有事件的 page_url 使用此值
|
|
88
|
-
* 3. 直到下一次 setPage() / leavePage() / SPA 路由变化时被更新
|
|
89
|
-
*
|
|
90
|
-
* @param pageUrl - 自定义页面地址
|
|
91
|
-
* @param options - 可选配置
|
|
92
|
-
* @param options.pageTitle - 页面标题
|
|
93
|
-
* @param options.pageGroup - 页面组(归一化后的名称,用于聚合分析,预留字段)
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* // 基本用法
|
|
97
|
-
* tdem.setPage('/checkout');
|
|
98
|
-
*
|
|
99
|
-
* // 带标题和页面组
|
|
100
|
-
* tdem.setPage('/users/12345', {
|
|
101
|
-
* pageTitle: '用户详情',
|
|
102
|
-
* pageGroup: '/users/:id',
|
|
103
|
-
* });
|
|
104
|
-
*
|
|
105
|
-
* // 虚拟页面(弹窗)
|
|
106
|
-
* tdem.setPage('/modal/confirm', { pageTitle: '确认弹窗' });
|
|
107
|
-
* // ... 弹窗关闭后
|
|
108
|
-
* tdem.leavePage();
|
|
109
|
-
*/
|
|
110
|
-
setPage(pageUrl: string, options?: {
|
|
111
|
-
pageTitle?: string;
|
|
112
|
-
pageGroup?: string;
|
|
113
|
-
}): void;
|
|
114
|
-
/**
|
|
115
|
-
* 离开手动设置的页面,恢复为自动检测模式(location.href)
|
|
116
|
-
*
|
|
117
|
-
* 一般不需要主动调用——下一次 setPage() 或 SPA 路由变化会自动覆盖。
|
|
118
|
-
* 主要用于"虚拟页面"场景:弹窗关闭、Tab 切回等 URL 没有变化的情况。
|
|
119
|
-
*
|
|
120
|
-
* 不会上报 PV 事件,仅恢复后续事件的 page_url 为真实 URL。
|
|
121
|
-
*/
|
|
95
|
+
reportPageView(pageUrl?: string, options?: ReportPageViewOptions): void;
|
|
96
|
+
setPage(pageUrl: string, options?: SetPageOptions): void;
|
|
122
97
|
leavePage(): void;
|
|
123
|
-
/**
|
|
124
|
-
* 上报 TDEM 自定义信息 (新方法)
|
|
125
|
-
*/
|
|
126
|
-
infoTDEM(message: string, ext?: any): void;
|
|
127
|
-
/**
|
|
128
|
-
* 上报 TDEM 错误 (新方法)
|
|
129
|
-
*/
|
|
130
|
-
errorTDEM(error: Error | string, ext?: any): void;
|
|
131
98
|
private getCurrentEventPageUrl;
|
|
132
99
|
private getCurrentReplayId;
|
|
133
100
|
private getDefaultRuleVersion;
|
|
101
|
+
private getEventReplayId;
|
|
102
|
+
private mergeEventTags;
|
|
103
|
+
private sanitizeStringMap;
|
|
134
104
|
private sanitizeEventTags;
|
|
105
|
+
private sanitizeEventProperties;
|
|
135
106
|
private sanitizeEventPayload;
|
|
136
107
|
private getPayloadAllowlist;
|
|
137
108
|
private normalizeRelatedEventIds;
|
|
138
|
-
reportT(obj: ReportTimeLog): void;
|
|
139
|
-
reportTime(key: string | ReportTimeLog, duration?: number): void;
|
|
140
|
-
time(key: string): void;
|
|
141
|
-
timeEnd(key: string | TimeEndLog): void;
|
|
142
109
|
ready(_options: SendOption, _success?: SendSuccess, _fail?: SendFail): void;
|
|
143
110
|
request(_options: SendOption, _success?: SendSuccess, _fail?: SendFail): void;
|
|
144
111
|
speedLogPipeline(_log?: SpeedLog | SpeedLog[] | BridgeLog | BridgeLog[]): void;
|
|
145
112
|
getOriginFrom(): string;
|
|
146
113
|
get __version__(): string;
|
|
147
|
-
|
|
148
|
-
private submitCustomTime;
|
|
114
|
+
private submitMeasure;
|
|
149
115
|
private getTimeEventDuration;
|
|
150
116
|
}
|
|
@@ -3,7 +3,7 @@ import Core from './core';
|
|
|
3
3
|
import Plugin from './plugin';
|
|
4
4
|
export { Plugin };
|
|
5
5
|
export default Core;
|
|
6
|
-
export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, Config, CoreApiConfig, SendOption, SendSuccess, SendFail, SendType, PlatTypeNum, NetworkTypeNum, PagePerformanceStruct, EventType, EventCategory, BaseEvent, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, WebVitalsEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, ReportFormSubmitResultParams, generateEventId, parseErrorStack, } from './interface';
|
|
6
|
+
export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, Config, InternalConfig, CoreApiConfig, SendOption, SendSuccess, SendFail, SendType, Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, PlatTypeNum, NetworkTypeNum, PagePerformanceStruct, EventType, EventCategory, BaseEvent, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, WebVitalsEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, ReportFormSubmitResultParams, EventOptions, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './interface';
|
|
7
7
|
export { getDefaultConfig, setConfigUrl, globalAny, REPORT_TIMEOUT, MAX_FROM_LENGTH, ERROR_MSG_IGNORE, URL_SPEED_IGNORE, RESOURCE_TYPE_FETCH, RESOURCE_TYPE_STATIC, UNKNOWN, RESOURCE_TYPE, MAX_PROMISE_ERROR_MSG_LENGTH, } from './constant';
|
|
8
8
|
export * from './pipes';
|
|
9
9
|
export * from './util';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 配置Interface
|
|
2
|
+
* 配置 Interface
|
|
3
3
|
*/
|
|
4
4
|
export declare type CoreApiConfig = {
|
|
5
5
|
apiDetail?: boolean;
|
|
@@ -12,20 +12,42 @@ export declare type CoreApiConfig = {
|
|
|
12
12
|
resHeaders?: Array<string>;
|
|
13
13
|
reqHeaders?: Array<string>;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* TDEM SDK 对外公开的基础配置。
|
|
17
|
+
*
|
|
18
|
+
* 这里仅保留新的 public surface;
|
|
19
|
+
* 旧字段和内部实现字段统一收敛到 `InternalConfig`,
|
|
20
|
+
* 便于分阶段迁移实现代码而不继续污染公开类型。
|
|
21
|
+
*/
|
|
15
22
|
export interface Config {
|
|
16
23
|
id?: string;
|
|
17
|
-
|
|
24
|
+
userId?: string;
|
|
18
25
|
aid?: boolean | string;
|
|
19
26
|
onError?: boolean;
|
|
20
|
-
device?: boolean;
|
|
21
27
|
env?: string;
|
|
22
28
|
version?: number | string;
|
|
23
29
|
delay?: number;
|
|
24
|
-
repeat?: number |
|
|
30
|
+
repeat?: number | Record<string, number>;
|
|
31
|
+
url?: string;
|
|
32
|
+
pageUrl?: string;
|
|
33
|
+
reportImmediately?: boolean;
|
|
34
|
+
beforeReport?: Function;
|
|
35
|
+
beforeRequest?: Function;
|
|
36
|
+
afterRequest?: Function;
|
|
37
|
+
defaultTags?: Record<string, string>;
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* SDK 内部过渡配置。
|
|
42
|
+
*
|
|
43
|
+
* 为了分阶段实施参数/API 收敛,当前实现仍需读取部分旧字段和内部字段,
|
|
44
|
+
* 这些字段不应继续视为 public API。
|
|
45
|
+
*/
|
|
46
|
+
export interface InternalConfig extends Config {
|
|
47
|
+
uin?: number | string;
|
|
25
48
|
random?: number;
|
|
26
49
|
speedSample?: boolean;
|
|
27
50
|
hostUrl?: string;
|
|
28
|
-
url?: string;
|
|
29
51
|
maxLength?: number;
|
|
30
52
|
customTimeUrl?: string;
|
|
31
53
|
whiteListUrl?: string;
|
|
@@ -37,18 +59,25 @@ export interface Config {
|
|
|
37
59
|
eventUrl?: string;
|
|
38
60
|
webVitalsUrl?: string;
|
|
39
61
|
setDataReportUrl?: string;
|
|
40
|
-
pageUrl?: string;
|
|
41
62
|
getNetworkType?: Function;
|
|
63
|
+
getNetworkStatus?: Function;
|
|
42
64
|
websocketHack?: boolean;
|
|
43
|
-
beforeReport?: Function;
|
|
44
65
|
logCreated?: Function;
|
|
45
66
|
onReport?: Function;
|
|
46
67
|
onWhitelist?: Function;
|
|
47
|
-
api?: CoreApiConfig
|
|
68
|
+
api?: CoreApiConfig | boolean | Record<string, any>;
|
|
48
69
|
beforeReportSpeed?: Function;
|
|
49
70
|
reportAssetSpeed?: boolean | object;
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
reportApiSpeed?: boolean | object;
|
|
72
|
+
reportBridgeSpeed?: boolean;
|
|
73
|
+
h5Bridge?: Record<string, any>;
|
|
74
|
+
h5BridgeFunc?: string[];
|
|
75
|
+
apiLog?: boolean;
|
|
76
|
+
slowApiLog?: boolean;
|
|
77
|
+
pageLoadLog?: boolean;
|
|
78
|
+
slowPageLoadLog?: boolean;
|
|
79
|
+
assetLog?: boolean;
|
|
80
|
+
slowAssetLog?: boolean;
|
|
52
81
|
urlHandler?: Function;
|
|
53
82
|
ext1?: string;
|
|
54
83
|
ext2?: string;
|
|
@@ -62,16 +91,16 @@ export interface Config {
|
|
|
62
91
|
ext10?: string;
|
|
63
92
|
destroy?: Function;
|
|
64
93
|
pagePerformance?: boolean | PagePerformanceStruct;
|
|
65
|
-
/** TDEM Collector API 地址(用于 /api/v1/config 和 /api/v1/collect/events) */
|
|
66
94
|
apiUrl?: string;
|
|
67
|
-
/**
|
|
68
|
-
* TDEM 远程采样率控制(内部配置,默认开启)
|
|
69
|
-
* SDK 启动时自动从 Collector 获取采样率配置
|
|
70
|
-
*/
|
|
71
95
|
tdemConfig?: boolean;
|
|
96
|
+
device?: boolean;
|
|
97
|
+
ignoreElements?: {
|
|
98
|
+
ignoreIds?: string[];
|
|
99
|
+
ignoreClasses?: string[];
|
|
100
|
+
};
|
|
72
101
|
[key: string]: any;
|
|
73
102
|
}
|
|
74
103
|
export declare type PagePerformanceStruct = {
|
|
75
|
-
firstScreenInfo?:
|
|
104
|
+
firstScreenInfo?: boolean;
|
|
76
105
|
urlHandler?: () => string;
|
|
77
106
|
};
|
|
@@ -17,6 +17,10 @@ export declare enum EventType {
|
|
|
17
17
|
WEB_VITALS = "web_vitals",
|
|
18
18
|
CLICK = "click",
|
|
19
19
|
PAGE_VIEW = "page_view",
|
|
20
|
+
TAB_HIDDEN = "tab_hidden",
|
|
21
|
+
TAB_VISIBLE = "tab_visible",
|
|
22
|
+
WINDOW_BLUR = "window_blur",
|
|
23
|
+
WINDOW_FOCUS = "window_focus",
|
|
20
24
|
FORM_FOCUS = "form_focus",
|
|
21
25
|
FORM_BLUR = "form_blur",
|
|
22
26
|
FORM_CHANGE = "form_change",
|
|
@@ -63,6 +67,11 @@ export interface EventContext {
|
|
|
63
67
|
session_id: string;
|
|
64
68
|
user_id?: string;
|
|
65
69
|
platform: string;
|
|
70
|
+
runtime?: string;
|
|
71
|
+
process_type?: string;
|
|
72
|
+
window_id?: string;
|
|
73
|
+
web_contents_id?: string;
|
|
74
|
+
app_version?: string;
|
|
66
75
|
user_agent?: string;
|
|
67
76
|
screen_resolution?: string;
|
|
68
77
|
language?: string;
|
|
@@ -122,6 +131,7 @@ export interface JSErrorEvent extends BaseEvent {
|
|
|
122
131
|
exception_frames: ExceptionFrame[];
|
|
123
132
|
replay_id?: string;
|
|
124
133
|
tags?: Record<string, string>;
|
|
134
|
+
event_properties?: Record<string, string>;
|
|
125
135
|
};
|
|
126
136
|
}
|
|
127
137
|
/**
|
|
@@ -135,6 +145,7 @@ export interface PromiseErrorEvent extends BaseEvent {
|
|
|
135
145
|
exception_frames: ExceptionFrame[];
|
|
136
146
|
replay_id?: string;
|
|
137
147
|
tags?: Record<string, string>;
|
|
148
|
+
event_properties?: Record<string, string>;
|
|
138
149
|
};
|
|
139
150
|
}
|
|
140
151
|
/**
|
|
@@ -325,6 +336,17 @@ export interface PageViewEvent extends BaseEvent {
|
|
|
325
336
|
};
|
|
326
337
|
};
|
|
327
338
|
}
|
|
339
|
+
export interface LifecycleEvent extends BaseEvent {
|
|
340
|
+
event_type: EventType.TAB_HIDDEN | EventType.TAB_VISIBLE | EventType.WINDOW_BLUR | EventType.WINDOW_FOCUS;
|
|
341
|
+
event_category: EventCategory.BEHAVIOR;
|
|
342
|
+
data: BehaviorContextData & {
|
|
343
|
+
page_title: string;
|
|
344
|
+
event_properties?: Record<string, string> & {
|
|
345
|
+
visibility_state?: string;
|
|
346
|
+
lifecycle_type?: string;
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
}
|
|
328
350
|
export interface FormFocusEvent extends BaseEvent {
|
|
329
351
|
event_type: EventType.FORM_FOCUS;
|
|
330
352
|
event_category: EventCategory.BEHAVIOR;
|
|
@@ -400,6 +422,8 @@ export interface CustomTimeEvent extends BaseEvent {
|
|
|
400
422
|
};
|
|
401
423
|
replay_id?: string;
|
|
402
424
|
tags?: Record<string, string>;
|
|
425
|
+
payload?: Record<string, any>;
|
|
426
|
+
event_properties?: Record<string, string>;
|
|
403
427
|
};
|
|
404
428
|
}
|
|
405
429
|
/**
|
|
@@ -409,7 +433,7 @@ export interface LogEvent extends BaseEvent {
|
|
|
409
433
|
event_type: EventType.LOG;
|
|
410
434
|
event_category: EventCategory.LOG;
|
|
411
435
|
data: {
|
|
412
|
-
log_level: 'info' | 'info_all' | 'report' | 'error';
|
|
436
|
+
log_level: 'info' | 'warn' | 'info_all' | 'report' | 'error';
|
|
413
437
|
message?: string;
|
|
414
438
|
replay_id?: string;
|
|
415
439
|
tags?: Record<string, string>;
|
|
@@ -420,7 +444,7 @@ export interface LogEvent extends BaseEvent {
|
|
|
420
444
|
/**
|
|
421
445
|
* 所有事件的联合类型
|
|
422
446
|
*/
|
|
423
|
-
export declare type TDEMEvent = JSErrorEvent | PromiseErrorEvent | ResourceErrorEvent | APIErrorEvent | PageLoadEvent | ResourceLoadEvent | APICallEvent | WebVitalsEvent | ClickEvent | PageViewEvent | FormFocusEvent | FormBlurEvent | FormChangeEvent | FormSubmitEvent | FormSubmitResultEvent | StruggleEvent | CustomEvent | CustomTimeEvent | LogEvent;
|
|
447
|
+
export declare type TDEMEvent = JSErrorEvent | PromiseErrorEvent | ResourceErrorEvent | APIErrorEvent | PageLoadEvent | ResourceLoadEvent | APICallEvent | WebVitalsEvent | ClickEvent | PageViewEvent | LifecycleEvent | FormFocusEvent | FormBlurEvent | FormChangeEvent | FormSubmitEvent | FormSubmitResultEvent | StruggleEvent | CustomEvent | CustomTimeEvent | LogEvent;
|
|
424
448
|
export interface ReportStruggleParams {
|
|
425
449
|
type: StruggleEventName;
|
|
426
450
|
ownerType: StruggleOwnerType;
|
|
@@ -455,6 +479,35 @@ export interface ReportFormSubmitResultParams {
|
|
|
455
479
|
payloadAllowlist?: string[];
|
|
456
480
|
tags?: Record<string, string>;
|
|
457
481
|
}
|
|
482
|
+
export interface EventOptions {
|
|
483
|
+
tags?: Record<string, string>;
|
|
484
|
+
properties?: Record<string, string>;
|
|
485
|
+
pageUrl?: string;
|
|
486
|
+
replayId?: string;
|
|
487
|
+
}
|
|
488
|
+
export interface TrackOptions extends EventOptions {
|
|
489
|
+
payload?: Record<string, any>;
|
|
490
|
+
}
|
|
491
|
+
export interface MeasureOptions extends EventOptions {
|
|
492
|
+
payload?: Record<string, any>;
|
|
493
|
+
}
|
|
494
|
+
export interface CaptureOptions extends EventOptions {
|
|
495
|
+
level?: 'info' | 'warn' | 'error';
|
|
496
|
+
}
|
|
497
|
+
export interface SetPageOptions {
|
|
498
|
+
pageTitle?: string;
|
|
499
|
+
pageGroup?: string;
|
|
500
|
+
}
|
|
501
|
+
export interface ReportPageViewOptions extends EventOptions {
|
|
502
|
+
pageTitle?: string;
|
|
503
|
+
referrer?: string;
|
|
504
|
+
navigationType?: NavigationType;
|
|
505
|
+
fromPage?: string;
|
|
506
|
+
toPage?: string;
|
|
507
|
+
isFirstVisit?: boolean;
|
|
508
|
+
isFirstLoad?: boolean;
|
|
509
|
+
deviceType?: string;
|
|
510
|
+
}
|
|
458
511
|
/**
|
|
459
512
|
* 生成事件ID
|
|
460
513
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { Config, CoreApiConfig, PagePerformanceStruct } from './config';
|
|
2
|
-
export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog,
|
|
1
|
+
export { Config, InternalConfig, CoreApiConfig, PagePerformanceStruct } from './config';
|
|
2
|
+
export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, PlatTypeNum, NetworkTypeNum, } from './log';
|
|
3
3
|
export { SendOption, SendSuccess, SendFail, SendType, } from './send';
|
|
4
|
+
export { Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, } from './transport';
|
|
4
5
|
export { Environment, } from './env';
|
|
5
|
-
export { EventType, EventCategory, BaseEvent, EventContext, SDKInfo, AppInfo, CollectEventsRequest, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, WebVitalsEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, ReportFormSubmitResultParams, generateEventId, parseErrorStack, } from './event';
|
|
6
|
+
export { EventType, EventCategory, BaseEvent, EventContext, SDKInfo, AppInfo, CollectEventsRequest, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, WebVitalsEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, ReportFormSubmitResultParams, EventOptions, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './event';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { SendFail, SendOption, SendSuccess } from './send';
|
|
2
|
+
export declare type TransportMethod = 'GET' | 'POST' | 'get' | 'post';
|
|
3
|
+
export declare type TransportBody = string | ArrayBuffer | ArrayBufferView | Record<string, any> | null | undefined;
|
|
4
|
+
export interface TransportRequest {
|
|
5
|
+
readonly id?: string;
|
|
6
|
+
readonly kind?: 'config' | 'events' | 'replay' | 'custom' | string;
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly method?: TransportMethod;
|
|
9
|
+
readonly headers?: Record<string, string>;
|
|
10
|
+
readonly contentType?: string;
|
|
11
|
+
readonly body?: TransportBody;
|
|
12
|
+
readonly data?: any;
|
|
13
|
+
readonly sendBeacon?: boolean;
|
|
14
|
+
readonly handoff?: boolean;
|
|
15
|
+
readonly timeout?: number;
|
|
16
|
+
readonly retry?: boolean;
|
|
17
|
+
readonly source?: SendOption;
|
|
18
|
+
}
|
|
19
|
+
export interface TransportResult {
|
|
20
|
+
readonly ok: boolean;
|
|
21
|
+
readonly status?: number;
|
|
22
|
+
readonly statusText?: string;
|
|
23
|
+
readonly headers?: Record<string, string>;
|
|
24
|
+
readonly body?: any;
|
|
25
|
+
readonly error?: any;
|
|
26
|
+
readonly request?: TransportRequest;
|
|
27
|
+
readonly handoffAccepted?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface TransportCallbacks {
|
|
30
|
+
readonly success?: SendSuccess;
|
|
31
|
+
readonly fail?: SendFail;
|
|
32
|
+
readonly final?: (result: TransportResult) => void;
|
|
33
|
+
}
|
|
34
|
+
export interface Transport {
|
|
35
|
+
request(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult> | TransportResult | void;
|
|
36
|
+
handoff?(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult> | TransportResult | void;
|
|
37
|
+
dispose?(): void;
|
|
38
|
+
}
|
|
39
|
+
export declare type RetryDelayResolver = (attempt: number, error?: any, request?: TransportRequest) => number;
|
|
40
|
+
export interface RetrySchedule {
|
|
41
|
+
readonly maxAttempts: number;
|
|
42
|
+
readonly delays: ReadonlyArray<number> | RetryDelayResolver;
|
|
43
|
+
}
|
|
44
|
+
export declare const DEFAULT_TRANSPORT_RETRY_SCHEDULE: RetrySchedule;
|
|
45
|
+
export interface InternalSdkOptions {
|
|
46
|
+
readonly transport?: Transport;
|
|
47
|
+
readonly retrySchedule?: RetrySchedule;
|
|
48
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Pipe } from './index';
|
|
2
|
-
import {
|
|
3
|
-
export declare const createSpeedRepeatLimitPipe: (config:
|
|
2
|
+
import { InternalConfig } from '../interface';
|
|
3
|
+
export declare const createSpeedRepeatLimitPipe: (config: InternalConfig) => Pipe;
|
|
@@ -1,60 +1,85 @@
|
|
|
1
|
-
import { Config, CoreApiConfig, TraceType, TraceRequestHeader, PagePerformanceStruct } from "../../../core/src";
|
|
1
|
+
import { Config, InternalConfig, CoreApiConfig, TraceType, TraceRequestHeader, PagePerformanceStruct } from "../../../core/src";
|
|
2
2
|
import { SessionReplayConfig } from '../plugins/session-replay/types';
|
|
3
3
|
import { StruggleMonitorConfig } from '../plugins/struggle-monitor';
|
|
4
|
-
declare type
|
|
4
|
+
export declare type ApiMonitorConfig = CoreApiConfig & {
|
|
5
5
|
injectTraceHeader?: TraceType;
|
|
6
6
|
injectTraceUrls?: Array<string | RegExp>;
|
|
7
7
|
injectTraceIgnoreUrls?: Array<string | RegExp>;
|
|
8
8
|
traceFlag?: boolean | number;
|
|
9
9
|
ignoreHackReg?: RegExp;
|
|
10
10
|
usePerformanceTiming?: boolean;
|
|
11
|
-
|
|
11
|
+
slowThreshold?: number;
|
|
12
12
|
assetSlowThreshold?: number;
|
|
13
13
|
isSlowApi?: (api: any) => boolean;
|
|
14
14
|
isSlowAsset?: (asset: any) => boolean;
|
|
15
|
-
}
|
|
16
|
-
declare type
|
|
17
|
-
|
|
15
|
+
};
|
|
16
|
+
export declare type AssetMonitorConfig = {
|
|
17
|
+
slowThreshold?: number;
|
|
18
|
+
isSlowAsset?: (asset: any) => boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare type PagePerformanceConfig = PagePerformanceStruct & {
|
|
21
|
+
slowThreshold?: number;
|
|
18
22
|
isSlowPage?: (performance: any, vitals: any) => boolean;
|
|
19
|
-
}
|
|
23
|
+
};
|
|
20
24
|
export declare type WebReportRetryConfig = {
|
|
21
25
|
maxRetryCount?: number;
|
|
22
26
|
retryInterval?: number | ((retriedCount: number) => number);
|
|
23
27
|
whenRetryEndStillFail?: 'discard' | 'nextTimeReport';
|
|
24
28
|
};
|
|
25
|
-
export declare type
|
|
29
|
+
export declare type ClickMonitorConfig = {
|
|
26
30
|
ignoreIds?: string[];
|
|
27
31
|
ignoreClasses?: string[];
|
|
28
32
|
};
|
|
33
|
+
export declare type ConsoleMonitorConfig = {
|
|
34
|
+
level?: 'log' | 'info' | 'warn' | 'error' | 'all';
|
|
35
|
+
};
|
|
36
|
+
export declare type BridgeMonitorConfig = {
|
|
37
|
+
target?: Record<string, any>;
|
|
38
|
+
methods?: string[];
|
|
39
|
+
};
|
|
40
|
+
export declare type WebSocketMonitorConfig = {
|
|
41
|
+
enabled?: boolean;
|
|
42
|
+
};
|
|
43
|
+
export declare type WebVitalsConfig = {
|
|
44
|
+
manualReport?: boolean;
|
|
45
|
+
};
|
|
46
|
+
export declare type IgnoreElements = ClickMonitorConfig;
|
|
47
|
+
/**
|
|
48
|
+
* TDEM Web SDK 对外公开配置。
|
|
49
|
+
*
|
|
50
|
+
* 这里只保留新的 public surface;
|
|
51
|
+
* 遗留参数统一放入 `InternalWebConfig`,供实施期内部代码使用。
|
|
52
|
+
*/
|
|
29
53
|
export interface WebConfig extends Config {
|
|
30
|
-
asyncPlugin?: boolean;
|
|
31
|
-
reportApiSpeed?: boolean | {
|
|
32
|
-
urlHandler: (url: string, payload: object) => string;
|
|
33
|
-
};
|
|
34
|
-
reportImmediately?: boolean;
|
|
35
|
-
getNetworkType?: Function;
|
|
36
|
-
getNetworkStatus?: Function;
|
|
37
|
-
reportBridgeSpeed?: boolean;
|
|
38
|
-
h5Bridge?: Object;
|
|
39
|
-
h5BridgeFunc?: string[];
|
|
40
54
|
/** 当前页面是否是单页应用 */
|
|
41
55
|
spa?: boolean;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
slowPageLoadLog?: boolean;
|
|
46
|
-
assetLog?: boolean;
|
|
47
|
-
slowAssetLog?: boolean;
|
|
48
|
-
api?: WebApiConfig;
|
|
49
|
-
pagePerformance?: boolean | WebPageConfig;
|
|
56
|
+
api?: boolean | ApiMonitorConfig;
|
|
57
|
+
assets?: boolean | AssetMonitorConfig;
|
|
58
|
+
pagePerformance?: boolean | PagePerformanceConfig;
|
|
50
59
|
reportRetry?: boolean | WebReportRetryConfig;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
click?: boolean | ClickMonitorConfig;
|
|
61
|
+
console?: boolean | ConsoleMonitorConfig;
|
|
62
|
+
bridge?: boolean | BridgeMonitorConfig;
|
|
63
|
+
websocket?: boolean | WebSocketMonitorConfig;
|
|
64
|
+
webVitals?: boolean | WebVitalsConfig;
|
|
55
65
|
sessionReplay?: boolean | SessionReplayConfig;
|
|
56
66
|
struggleMonitor?: boolean | StruggleMonitorConfig;
|
|
57
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Web SDK 内部过渡配置。
|
|
70
|
+
*
|
|
71
|
+
* 收敛方向:对外 public surface 统一到 `WebConfig`,
|
|
72
|
+
* 历史遗留字段(reportApiSpeed / h5Bridge / apiLog / ignoreElements 等)
|
|
73
|
+
* 仍存在于 `InternalConfig`(由 tdem-core 定义,mp-sdk 共享),
|
|
74
|
+
* 这里不再重复声明——Web SDK 内部代码应只读新字段,
|
|
75
|
+
* 不要再新增对旧字段的直接引用。
|
|
76
|
+
*/
|
|
77
|
+
export interface InternalWebConfig extends WebConfig, InternalConfig {
|
|
78
|
+
asyncPlugin?: boolean;
|
|
79
|
+
getNetworkType?: Function;
|
|
80
|
+
getNetworkStatus?: Function;
|
|
81
|
+
webVitals?: boolean | WebVitalsConfig;
|
|
82
|
+
}
|
|
58
83
|
export interface MarkDoms {
|
|
59
84
|
[timing: number]: Element[];
|
|
60
85
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SpeedLog } from "../../../../core/src";
|
|
2
|
-
import {
|
|
2
|
+
import { InternalWebConfig } from '../../interface';
|
|
3
3
|
export declare const API_LOG_LEVEL: {
|
|
4
4
|
readonly API_RESPONSE: "api_response";
|
|
5
5
|
readonly AJAX_ERROR: "ajax_error";
|
|
@@ -15,16 +15,22 @@ export declare const createLine: (value: string, label: string) => string;
|
|
|
15
15
|
* @param url
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
|
-
export declare const getRequestType: (config:
|
|
18
|
+
export declare const getRequestType: (config: InternalWebConfig & {
|
|
19
|
+
api?: any;
|
|
20
|
+
}, contentType: string | undefined, url: string) => any;
|
|
19
21
|
export declare const getLogLevel: (isAjaxError: boolean, isErr: boolean) => ApiLogLevel;
|
|
20
|
-
export declare const isSlowRequest: (duration: number | undefined, config?:
|
|
22
|
+
export declare const isSlowRequest: (duration: number | undefined, config?: (InternalWebConfig & {
|
|
23
|
+
api?: any;
|
|
24
|
+
}) | undefined, apiData?: any) => any;
|
|
21
25
|
/**
|
|
22
26
|
* 从 performance 中获取接口真实耗时
|
|
23
27
|
* @param config
|
|
24
28
|
* @param defaultValue
|
|
25
29
|
* @returns
|
|
26
30
|
*/
|
|
27
|
-
export declare const getPerformanceEntryByUrl: (config:
|
|
31
|
+
export declare const getPerformanceEntryByUrl: (config: InternalWebConfig & {
|
|
32
|
+
api?: any;
|
|
33
|
+
}, defaultValue: {
|
|
28
34
|
url: string;
|
|
29
35
|
duration: number;
|
|
30
36
|
type: 'static' | 'fetch';
|