@macroui/event-tracker 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +343 -0
- package/bin/event-tracker-suggest.mjs +141 -0
- package/bin/event-tracker.mjs +157 -0
- package/dist/event-tracker.cjs +3449 -0
- package/dist/event-tracker.js +3455 -0
- package/dist/event-tracker.min.js +1 -0
- package/dist/event-tracker.mjs +3402 -0
- package/dist/plugin/auto-track.cjs +201 -0
- package/dist/plugin/auto-track.mjs +199 -0
- package/dist/plugin/debug-sender.cjs +214 -0
- package/dist/plugin/debug-sender.mjs +211 -0
- package/dist/plugin/encrypt.cjs +284 -0
- package/dist/plugin/encrypt.mjs +275 -0
- package/dist/plugin/exposure.cjs +121 -0
- package/dist/plugin/exposure.mjs +119 -0
- package/dist/plugin/indexeddb-sender.cjs +94 -0
- package/dist/plugin/indexeddb-sender.mjs +92 -0
- package/dist/plugin/pageleave.cjs +74 -0
- package/dist/plugin/pageleave.mjs +72 -0
- package/dist/plugin/pageload.cjs +198 -0
- package/dist/plugin/pageload.mjs +196 -0
- package/dist/plugin/session-event.cjs +142 -0
- package/dist/plugin/session-event.mjs +140 -0
- package/dist/plugin/webview-bridge.cjs +111 -0
- package/dist/plugin/webview-bridge.mjs +109 -0
- package/dist/types/core/env.d.ts +10 -0
- package/dist/types/core/errors.d.ts +76 -0
- package/dist/types/core/failed-queue.d.ts +24 -0
- package/dist/types/core/identity-api.d.ts +6 -0
- package/dist/types/core/identity.d.ts +39 -0
- package/dist/types/core/instance-channel.d.ts +34 -0
- package/dist/types/core/lifecycle.d.ts +26 -0
- package/dist/types/core/logger.d.ts +13 -0
- package/dist/types/core/plugin.d.ts +60 -0
- package/dist/types/core/profile-api.d.ts +6 -0
- package/dist/types/core/profile-store.d.ts +23 -0
- package/dist/types/core/register-api.d.ts +22 -0
- package/dist/types/core/retry-policy.d.ts +33 -0
- package/dist/types/core/send-pipeline.d.ts +55 -0
- package/dist/types/core/signed-identity.d.ts +29 -0
- package/dist/types/core/stage.d.ts +48 -0
- package/dist/types/core/track-api.d.ts +6 -0
- package/dist/types/core/tracker.d.ts +130 -0
- package/dist/types/core/uuid.d.ts +4 -0
- package/dist/types/index.d.ts +40 -0
- package/dist/types/plugins/auto-track/index.d.ts +21 -0
- package/dist/types/plugins/debug-sender/index.d.ts +24 -0
- package/dist/types/plugins/encrypt/index.d.ts +56 -0
- package/dist/types/plugins/exposure/index.d.ts +18 -0
- package/dist/types/plugins/indexeddb-sender/index.d.ts +15 -0
- package/dist/types/plugins/pageleave/index.d.ts +12 -0
- package/dist/types/plugins/pageload/index.d.ts +14 -0
- package/dist/types/plugins/session-event/index.d.ts +14 -0
- package/dist/types/plugins/webview-bridge/index.d.ts +33 -0
- package/dist/types/presets/preset-properties.d.ts +25 -0
- package/dist/types/send/ajax-sender.d.ts +11 -0
- package/dist/types/send/batch-sender.d.ts +17 -0
- package/dist/types/send/beacon-sender.d.ts +10 -0
- package/dist/types/send/encode.d.ts +8 -0
- package/dist/types/send/image-sender.d.ts +10 -0
- package/dist/types/send/sender.d.ts +20 -0
- package/dist/types/storage/indexeddb-store.d.ts +14 -0
- package/dist/types/storage/store.d.ts +56 -0
- package/dist/types/types/common.d.ts +26 -0
- package/dist/types/types/config.d.ts +117 -0
- package/dist/types/types/constants.d.ts +110 -0
- package/dist/types/types/index.d.ts +25 -0
- package/dist/types/types.test-d.d.ts +5 -0
- package/dist/types.test-d.ts +103 -0
- package/package.json +218 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* exposure 插件:元素曝光(IntersectionObserver)
|
|
3
|
+
* - $element_exposure 事件
|
|
4
|
+
* - 元素进入视口超过阈值持续 X ms 才上报(默认 500ms)
|
|
5
|
+
* - 同元素同阈值只上报一次
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from '../../core/plugin.js';
|
|
8
|
+
export interface ExposureOptions {
|
|
9
|
+
/** 选择器或元素集合 */
|
|
10
|
+
selector?: string;
|
|
11
|
+
/** 阈值(0~1,默认 0.5) */
|
|
12
|
+
threshold?: number;
|
|
13
|
+
/** 最小停留时间(ms,默认 500) */
|
|
14
|
+
duration?: number;
|
|
15
|
+
/** 额外附加属性(按 data-attr 注入到事件) */
|
|
16
|
+
attrPrefix?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function exposure(opts?: ExposureOptions): Plugin;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* indexeddb-sender 插件:把事件写到 IndexedDB(用于离线缓存 / 批量消费)
|
|
3
|
+
* - 不实际发送,只把序列化事件追加到指定 IDB store
|
|
4
|
+
* - 适合后续被 webview bridge / native / service worker 消费
|
|
5
|
+
*/
|
|
6
|
+
import type { Plugin } from '../../core/plugin.js';
|
|
7
|
+
export interface IndexedDBSenderOptions {
|
|
8
|
+
/** IDB 名(默认 event-tracker-outbox) */
|
|
9
|
+
dbName?: string;
|
|
10
|
+
/** object store 名(默认 outbox) */
|
|
11
|
+
storeName?: string;
|
|
12
|
+
/** 上限(条),超过从头丢弃 */
|
|
13
|
+
max?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function indexedDBSender(opts?: IndexedDBSenderOptions): Plugin;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pageleave 插件:用户离开页面(关闭、跳转、切到后台)时上报
|
|
3
|
+
* - $WebPageLeave 事件
|
|
4
|
+
* - 包含 $event_duration / $url_path / $referrer / $viewport_position
|
|
5
|
+
* - 包含 page_visible 标记(visibilitychange API)
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from '../../core/plugin.js';
|
|
8
|
+
export interface PageLeaveOptions {
|
|
9
|
+
/** 是否同步阻塞(sendBeacon 异步即可) */
|
|
10
|
+
sendOnUnload?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function pageLeave(_opts?: PageLeaveOptions): Plugin;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pageload 插件:performance API 采集首屏加载性能
|
|
3
|
+
* - $WebPageLoad 事件,包含:
|
|
4
|
+
* $load_time / $dom_ready_time / $dom_interactive_time / $response_time
|
|
5
|
+
* $page_resource_size / $page_height / $viewport_position
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from '../../core/plugin.js';
|
|
8
|
+
export interface PageLoadOptions {
|
|
9
|
+
/** 是否立即触发(默认 true) */
|
|
10
|
+
immediate?: boolean;
|
|
11
|
+
/** 自定义时间轴 */
|
|
12
|
+
measures?: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare function pageLoad(opts?: PageLoadOptions): Plugin;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session-event 插件:会话管理
|
|
3
|
+
* - 每条事件附 $event_session_id(首次访问生成,存 storage)
|
|
4
|
+
* - $session_start / $session_end 事件
|
|
5
|
+
* - 超时(默认 30 分钟)则重开会话
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from '../../core/plugin.js';
|
|
8
|
+
export interface SessionOptions {
|
|
9
|
+
/** 会话超时(ms) */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
/** 是否在超时上报 $session_end */
|
|
12
|
+
endOnTimeout?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function sessionEvent(opts?: SessionOptions): Plugin;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebView 桥(vapph5 协议)
|
|
3
|
+
* - 客户端(iOS/Android)注入 window.vapph5define 对象
|
|
4
|
+
* - H5 通过 vapph5define.call(name, args) 调用客户端方法
|
|
5
|
+
* - 客户端通过 vapph5define.handle(name, fn) 监听 H5 调用
|
|
6
|
+
*
|
|
7
|
+
* 本插件负责:
|
|
8
|
+
* 1. 探测 WebView 标识
|
|
9
|
+
* 2. 在 SDK 启动时调用 vapph5define.call('getAppInfo'),把 app_version/app_id/...
|
|
10
|
+
* 注入到 config 与公共属性
|
|
11
|
+
* 3. 暴露 helper:bridge.call(name, args) 与 bridge.on(name, fn)
|
|
12
|
+
*/
|
|
13
|
+
import type { Plugin } from '../../core/plugin.js';
|
|
14
|
+
declare global {
|
|
15
|
+
interface Window {
|
|
16
|
+
vapph5define?: {
|
|
17
|
+
call: (name: string, ...args: unknown[]) => unknown;
|
|
18
|
+
handle: (name: string, fn: (...args: unknown[]) => unknown) => void;
|
|
19
|
+
isInApp?: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export interface WebViewBridgeOptions {
|
|
24
|
+
/** 自定义 vapph5 对象,默认 window.vapph5define */
|
|
25
|
+
defineName?: string;
|
|
26
|
+
/** 是否在 install 时立刻拉 app 信息 */
|
|
27
|
+
fetchOnInit?: boolean;
|
|
28
|
+
/** 自定义取 app 信息的协议名(默认 'getAppInfo') */
|
|
29
|
+
protocolName?: string;
|
|
30
|
+
/** 取回的应用信息合并到 SDK 的字段映射 */
|
|
31
|
+
fieldMap?: Partial<Record<'app_version' | 'app_id' | 'app_state' | 'channel' | 'lib', string>>;
|
|
32
|
+
}
|
|
33
|
+
export declare function webviewBridge(opts?: WebViewBridgeOptions): Plugin;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 公共属性 / 预置事件属性
|
|
3
|
+
* - 每次事件都会附加的属性
|
|
4
|
+
* - 包括 $lib / $lib_version / $app_id / $screen_width / $viewport_width / $url / $referrer / $latest_utm_* / ...
|
|
5
|
+
*
|
|
6
|
+
* 泛型 TRegisterProps:让用户能约束 register() / preset 的字段类型
|
|
7
|
+
*/
|
|
8
|
+
import type { TrackerConfig } from '../types/index.js';
|
|
9
|
+
/** 默认 register 类型 */
|
|
10
|
+
export type DefaultRegisterProps = Record<string, unknown>;
|
|
11
|
+
export declare class PresetPropertyBuilder<TRegister extends DefaultRegisterProps = DefaultRegisterProps> {
|
|
12
|
+
/** 当前会话级用户预设属性(来自 config.preset_properties) */
|
|
13
|
+
private preset;
|
|
14
|
+
setPreset(props: Partial<TRegister>): void;
|
|
15
|
+
/** 一次性写入:每条事件都带 */
|
|
16
|
+
register(props: Partial<TRegister>): void;
|
|
17
|
+
/** 一次性写入:只在同会话内首次写入生效 */
|
|
18
|
+
registerOnce(props: Partial<TRegister>): void;
|
|
19
|
+
clearRegister(): void;
|
|
20
|
+
unsetRegister<K extends keyof TRegister>(key: K): void;
|
|
21
|
+
getPreset(): Partial<TRegister>;
|
|
22
|
+
/** 计算一次最终合并的属性(含 lib 自身信息、UA、URL 等) */
|
|
23
|
+
build(config: TrackerConfig, baseProps?: Record<string, unknown>): Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
export declare function parseUtm(query: string): Record<string, string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ajax 发送器(fetch + keepalive)
|
|
3
|
+
*/
|
|
4
|
+
import type { SendContext, Sender } from './sender.js';
|
|
5
|
+
import type { EventData } from '../types/index.js';
|
|
6
|
+
export declare class AjaxSender implements Sender {
|
|
7
|
+
name: "ajax";
|
|
8
|
+
canUse(): boolean;
|
|
9
|
+
send(event: EventData, ctx: SendContext): Promise<void>;
|
|
10
|
+
sendBatch(events: EventData[], ctx: SendContext): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch 发送器:事件先入队到 localStorage,定时或达上限时一次性 POST
|
|
3
|
+
*/
|
|
4
|
+
import type { SendContext, Sender } from './sender.js';
|
|
5
|
+
import type { EventData } from '../types/index.js';
|
|
6
|
+
export declare class BatchSender implements Sender {
|
|
7
|
+
name: "batch";
|
|
8
|
+
private timer;
|
|
9
|
+
canUse(): boolean;
|
|
10
|
+
start(ctx: SendContext): void;
|
|
11
|
+
stop(): void;
|
|
12
|
+
send(event: EventData, ctx: SendContext): Promise<void>;
|
|
13
|
+
private enqueue;
|
|
14
|
+
private read;
|
|
15
|
+
private write;
|
|
16
|
+
flush(ctx: SendContext): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beacon 发送器(navigator.sendBeacon)
|
|
3
|
+
*/
|
|
4
|
+
import type { SendContext, Sender } from './sender.js';
|
|
5
|
+
import type { EventData } from '../types/index.js';
|
|
6
|
+
export declare class BeaconSender implements Sender {
|
|
7
|
+
name: "beacon";
|
|
8
|
+
canUse(): boolean;
|
|
9
|
+
send(event: EventData, ctx: SendContext): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 序列化 & 编码
|
|
3
|
+
*/
|
|
4
|
+
import type { EventData } from '../types/index.js';
|
|
5
|
+
export type EncryptFn = (data: string) => string | Promise<string>;
|
|
6
|
+
export declare function encodeEvent(event: EventData, encryptor?: EncryptFn): string | Promise<string>;
|
|
7
|
+
export declare function encodeBatch(events: EventData[], encryptor?: EncryptFn): string | Promise<string>;
|
|
8
|
+
export declare function buildUrl(serverUrl: string | string[], payload: string, contentType?: 'json' | 'form'): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image 发送器(1x1 gif 兜底,兼容性最好)
|
|
3
|
+
*/
|
|
4
|
+
import type { SendContext, Sender } from './sender.js';
|
|
5
|
+
import type { EventData } from '../types/index.js';
|
|
6
|
+
export declare class ImageSender implements Sender {
|
|
7
|
+
name: "image";
|
|
8
|
+
canUse(): boolean;
|
|
9
|
+
send(event: EventData, ctx: SendContext): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 发送器基类
|
|
3
|
+
*/
|
|
4
|
+
import type { EventData, TrackerConfig, SendType } from '../types/index.js';
|
|
5
|
+
import type { Logger } from '../core/logger.js';
|
|
6
|
+
export interface SendContext {
|
|
7
|
+
config: TrackerConfig;
|
|
8
|
+
logger: Logger;
|
|
9
|
+
}
|
|
10
|
+
export interface Sender {
|
|
11
|
+
/** 此发送器是否适用于当前上下文 */
|
|
12
|
+
canUse(): boolean;
|
|
13
|
+
/** 发送单条事件 */
|
|
14
|
+
send(event: EventData, ctx: SendContext): Promise<void> | void;
|
|
15
|
+
/** 批量发送(batch 模式) */
|
|
16
|
+
sendBatch?(events: EventData[], ctx: SendContext): Promise<void> | void;
|
|
17
|
+
/** 名称 */
|
|
18
|
+
name: SendType | string;
|
|
19
|
+
}
|
|
20
|
+
export declare function pickSender(type: SendType | undefined, candidates: Sender[]): Sender;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IndexedDB KV 存储(同步接口版本)
|
|
3
|
+
* - 通过 localStorage 镜像 + 后台 IDB 写入实现同步语义
|
|
4
|
+
* - 对 SDK 完全透明:实现同步 KVStore 接口
|
|
5
|
+
*/
|
|
6
|
+
import type { KVStore } from './store.js';
|
|
7
|
+
export declare class IndexedDBStoreSync implements KVStore {
|
|
8
|
+
private dbPromise;
|
|
9
|
+
constructor();
|
|
10
|
+
get(key: string): string | null;
|
|
11
|
+
set(key: string, value: string): void;
|
|
12
|
+
remove(key: string): void;
|
|
13
|
+
keys(prefix?: string): string[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一 KV 存储抽象
|
|
3
|
+
* - CookieStore
|
|
4
|
+
* - LocalStorageStore
|
|
5
|
+
* - SessionStorageStore
|
|
6
|
+
* - MemoryStore
|
|
7
|
+
*/
|
|
8
|
+
import type { StorageType } from '../types/index.js';
|
|
9
|
+
export interface KVStore {
|
|
10
|
+
get(key: string): string | null;
|
|
11
|
+
set(key: string, value: string, expiresDays?: number): void;
|
|
12
|
+
remove(key: string): void;
|
|
13
|
+
/** 当前所有 key(用于清除命名空间) */
|
|
14
|
+
keys(prefix?: string): string[];
|
|
15
|
+
}
|
|
16
|
+
export declare class MemoryStore implements KVStore {
|
|
17
|
+
private backing;
|
|
18
|
+
get(key: string): string | null;
|
|
19
|
+
set(key: string, value: string): void;
|
|
20
|
+
remove(key: string): void;
|
|
21
|
+
keys(prefix?: string): string[];
|
|
22
|
+
}
|
|
23
|
+
declare class CookieStore implements KVStore {
|
|
24
|
+
private domain?;
|
|
25
|
+
private crossSubdomain;
|
|
26
|
+
private secure;
|
|
27
|
+
constructor(domain?: string | undefined, crossSubdomain?: boolean, secure?: boolean);
|
|
28
|
+
get(key: string): string | null;
|
|
29
|
+
set(key: string, value: string, expiresDays?: number): void;
|
|
30
|
+
remove(key: string): void;
|
|
31
|
+
keys(prefix?: string): string[];
|
|
32
|
+
}
|
|
33
|
+
declare class LocalStorageStore implements KVStore {
|
|
34
|
+
get(key: string): string | null;
|
|
35
|
+
set(key: string, value: string): void;
|
|
36
|
+
remove(key: string): void;
|
|
37
|
+
keys(prefix?: string): string[];
|
|
38
|
+
}
|
|
39
|
+
declare class SessionStorageStore implements KVStore {
|
|
40
|
+
get(key: string): string | null;
|
|
41
|
+
set(key: string, value: string): void;
|
|
42
|
+
remove(key: string): void;
|
|
43
|
+
keys(prefix?: string): string[];
|
|
44
|
+
}
|
|
45
|
+
export declare function createStore(type: StorageType, opts?: {
|
|
46
|
+
cookieDomain?: string;
|
|
47
|
+
cookieCrossSubdomain?: boolean;
|
|
48
|
+
secureCookie?: boolean;
|
|
49
|
+
}): KVStore;
|
|
50
|
+
/** 自动选最合适的存储(cookie 不可用 → localStorage → memory) */
|
|
51
|
+
export declare function autoStore(opts?: {
|
|
52
|
+
cookieDomain?: string;
|
|
53
|
+
cookieCrossSubdomain?: boolean;
|
|
54
|
+
secureCookie?: boolean;
|
|
55
|
+
}): KVStore;
|
|
56
|
+
export { CookieStore, LocalStorageStore, SessionStorageStore };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用类型(v1.1.1)
|
|
3
|
+
*/
|
|
4
|
+
/** 上报方式 */
|
|
5
|
+
export type SendType = 'image' | 'beacon' | 'ajax' | 'batch';
|
|
6
|
+
/** 存储类型 */
|
|
7
|
+
export type StorageType = 'memory' | 'localStorage' | 'sessionStorage' | 'cookie' | 'indexeddb';
|
|
8
|
+
/** 日志级别 */
|
|
9
|
+
export type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
|
|
10
|
+
/** 事件回调 */
|
|
11
|
+
export type Callback = (err: Error | null) => void;
|
|
12
|
+
/** 任意 JSON 值 */
|
|
13
|
+
export type JSONValue = string | number | boolean | null | JSONObject | JSONArray;
|
|
14
|
+
export interface JSONObject {
|
|
15
|
+
[key: string]: JSONValue;
|
|
16
|
+
}
|
|
17
|
+
export interface JSONArray extends Array<JSONValue> {
|
|
18
|
+
}
|
|
19
|
+
/** 内部事件 payload 类型 */
|
|
20
|
+
export type PropertyMap = Record<string, unknown>;
|
|
21
|
+
/** 上报 URL 类型 */
|
|
22
|
+
export type ServerURL = string | string[];
|
|
23
|
+
/** 阶段名 */
|
|
24
|
+
export type StageName = 'buildDataStage' | 'businessStage' | 'sendDataStage';
|
|
25
|
+
/** 钩子名 */
|
|
26
|
+
export type HookName = 'sdkReady' | 'sdkInitPara' | 'sdkAfterInitPara' | 'sdkInitAPI' | 'sdkAfterInitAPI' | 'changeDistinctId' | 'switch';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TrackerConfig 类型分层(v1.1.1)
|
|
3
|
+
*
|
|
4
|
+
* BaseConfig 公共基础
|
|
5
|
+
* ├─ SendConfig 上报相关(URL / 模式 / 重试)
|
|
6
|
+
* ├─ StorageConfig 存储类型 / cookie 配置
|
|
7
|
+
* ├─ IdentityConfig 身份注入
|
|
8
|
+
* ├─ EncryptConfig 加密 / 脱敏
|
|
9
|
+
* ├─ PresetConfig 预设属性 / 事件
|
|
10
|
+
* └─ DebugConfig debug / 日志
|
|
11
|
+
*
|
|
12
|
+
* TrackerConfig = 所有子集
|
|
13
|
+
*/
|
|
14
|
+
import type { SendType, StorageType } from './common.js';
|
|
15
|
+
export interface BaseConfig {
|
|
16
|
+
/** 项目 ID(必填) */
|
|
17
|
+
app_id: string;
|
|
18
|
+
/** SDK 名(默认 event-tracker) */
|
|
19
|
+
lib_name?: string;
|
|
20
|
+
/** SDK 版本(默认 1.1.0) */
|
|
21
|
+
lib_version?: string;
|
|
22
|
+
/** 关闭 SDK:true 后所有 track 都是 noop */
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/** 自定义客户端事件时间戳(覆盖 Date.now) */
|
|
25
|
+
get_client_timestamp?: () => number;
|
|
26
|
+
}
|
|
27
|
+
export interface SendConfig {
|
|
28
|
+
/** 服务端接收地址(单点 / 多点) */
|
|
29
|
+
server_url: string | string[];
|
|
30
|
+
/** 发送方式(image/beacon/ajax/batch) */
|
|
31
|
+
send_type?: SendType;
|
|
32
|
+
/** 批量上报配置(batch 模式) */
|
|
33
|
+
batch_send?: {
|
|
34
|
+
send_interval?: number;
|
|
35
|
+
max_length?: number;
|
|
36
|
+
};
|
|
37
|
+
/** 单条超时(ms),超过后失败 */
|
|
38
|
+
send_timeout?: number;
|
|
39
|
+
/** 失败重试次数(默认 3) */
|
|
40
|
+
max_retry_count?: number;
|
|
41
|
+
/** 最大重试时长(ms),默认 30s */
|
|
42
|
+
max_retry_duration?: number;
|
|
43
|
+
/** 单条数据额外回调(成功后) */
|
|
44
|
+
callback?: (event: unknown) => void;
|
|
45
|
+
/** 单条数据发送失败回调 */
|
|
46
|
+
on_error?: (err: Error, event: unknown) => void;
|
|
47
|
+
}
|
|
48
|
+
export interface StorageConfig {
|
|
49
|
+
/** 存储类型(memory/localStorage/sessionStorage/cookie/indexeddb) */
|
|
50
|
+
storage_type?: StorageType;
|
|
51
|
+
/** cookie 作用域 */
|
|
52
|
+
cookie_domain?: string;
|
|
53
|
+
/** cookie 是否跨子域 */
|
|
54
|
+
cookie_cross_subdomain?: boolean;
|
|
55
|
+
/** cookie secure 标志 */
|
|
56
|
+
secure_cookie?: boolean;
|
|
57
|
+
/** localStorage 命名空间前缀 */
|
|
58
|
+
storage_prefix?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface IdentityConfig {
|
|
61
|
+
/** 已有的 distinct_id(外部系统注入) */
|
|
62
|
+
get_distinct_id?: () => string;
|
|
63
|
+
set_distinct_id?: (id: string) => void;
|
|
64
|
+
get_anonymous_id?: () => string;
|
|
65
|
+
set_anonymous_id?: (id: string) => void;
|
|
66
|
+
get_first_id?: () => string;
|
|
67
|
+
set_first_id?: (id: string) => void;
|
|
68
|
+
/** 身份签名密钥(开启 signed identity) */
|
|
69
|
+
identity_secret?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface EncryptConfig {
|
|
72
|
+
/** 加密(接收 JSON 字符串返回 string | Promise<string>) */
|
|
73
|
+
encryptor?: (data: string) => string | Promise<string>;
|
|
74
|
+
/** 解密(占位) */
|
|
75
|
+
decoder?: (data: string) => string;
|
|
76
|
+
/** 事件级加密前钩子(脱敏 / 补字段) */
|
|
77
|
+
encryptEvent?: (event: Record<string, unknown>) => unknown;
|
|
78
|
+
/** 解密后处理 */
|
|
79
|
+
decryptEvent?: (event: Record<string, unknown>) => unknown;
|
|
80
|
+
}
|
|
81
|
+
export interface PresetConfig {
|
|
82
|
+
/** 自定义预置属性(覆盖默认) */
|
|
83
|
+
preset_properties?: Record<string, unknown>;
|
|
84
|
+
/** 是否采集 UTM 参数(默认 true) */
|
|
85
|
+
is_collect_utm?: boolean;
|
|
86
|
+
}
|
|
87
|
+
export interface DebugConfig {
|
|
88
|
+
/** debug 模式(0=关闭 1=basic 2=verbose) */
|
|
89
|
+
debug?: 0 | 1 | 2;
|
|
90
|
+
/** 是否显示日志 */
|
|
91
|
+
show_log?: boolean;
|
|
92
|
+
}
|
|
93
|
+
export type TrackerConfig = BaseConfig & SendConfig & StorageConfig & IdentityConfig & EncryptConfig & PresetConfig & DebugConfig & JsAppConfig & ClientConfig & DebugSenderConfig;
|
|
94
|
+
export interface JsAppConfig {
|
|
95
|
+
/** 应用版本(JS) */
|
|
96
|
+
app_version?: string;
|
|
97
|
+
/** 自定义 user-agent */
|
|
98
|
+
user_agent?: string;
|
|
99
|
+
/** 多实例 client_id */
|
|
100
|
+
client_id?: string;
|
|
101
|
+
/** 数据上报超时(batch 模式兜底,alias of send_timeout) */
|
|
102
|
+
datasend_timeout?: number;
|
|
103
|
+
}
|
|
104
|
+
export interface ClientConfig {
|
|
105
|
+
/** 自定义 fetch(用于测试 / polyfill) */
|
|
106
|
+
customFetch?: typeof fetch;
|
|
107
|
+
/** 自定义 navigator.sendBeacon(用于测试) */
|
|
108
|
+
customSendBeacon?: (url: string, data: BodyInit | null) => boolean;
|
|
109
|
+
}
|
|
110
|
+
export interface DebugSenderConfig {
|
|
111
|
+
/** debug 模式下是否启用 debug-sender 插件 */
|
|
112
|
+
debug_mode?: boolean;
|
|
113
|
+
/** debug 上报 URL(覆盖 server_url) */
|
|
114
|
+
debug_mode_url?: string;
|
|
115
|
+
/** debug 上传目标 */
|
|
116
|
+
debug_mode_upload?: string;
|
|
117
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 预置事件名与预置属性 key(v1.1:完整对齐神策)
|
|
3
|
+
* 命名风格对齐神策,方便跨平台对接
|
|
4
|
+
*/
|
|
5
|
+
/** 预置事件名 */
|
|
6
|
+
export declare const PresetEvent: {
|
|
7
|
+
readonly PageView: "$pageview";
|
|
8
|
+
readonly WebPageLoad: "$WebPageLoad";
|
|
9
|
+
readonly WebPageLeave: "$WebPageLeave";
|
|
10
|
+
readonly WebClick: "$WebClick";
|
|
11
|
+
readonly WebStay: "$WebStay";
|
|
12
|
+
readonly SignUp: "$SignUp";
|
|
13
|
+
readonly BindID: "$BindID";
|
|
14
|
+
readonly UnbindID: "$UnbindID";
|
|
15
|
+
readonly ABTestTrigger: "$ABTestTrigger";
|
|
16
|
+
readonly PlanPopupClick: "$PlanPopupClick";
|
|
17
|
+
readonly PlanPopupDisplay: "$PlanPopupDisplay";
|
|
18
|
+
readonly ChannelLinkReaching: "$ChannelLinkReaching";
|
|
19
|
+
readonly ElementExposure: "$element_exposure";
|
|
20
|
+
readonly ScrollDepth: "$scrolldepth";
|
|
21
|
+
readonly ExitClick: "$exit_click";
|
|
22
|
+
readonly PageLeave: "$page_leave";
|
|
23
|
+
readonly HeatmapEvent: "$heatmap_event";
|
|
24
|
+
};
|
|
25
|
+
export type PresetEventName = (typeof PresetEvent)[keyof typeof PresetEvent];
|
|
26
|
+
/** 预置属性 key */
|
|
27
|
+
export declare const PresetProperty: {
|
|
28
|
+
readonly AppId: "$app_id";
|
|
29
|
+
readonly AppVersion: "$app_version";
|
|
30
|
+
readonly Lib: "$lib";
|
|
31
|
+
readonly LibMethod: "$lib_method";
|
|
32
|
+
readonly LibDetail: "$lib_detail";
|
|
33
|
+
readonly LibVersion: "$lib_version";
|
|
34
|
+
readonly ScreenWidth: "$screen_width";
|
|
35
|
+
readonly ScreenHeight: "$screen_height";
|
|
36
|
+
readonly ViewportWidth: "$viewport_width";
|
|
37
|
+
readonly ViewportHeight: "$viewport_height";
|
|
38
|
+
readonly TimezoneOffset: "$timezone_offset";
|
|
39
|
+
readonly UserAgent: "$user_agent";
|
|
40
|
+
readonly Language: "$language";
|
|
41
|
+
readonly FirstBrowserCharset: "$first_browser_charset";
|
|
42
|
+
readonly FirstBrowserLanguage: "$first_browser_language";
|
|
43
|
+
readonly URL: "$url";
|
|
44
|
+
readonly URLPath: "$url_path";
|
|
45
|
+
readonly Title: "$title";
|
|
46
|
+
readonly Referrer: "$referrer";
|
|
47
|
+
readonly ReferrerHost: "$referrer_host";
|
|
48
|
+
readonly LatestReferrer: "$latest_referrer";
|
|
49
|
+
readonly LatestReferrerHost: "$latest_referrer_host";
|
|
50
|
+
readonly LatestLandingPage: "$latest_landing_page";
|
|
51
|
+
readonly LatestSearchKeyword: "$latest_search_keyword";
|
|
52
|
+
readonly LatestTrafficSourceType: "$latest_traffic_source_type";
|
|
53
|
+
readonly FirstReferrer: "$first_referrer";
|
|
54
|
+
readonly FirstReferrerHost: "$first_referrer_host";
|
|
55
|
+
readonly FirstSearchKeyword: "$first_search_keyword";
|
|
56
|
+
readonly FirstTrafficSourceType: "$first_traffic_source_type";
|
|
57
|
+
readonly FirstVisitTime: "$first_visit_time";
|
|
58
|
+
readonly SearchKeywordId: "$search_keyword_id";
|
|
59
|
+
readonly SearchKeywordIdHash: "$search_keyword_id_hash";
|
|
60
|
+
readonly SearchKeywordIdType: "$search_keyword_id_type";
|
|
61
|
+
readonly IsFirstDay: "$is_first_day";
|
|
62
|
+
readonly IsFirstTime: "$is_first_time";
|
|
63
|
+
readonly LatestUtmSource: "$latest_utm_source";
|
|
64
|
+
readonly LatestUtmMedium: "$latest_utm_medium";
|
|
65
|
+
readonly LatestUtmCampaign: "$latest_utm_campaign";
|
|
66
|
+
readonly LatestUtmContent: "$latest_utm_content";
|
|
67
|
+
readonly LatestUtmTerm: "$latest_utm_term";
|
|
68
|
+
readonly Utms: "$utms";
|
|
69
|
+
readonly DistinctId: "$distinct_id";
|
|
70
|
+
readonly AnonymousId: "$anonymous_id";
|
|
71
|
+
readonly FirstId: "$first_id";
|
|
72
|
+
readonly OriginalId: "$original_id";
|
|
73
|
+
readonly LoginId: "$login_id";
|
|
74
|
+
readonly IsLoginId: "$is_login_id";
|
|
75
|
+
readonly IdentityLoginId: "$identity_login_id";
|
|
76
|
+
readonly IdentityAnonymousId: "$identity_anonymous_id";
|
|
77
|
+
readonly IdentityCookieId: "$identity_cookie_id";
|
|
78
|
+
readonly IdentityEmail: "$identity_email";
|
|
79
|
+
readonly IdentityMobile: "$identity_mobile";
|
|
80
|
+
readonly ElementSelector: "$element_selector";
|
|
81
|
+
readonly ElementPath: "$element_path";
|
|
82
|
+
readonly ElementType: "$element_type";
|
|
83
|
+
readonly ElementId: "$element_id";
|
|
84
|
+
readonly ElementClassName: "$element_class_name";
|
|
85
|
+
readonly ElementName: "$element_name";
|
|
86
|
+
readonly ElementContent: "$element_content";
|
|
87
|
+
readonly ElementTargetUrl: "$element_target_url";
|
|
88
|
+
readonly ElementPosition: "$element_position";
|
|
89
|
+
readonly PageX: "$page_x";
|
|
90
|
+
readonly PageY: "$page_y";
|
|
91
|
+
readonly PageHeight: "$page_height";
|
|
92
|
+
readonly PageResourceSize: "$page_resource_size";
|
|
93
|
+
readonly EventDuration: "$event_duration";
|
|
94
|
+
readonly ViewportPosition: "$viewport_position";
|
|
95
|
+
readonly LatestWxAdClickId: "$latest_wx_ad_click_id";
|
|
96
|
+
readonly LatestWxAdCallbacks: "$latest_wx_ad_callbacks";
|
|
97
|
+
readonly LatestWxAdHashKey: "$latest_wx_ad_hash_key";
|
|
98
|
+
readonly IsChannelCallbackEvent: "$is_channel_callback_event";
|
|
99
|
+
readonly EventSessionId: "$event_session_id";
|
|
100
|
+
readonly Time: "$time";
|
|
101
|
+
readonly Event: "$event";
|
|
102
|
+
readonly Option: "$option";
|
|
103
|
+
readonly Project: "$project";
|
|
104
|
+
readonly Token: "$token";
|
|
105
|
+
readonly SignupMethod: "$signup_method";
|
|
106
|
+
};
|
|
107
|
+
export type PresetPropertyKey = (typeof PresetProperty)[keyof typeof PresetProperty];
|
|
108
|
+
/** 库自身信息 */
|
|
109
|
+
export declare const LIB_NAME = "event-tracker";
|
|
110
|
+
export declare const LIB_VERSION = "1.1.0";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 类型总入口(v1.1.1)
|
|
3
|
+
*/
|
|
4
|
+
export type { SendType, StorageType, LogLevel, Callback, JSONValue, JSONObject, JSONArray, PropertyMap, ServerURL, StageName, HookName, } from './common.js';
|
|
5
|
+
export type { BaseConfig, SendConfig, StorageConfig, IdentityConfig, EncryptConfig, PresetConfig, DebugConfig, JsAppConfig, ClientConfig, DebugSenderConfig, TrackerConfig, } from './config.js';
|
|
6
|
+
/** 待发送事件结构 */
|
|
7
|
+
export interface EventData {
|
|
8
|
+
type: 'track' | 'track_signup' | 'track_id_bind' | 'track_id_unbind' | 'profile_set' | 'profile_set_once' | 'profile_increment' | 'profile_append' | 'profile_unset' | 'profile_delete' | 'item_set' | 'item_delete';
|
|
9
|
+
event?: string;
|
|
10
|
+
time: number;
|
|
11
|
+
distinct_id: string;
|
|
12
|
+
anonymous_id?: string;
|
|
13
|
+
first_id?: string;
|
|
14
|
+
login_id?: string;
|
|
15
|
+
original_id?: string;
|
|
16
|
+
properties: Record<string, unknown>;
|
|
17
|
+
token?: string;
|
|
18
|
+
project?: string;
|
|
19
|
+
lib?: {
|
|
20
|
+
$lib?: string;
|
|
21
|
+
$lib_version?: string;
|
|
22
|
+
};
|
|
23
|
+
_encrypted?: string;
|
|
24
|
+
}
|
|
25
|
+
export { PresetEvent, PresetProperty, LIB_NAME, LIB_VERSION } from './constants.js';
|