@anker-in/analysis 0.2.0 → 0.2.2

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/dist/index.d.mts CHANGED
@@ -114,7 +114,6 @@ interface WithTrackingConfig<P extends PlatformType = PlatformType> {
114
114
  * TrackByTags 事件数据接口
115
115
  */
116
116
  interface TrackByTagsData {
117
- event: string;
118
117
  [key: string]: any;
119
118
  }
120
119
  /**
@@ -122,7 +121,7 @@ interface TrackByTagsData {
122
121
  */
123
122
  interface TrackByTagsParams {
124
123
  tags: string[];
125
- data: TrackByTagsData[];
124
+ data?: TrackByTagsData[];
126
125
  }
127
126
  /**
128
127
  * 解析后的标签结构(内部使用)
@@ -137,13 +136,6 @@ interface ParsedTag {
137
136
  * 埋点平台类型
138
137
  */
139
138
  type PlatformType = "gtag" | "meta";
140
- declare global {
141
- interface Window {
142
- gtag?: (...args: any[]) => void;
143
- fbq?: (...args: any[]) => void;
144
- dataLayer?: any[];
145
- }
146
- }
147
139
  /**
148
140
  * 埋点事件类型
149
141
  */
@@ -262,17 +254,17 @@ declare function withTracking<T extends (...args: any[]) => any>(fn: T, config:
262
254
  declare function useTracking(config: WithTrackingConfig): <T extends (...args: any[]) => any>(fn: T) => T;
263
255
 
264
256
  /**
265
- * 基于标签进行埋点上报
257
+ * 基于标签进行埋点上报(简化版)
266
258
  *
267
259
  * @param tags - 标签数组,格式: ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123']
268
- * @param data - 事件数据数组,每个元素包含 event 字段用于匹配标签
260
+ * @param data - 事件数据数组,包含事件相关的额外数据
269
261
  *
270
262
  * @example
271
263
  * ```typescript
272
- * trackByTags(
273
- * ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123'],
274
- * [{ event: 'atc' }]
275
- * );
264
+ * trackByTags({
265
+ * tags: ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123'],
266
+ * data: [{ event: 'custom' }]
267
+ * });
276
268
  * ```
277
269
  */
278
270
  declare function trackByTags({ tags, data }: TrackByTagsParams): void;
@@ -325,6 +317,109 @@ declare function updateScriptsType(scriptIds: string[] | ((index: number) => str
325
317
  */
326
318
  declare const isPlatformAvailable: (platform: PlatformType) => boolean;
327
319
 
320
+ /**
321
+ * 触发埋点上报工具
322
+ *
323
+ * 从 sessionStorage 读取 trackTags 配置,并根据 trackPoint 触发对应的埋点上报
324
+ */
325
+ /**
326
+ * TrackTags 配置类型
327
+ * key: trackPoint 标识
328
+ * value: 标签数组
329
+ */
330
+ interface TrackTagsConfig {
331
+ [trackPoint: string]: string[];
332
+ }
333
+ /**
334
+ * 埋点触发选项
335
+ */
336
+ interface TriggerTrackOptions {
337
+ tags?: Array<string>;
338
+ /** 自定义事件数据 */
339
+ eventData?: Record<string, unknown>;
340
+ /** 自定义存储键名,默认为 'trackTags' */
341
+ storageKey?: string;
342
+ /** 是否静默失败(不输出警告日志),默认为 false */
343
+ silent?: boolean;
344
+ }
345
+ /**
346
+ * 触发埋点上报
347
+ *
348
+ * 从 sessionStorage 读取 trackTags 配置,根据 trackPoint 获取对应的标签数组,
349
+ * 然后调用 trackByTags 进行埋点上报。
350
+ *
351
+ * @param trackPoint - 埋点标识,对应 trackTags 中的 key
352
+ * @param options - 可选配置项
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * // 基础用法
357
+ * triggerTrack('add_to_cart');
358
+ *
359
+ * // 带自定义数据
360
+ * triggerTrack('purchase', {
361
+ * eventData: {
362
+ * value: 99.99,
363
+ * currency: 'USD',
364
+ * transactionId: 'ORDER-123'
365
+ * }
366
+ * });
367
+ *
368
+ * // 使用自定义存储键
369
+ * triggerTrack('custom_event', {
370
+ * storageKey: 'customTrackTags'
371
+ * });
372
+ * ```
373
+ */
374
+ declare function triggerTrack(trackPoint: string, options?: TriggerTrackOptions): void;
375
+ /**
376
+ * 批量触发多个埋点
377
+ *
378
+ * @param trackPoints - 埋点标识数组
379
+ * @param options - 可选配置项(应用到所有埋点)
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * // 批量触发多个埋点
384
+ * triggerTrackBatch(['view_item', 'add_to_cart']);
385
+ *
386
+ * // 带共享的事件数据
387
+ * triggerTrackBatch(['event1', 'event2'], {
388
+ * eventData: { sessionId: '12345' }
389
+ * });
390
+ * ```
391
+ */
392
+ declare function triggerTrackBatch(trackPoints: string[], options?: TriggerTrackOptions): void;
393
+ /**
394
+ * 设置 trackTags 到 sessionStorage
395
+ *
396
+ * @param trackTags - TrackTags 配置对象
397
+ * @param storageKey - 存储键名,默认为 'trackTags'
398
+ *
399
+ * @example
400
+ * ```typescript
401
+ * setTrackTags({
402
+ * 'add_to_cart': ['fbq:atc:123456', 'gtag:atc:AW-123/abc'],
403
+ * 'purchase': ['fbq:purchase:123456', 'gtag:purchase:AW-123/xyz']
404
+ * });
405
+ * ```
406
+ */
407
+ declare function setTrackTags(trackTags: TrackTagsConfig, storageKey?: string): void;
408
+ /**
409
+ * 清除 trackTags
410
+ *
411
+ * @param storageKey - 存储键名,默认为 'trackTags'
412
+ */
413
+ declare function clearTrackTags(storageKey?: string): void;
414
+ /**
415
+ * 检查某个 trackPoint 是否存在
416
+ *
417
+ * @param trackPoint - 埋点标识
418
+ * @param storageKey - 存储键名,默认为 'trackTags'
419
+ * @returns 是否存在对应的标签配置
420
+ */
421
+ declare function hasTrackPoint(trackPoint: string, storageKey?: string): boolean;
422
+
328
423
  /**
329
424
  * Google Analytics / gtag.js 适配器
330
425
  * 使用标准的 window.gtag() API
@@ -384,4 +479,4 @@ declare const _default: {
384
479
  updateScriptsType: typeof updateScriptsType;
385
480
  };
386
481
 
387
- export { type AnalysisConfig, type AutoTrackConfig, type BasePlatformConfig, type Currency, type GtagConfig, type GtagConfigParams, type GtagEventName, GtagPixel, type GtagTrackParams, MetaPixel, type MetaPixelConfig, type MetaTrackParams, type ParsedTag, PixelsManager, type PixelsManagerConfig, type PlatformType, type ScarabConfig, type TikTokPixelConfig, type TrackByTagsData, type TrackByTagsParams, type TrackConfig, type TrackEventType, type TrackParams, TrackTagsVersionMap, type Tracker, type UpdateScriptTypeOptions, _default as default, gtagTrack, isPlatformAvailable, logger, metaTrack, track, trackByTags, updateScriptType, updateScriptsType, useTracking, withTracking };
482
+ export { type AnalysisConfig, type AutoTrackConfig, type BasePlatformConfig, type Currency, type GtagConfig, type GtagConfigParams, type GtagEventName, GtagPixel, type GtagTrackParams, MetaPixel, type MetaPixelConfig, type MetaTrackParams, type ParsedTag, PixelsManager, type PixelsManagerConfig, type PlatformType, type ScarabConfig, type TikTokPixelConfig, type TrackByTagsData, type TrackByTagsParams, type TrackConfig, type TrackEventType, type TrackParams, type TrackTagsConfig, TrackTagsVersionMap, type Tracker, type TriggerTrackOptions, type UpdateScriptTypeOptions, clearTrackTags, _default as default, gtagTrack, hasTrackPoint, isPlatformAvailable, logger, metaTrack, setTrackTags, track, trackByTags, triggerTrack, triggerTrackBatch, updateScriptType, updateScriptsType, useTracking, withTracking };
package/dist/index.d.ts CHANGED
@@ -114,7 +114,6 @@ interface WithTrackingConfig<P extends PlatformType = PlatformType> {
114
114
  * TrackByTags 事件数据接口
115
115
  */
116
116
  interface TrackByTagsData {
117
- event: string;
118
117
  [key: string]: any;
119
118
  }
120
119
  /**
@@ -122,7 +121,7 @@ interface TrackByTagsData {
122
121
  */
123
122
  interface TrackByTagsParams {
124
123
  tags: string[];
125
- data: TrackByTagsData[];
124
+ data?: TrackByTagsData[];
126
125
  }
127
126
  /**
128
127
  * 解析后的标签结构(内部使用)
@@ -137,13 +136,6 @@ interface ParsedTag {
137
136
  * 埋点平台类型
138
137
  */
139
138
  type PlatformType = "gtag" | "meta";
140
- declare global {
141
- interface Window {
142
- gtag?: (...args: any[]) => void;
143
- fbq?: (...args: any[]) => void;
144
- dataLayer?: any[];
145
- }
146
- }
147
139
  /**
148
140
  * 埋点事件类型
149
141
  */
@@ -262,17 +254,17 @@ declare function withTracking<T extends (...args: any[]) => any>(fn: T, config:
262
254
  declare function useTracking(config: WithTrackingConfig): <T extends (...args: any[]) => any>(fn: T) => T;
263
255
 
264
256
  /**
265
- * 基于标签进行埋点上报
257
+ * 基于标签进行埋点上报(简化版)
266
258
  *
267
259
  * @param tags - 标签数组,格式: ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123']
268
- * @param data - 事件数据数组,每个元素包含 event 字段用于匹配标签
260
+ * @param data - 事件数据数组,包含事件相关的额外数据
269
261
  *
270
262
  * @example
271
263
  * ```typescript
272
- * trackByTags(
273
- * ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123'],
274
- * [{ event: 'atc' }]
275
- * );
264
+ * trackByTags({
265
+ * tags: ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123'],
266
+ * data: [{ event: 'custom' }]
267
+ * });
276
268
  * ```
277
269
  */
278
270
  declare function trackByTags({ tags, data }: TrackByTagsParams): void;
@@ -325,6 +317,109 @@ declare function updateScriptsType(scriptIds: string[] | ((index: number) => str
325
317
  */
326
318
  declare const isPlatformAvailable: (platform: PlatformType) => boolean;
327
319
 
320
+ /**
321
+ * 触发埋点上报工具
322
+ *
323
+ * 从 sessionStorage 读取 trackTags 配置,并根据 trackPoint 触发对应的埋点上报
324
+ */
325
+ /**
326
+ * TrackTags 配置类型
327
+ * key: trackPoint 标识
328
+ * value: 标签数组
329
+ */
330
+ interface TrackTagsConfig {
331
+ [trackPoint: string]: string[];
332
+ }
333
+ /**
334
+ * 埋点触发选项
335
+ */
336
+ interface TriggerTrackOptions {
337
+ tags?: Array<string>;
338
+ /** 自定义事件数据 */
339
+ eventData?: Record<string, unknown>;
340
+ /** 自定义存储键名,默认为 'trackTags' */
341
+ storageKey?: string;
342
+ /** 是否静默失败(不输出警告日志),默认为 false */
343
+ silent?: boolean;
344
+ }
345
+ /**
346
+ * 触发埋点上报
347
+ *
348
+ * 从 sessionStorage 读取 trackTags 配置,根据 trackPoint 获取对应的标签数组,
349
+ * 然后调用 trackByTags 进行埋点上报。
350
+ *
351
+ * @param trackPoint - 埋点标识,对应 trackTags 中的 key
352
+ * @param options - 可选配置项
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * // 基础用法
357
+ * triggerTrack('add_to_cart');
358
+ *
359
+ * // 带自定义数据
360
+ * triggerTrack('purchase', {
361
+ * eventData: {
362
+ * value: 99.99,
363
+ * currency: 'USD',
364
+ * transactionId: 'ORDER-123'
365
+ * }
366
+ * });
367
+ *
368
+ * // 使用自定义存储键
369
+ * triggerTrack('custom_event', {
370
+ * storageKey: 'customTrackTags'
371
+ * });
372
+ * ```
373
+ */
374
+ declare function triggerTrack(trackPoint: string, options?: TriggerTrackOptions): void;
375
+ /**
376
+ * 批量触发多个埋点
377
+ *
378
+ * @param trackPoints - 埋点标识数组
379
+ * @param options - 可选配置项(应用到所有埋点)
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * // 批量触发多个埋点
384
+ * triggerTrackBatch(['view_item', 'add_to_cart']);
385
+ *
386
+ * // 带共享的事件数据
387
+ * triggerTrackBatch(['event1', 'event2'], {
388
+ * eventData: { sessionId: '12345' }
389
+ * });
390
+ * ```
391
+ */
392
+ declare function triggerTrackBatch(trackPoints: string[], options?: TriggerTrackOptions): void;
393
+ /**
394
+ * 设置 trackTags 到 sessionStorage
395
+ *
396
+ * @param trackTags - TrackTags 配置对象
397
+ * @param storageKey - 存储键名,默认为 'trackTags'
398
+ *
399
+ * @example
400
+ * ```typescript
401
+ * setTrackTags({
402
+ * 'add_to_cart': ['fbq:atc:123456', 'gtag:atc:AW-123/abc'],
403
+ * 'purchase': ['fbq:purchase:123456', 'gtag:purchase:AW-123/xyz']
404
+ * });
405
+ * ```
406
+ */
407
+ declare function setTrackTags(trackTags: TrackTagsConfig, storageKey?: string): void;
408
+ /**
409
+ * 清除 trackTags
410
+ *
411
+ * @param storageKey - 存储键名,默认为 'trackTags'
412
+ */
413
+ declare function clearTrackTags(storageKey?: string): void;
414
+ /**
415
+ * 检查某个 trackPoint 是否存在
416
+ *
417
+ * @param trackPoint - 埋点标识
418
+ * @param storageKey - 存储键名,默认为 'trackTags'
419
+ * @returns 是否存在对应的标签配置
420
+ */
421
+ declare function hasTrackPoint(trackPoint: string, storageKey?: string): boolean;
422
+
328
423
  /**
329
424
  * Google Analytics / gtag.js 适配器
330
425
  * 使用标准的 window.gtag() API
@@ -384,4 +479,4 @@ declare const _default: {
384
479
  updateScriptsType: typeof updateScriptsType;
385
480
  };
386
481
 
387
- export { type AnalysisConfig, type AutoTrackConfig, type BasePlatformConfig, type Currency, type GtagConfig, type GtagConfigParams, type GtagEventName, GtagPixel, type GtagTrackParams, MetaPixel, type MetaPixelConfig, type MetaTrackParams, type ParsedTag, PixelsManager, type PixelsManagerConfig, type PlatformType, type ScarabConfig, type TikTokPixelConfig, type TrackByTagsData, type TrackByTagsParams, type TrackConfig, type TrackEventType, type TrackParams, TrackTagsVersionMap, type Tracker, type UpdateScriptTypeOptions, _default as default, gtagTrack, isPlatformAvailable, logger, metaTrack, track, trackByTags, updateScriptType, updateScriptsType, useTracking, withTracking };
482
+ export { type AnalysisConfig, type AutoTrackConfig, type BasePlatformConfig, type Currency, type GtagConfig, type GtagConfigParams, type GtagEventName, GtagPixel, type GtagTrackParams, MetaPixel, type MetaPixelConfig, type MetaTrackParams, type ParsedTag, PixelsManager, type PixelsManagerConfig, type PlatformType, type ScarabConfig, type TikTokPixelConfig, type TrackByTagsData, type TrackByTagsParams, type TrackConfig, type TrackEventType, type TrackParams, type TrackTagsConfig, TrackTagsVersionMap, type Tracker, type TriggerTrackOptions, type UpdateScriptTypeOptions, clearTrackTags, _default as default, gtagTrack, hasTrackPoint, isPlatformAvailable, logger, metaTrack, setTrackTags, track, trackByTags, triggerTrack, triggerTrackBatch, updateScriptType, updateScriptsType, useTracking, withTracking };