tdem-web-sdk 1.0.1 → 1.0.6

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,4 +1,4 @@
1
- import { Config } from '../interface';
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: () => Config;
14
- export declare const setConfigUrl: (config: Config, hostUrl?: string) => Config;
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 { Config, Environment, SendOption, SendSuccess, SendFail, SpeedLog, BridgeLog, ReportTimeLog, SendType, EventLog, TDEMEvent, ReportFormSubmitResultParams, ReportStruggleParams } from './interface';
2
+ import { InternalConfig, Environment, SendOption, SendSuccess, SendFail, SpeedLog, BridgeLog, SendType, TDEMEvent, ReportFormSubmitResultParams, ReportStruggleParams, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions } 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 的基础实例方法,包括 info report reportEvent 等,平台无需自己重复实现
11
+ * 3. 封装了 TDEM 的基础实例方法,包括 track / measure / capture / pageView 等能力,平台无需自己重复实现
13
12
  * 4. 封装了 TDEM 的生命周期,实现生命周期管理
14
13
  */
15
14
  export default class Core {
@@ -29,7 +28,7 @@ export default class Core {
29
28
  static unuse(plugin: Plugin): void;
30
29
  isGetSample: boolean;
31
30
  isHidden: boolean;
32
- config: Config;
31
+ config: InternalConfig;
33
32
  isWhiteList: boolean;
34
33
  lifeCycle: InterfaceEventEmitter;
35
34
  bean: {
@@ -44,12 +43,12 @@ export default class Core {
44
43
  * 构造函数
45
44
  * @param config
46
45
  */
47
- constructor(config: Config);
46
+ constructor(_config: InternalConfig);
48
47
  /**
49
48
  * 初始化方法,用于记录用户传入参数和初始化 SDK 所有插件
50
49
  * @param config
51
50
  */
52
- init(config: Config): void;
51
+ init(config: InternalConfig): void;
53
52
  /**
54
53
  * 销毁 TDEM 实例,清空 TDEM 实例属性和方法,销毁插件
55
54
  * @param force
@@ -60,91 +59,49 @@ export default class Core {
60
59
  * @param config
61
60
  * @returns
62
61
  */
63
- setConfig(config: Partial<Config>): Config;
62
+ setConfig(config: Partial<InternalConfig>): InternalConfig;
64
63
  extendBean(key: string, value: string | number): void;
65
64
  send(options: SendOption, success?: SendSuccess, fail?: SendFail): any;
66
65
  sendSDKError(err: Error): void;
67
66
  sendPipeline(pipes: Pipe[], type: SendType): import("./pipes").Pipeline<any, any>;
68
- validateRange(value: number): number;
69
- reportEvent(event: string | EventLog): void;
67
+ track(name: string, options?: TrackOptions): void;
70
68
  /**
71
- * 上报 TDEM Event (新方法)
72
- * @param event - 单个Event或Event数组
69
+ * 上报 TDEM Event 标准事件。
70
+ *
71
+ * SDK 会在这里统一补齐 page_url,并将 config.defaultTags 合并进事件 tags。
73
72
  */
74
73
  reportTDEMEvent(event: TDEMEvent | TDEMEvent[]): void;
74
+ measure(name: string, duration: number, options?: MeasureOptions): void;
75
+ startMeasure(name: string): void;
76
+ endMeasure(name: string, options?: MeasureOptions): void;
77
+ captureMessage(message: string, options?: CaptureOptions): void;
78
+ captureException(error: Error | string, options?: CaptureOptions): void;
79
+ setTags(tags: Record<string, any>): void;
80
+ removeTags(keys: string | string[]): void;
81
+ clearTags(): void;
82
+ setUser(userId: string): void;
83
+ clearUser(): void;
75
84
  reportStruggle(input: ReportStruggleParams): void;
76
85
  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
- */
86
+ reportPageView(pageUrl?: string, options?: ReportPageViewOptions): void;
87
+ setPage(pageUrl: string, options?: SetPageOptions): void;
122
88
  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
89
  private getCurrentEventPageUrl;
132
90
  private getCurrentReplayId;
133
91
  private getDefaultRuleVersion;
92
+ private getEventReplayId;
93
+ private mergeEventTags;
94
+ private sanitizeStringMap;
134
95
  private sanitizeEventTags;
96
+ private sanitizeEventProperties;
135
97
  private sanitizeEventPayload;
136
98
  private getPayloadAllowlist;
137
99
  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
100
  ready(_options: SendOption, _success?: SendSuccess, _fail?: SendFail): void;
143
101
  request(_options: SendOption, _success?: SendSuccess, _fail?: SendFail): void;
144
102
  speedLogPipeline(_log?: SpeedLog | SpeedLog[] | BridgeLog | BridgeLog[]): void;
145
103
  getOriginFrom(): string;
146
104
  get __version__(): string;
147
- reportPv(id: number): void;
148
- private submitCustomTime;
105
+ private submitMeasure;
149
106
  private getTimeEventDuration;
150
107
  }
@@ -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, 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
- uin?: number | string;
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 | object;
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
- beforeRequest?: Function;
51
- afterRequest?: Function;
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?: false;
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",
@@ -122,6 +126,7 @@ export interface JSErrorEvent extends BaseEvent {
122
126
  exception_frames: ExceptionFrame[];
123
127
  replay_id?: string;
124
128
  tags?: Record<string, string>;
129
+ event_properties?: Record<string, string>;
125
130
  };
126
131
  }
127
132
  /**
@@ -135,6 +140,7 @@ export interface PromiseErrorEvent extends BaseEvent {
135
140
  exception_frames: ExceptionFrame[];
136
141
  replay_id?: string;
137
142
  tags?: Record<string, string>;
143
+ event_properties?: Record<string, string>;
138
144
  };
139
145
  }
140
146
  /**
@@ -325,6 +331,17 @@ export interface PageViewEvent extends BaseEvent {
325
331
  };
326
332
  };
327
333
  }
334
+ export interface LifecycleEvent extends BaseEvent {
335
+ event_type: EventType.TAB_HIDDEN | EventType.TAB_VISIBLE | EventType.WINDOW_BLUR | EventType.WINDOW_FOCUS;
336
+ event_category: EventCategory.BEHAVIOR;
337
+ data: BehaviorContextData & {
338
+ page_title: string;
339
+ event_properties?: Record<string, string> & {
340
+ visibility_state?: string;
341
+ lifecycle_type?: string;
342
+ };
343
+ };
344
+ }
328
345
  export interface FormFocusEvent extends BaseEvent {
329
346
  event_type: EventType.FORM_FOCUS;
330
347
  event_category: EventCategory.BEHAVIOR;
@@ -400,6 +417,8 @@ export interface CustomTimeEvent extends BaseEvent {
400
417
  };
401
418
  replay_id?: string;
402
419
  tags?: Record<string, string>;
420
+ payload?: Record<string, any>;
421
+ event_properties?: Record<string, string>;
403
422
  };
404
423
  }
405
424
  /**
@@ -409,7 +428,7 @@ export interface LogEvent extends BaseEvent {
409
428
  event_type: EventType.LOG;
410
429
  event_category: EventCategory.LOG;
411
430
  data: {
412
- log_level: 'info' | 'info_all' | 'report' | 'error';
431
+ log_level: 'info' | 'warn' | 'info_all' | 'report' | 'error';
413
432
  message?: string;
414
433
  replay_id?: string;
415
434
  tags?: Record<string, string>;
@@ -420,7 +439,7 @@ export interface LogEvent extends BaseEvent {
420
439
  /**
421
440
  * 所有事件的联合类型
422
441
  */
423
- export declare type TDEMEvent = JSErrorEvent | PromiseErrorEvent | ResourceErrorEvent | APIErrorEvent | PageLoadEvent | ResourceLoadEvent | APICallEvent | WebVitalsEvent | ClickEvent | PageViewEvent | FormFocusEvent | FormBlurEvent | FormChangeEvent | FormSubmitEvent | FormSubmitResultEvent | StruggleEvent | CustomEvent | CustomTimeEvent | LogEvent;
442
+ 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
443
  export interface ReportStruggleParams {
425
444
  type: StruggleEventName;
426
445
  ownerType: StruggleOwnerType;
@@ -455,6 +474,35 @@ export interface ReportFormSubmitResultParams {
455
474
  payloadAllowlist?: string[];
456
475
  tags?: Record<string, string>;
457
476
  }
477
+ export interface EventOptions {
478
+ tags?: Record<string, string>;
479
+ properties?: Record<string, string>;
480
+ pageUrl?: string;
481
+ replayId?: string;
482
+ }
483
+ export interface TrackOptions extends EventOptions {
484
+ payload?: Record<string, any>;
485
+ }
486
+ export interface MeasureOptions extends EventOptions {
487
+ payload?: Record<string, any>;
488
+ }
489
+ export interface CaptureOptions extends EventOptions {
490
+ level?: 'info' | 'warn' | 'error';
491
+ }
492
+ export interface SetPageOptions {
493
+ pageTitle?: string;
494
+ pageGroup?: string;
495
+ }
496
+ export interface ReportPageViewOptions extends EventOptions {
497
+ pageTitle?: string;
498
+ referrer?: string;
499
+ navigationType?: NavigationType;
500
+ fromPage?: string;
501
+ toPage?: string;
502
+ isFirstVisit?: boolean;
503
+ isFirstLoad?: boolean;
504
+ deviceType?: string;
505
+ }
458
506
  /**
459
507
  * 生成事件ID
460
508
  */
@@ -1,5 +1,5 @@
1
- export { Config, CoreApiConfig, PagePerformanceStruct } from './config';
2
- export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, ReportTimeLog, EventLog, PlatTypeNum, NetworkTypeNum, } from './log';
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
4
  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';
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, EventOptions, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './event';
@@ -1,3 +1,3 @@
1
1
  import { Pipe } from './index';
2
- import { Config } from '../interface';
3
- export declare const createSpeedRepeatLimitPipe: (config: Config) => Pipe;
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 WebApiConfig = {
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
- apiSlowThreshold?: number;
11
+ slowThreshold?: number;
12
12
  assetSlowThreshold?: number;
13
13
  isSlowApi?: (api: any) => boolean;
14
14
  isSlowAsset?: (asset: any) => boolean;
15
- } & CoreApiConfig;
16
- declare type WebPageConfig = {
17
- slowPageThreshold?: number;
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
- } & PagePerformanceStruct;
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 IgnoreElements = {
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
- apiLog?: boolean;
43
- slowApiLog?: boolean;
44
- pageLoadLog?: boolean;
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
- ignoreElements?: IgnoreElements;
52
- webVitals?: boolean | {
53
- manualReport?: boolean;
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 { WebConfig } from '../../interface';
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: WebConfig, contentType: string | undefined, url: string) => any;
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?: WebConfig | undefined, apiData?: any) => boolean;
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: WebConfig, defaultValue: {
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';
@@ -20,6 +20,10 @@ export interface ClickDetectorOptions {
20
20
  onSlowClick?: (data: SlowClickData) => void;
21
21
  /** 愤怒点击回调 */
22
22
  onRageClick?: (data: RageClickData) => void;
23
+ /** 点击开始回调 */
24
+ onClickStart?: (data: ClickStartData) => void;
25
+ /** 点击产生有效响应回调 */
26
+ onEffectiveAction?: (data: EffectiveActionData) => void;
23
27
  /** 死点击回调 */
24
28
  onDeadClick?: (data: DeadClickData) => void;
25
29
  }
@@ -63,6 +67,22 @@ export interface ClickNodeInfo {
63
67
  /** CSS 选择器 */
64
68
  selector?: string;
65
69
  }
70
+ /** 有效动作原因 */
71
+ export declare type EffectiveActionReason = 'dom_mutation' | 'spa_navigation' | 'page_unload' | 'external_navigation' | 'window_open' | 'download' | 'form_submit' | 'form_change' | 'api_success' | 'clipboard' | 'custom';
72
+ /** 点击开始数据 */
73
+ export interface ClickStartData {
74
+ node: ClickNodeInfo;
75
+ timestamp: number;
76
+ target: HTMLElement;
77
+ event: PointerEvent;
78
+ effectiveActionReason?: EffectiveActionReason;
79
+ }
80
+ /** 有效动作数据 */
81
+ export interface EffectiveActionData {
82
+ reason: EffectiveActionReason;
83
+ timestamp: number;
84
+ node?: ClickNodeInfo;
85
+ }
66
86
  /**
67
87
  * ClickDetector - 点击行为检测器
68
88
  */
@@ -111,9 +131,15 @@ export declare class ClickDetector {
111
131
  private cleanupSlowClick;
112
132
  private isSameTarget;
113
133
  /**
114
- * 检查是否为可点击元素
134
+ * 标记当前点击已产生有效动作
135
+ */
136
+ markEffectiveAction(reason: EffectiveActionReason): void;
137
+ private emitEffectiveAction;
138
+ /**
139
+ * 获取可点击元素
115
140
  */
116
- private isClickableElement;
141
+ private getClickableElement;
142
+ private getExternalNavigationReason;
117
143
  /**
118
144
  * 获取节点信息
119
145
  */