@anker-in/analysis 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
  * 解析后的标签结构(内部使用)
@@ -262,17 +261,17 @@ declare function withTracking<T extends (...args: any[]) => any>(fn: T, config:
262
261
  declare function useTracking(config: WithTrackingConfig): <T extends (...args: any[]) => any>(fn: T) => T;
263
262
 
264
263
  /**
265
- * 基于标签进行埋点上报
264
+ * 基于标签进行埋点上报(简化版)
266
265
  *
267
266
  * @param tags - 标签数组,格式: ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123']
268
- * @param data - 事件数据数组,每个元素包含 event 字段用于匹配标签
267
+ * @param data - 事件数据数组,包含事件相关的额外数据
269
268
  *
270
269
  * @example
271
270
  * ```typescript
272
- * trackByTags(
273
- * ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123'],
274
- * [{ event: 'atc' }]
275
- * );
271
+ * trackByTags({
272
+ * tags: ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123'],
273
+ * data: [{ event: 'custom' }]
274
+ * });
276
275
  * ```
277
276
  */
278
277
  declare function trackByTags({ tags, data }: TrackByTagsParams): void;
@@ -325,6 +324,109 @@ declare function updateScriptsType(scriptIds: string[] | ((index: number) => str
325
324
  */
326
325
  declare const isPlatformAvailable: (platform: PlatformType) => boolean;
327
326
 
327
+ /**
328
+ * 触发埋点上报工具
329
+ *
330
+ * 从 sessionStorage 读取 trackTags 配置,并根据 trackPoint 触发对应的埋点上报
331
+ */
332
+ /**
333
+ * TrackTags 配置类型
334
+ * key: trackPoint 标识
335
+ * value: 标签数组
336
+ */
337
+ interface TrackTagsConfig {
338
+ [trackPoint: string]: string[];
339
+ }
340
+ /**
341
+ * 埋点触发选项
342
+ */
343
+ interface TriggerTrackOptions {
344
+ tags?: Array<string>;
345
+ /** 自定义事件数据 */
346
+ eventData?: Record<string, unknown>;
347
+ /** 自定义存储键名,默认为 'trackTags' */
348
+ storageKey?: string;
349
+ /** 是否静默失败(不输出警告日志),默认为 false */
350
+ silent?: boolean;
351
+ }
352
+ /**
353
+ * 触发埋点上报
354
+ *
355
+ * 从 sessionStorage 读取 trackTags 配置,根据 trackPoint 获取对应的标签数组,
356
+ * 然后调用 trackByTags 进行埋点上报。
357
+ *
358
+ * @param trackPoint - 埋点标识,对应 trackTags 中的 key
359
+ * @param options - 可选配置项
360
+ *
361
+ * @example
362
+ * ```typescript
363
+ * // 基础用法
364
+ * triggerTrack('add_to_cart');
365
+ *
366
+ * // 带自定义数据
367
+ * triggerTrack('purchase', {
368
+ * eventData: {
369
+ * value: 99.99,
370
+ * currency: 'USD',
371
+ * transactionId: 'ORDER-123'
372
+ * }
373
+ * });
374
+ *
375
+ * // 使用自定义存储键
376
+ * triggerTrack('custom_event', {
377
+ * storageKey: 'customTrackTags'
378
+ * });
379
+ * ```
380
+ */
381
+ declare function triggerTrack(trackPoint: string, options?: TriggerTrackOptions): void;
382
+ /**
383
+ * 批量触发多个埋点
384
+ *
385
+ * @param trackPoints - 埋点标识数组
386
+ * @param options - 可选配置项(应用到所有埋点)
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * // 批量触发多个埋点
391
+ * triggerTrackBatch(['view_item', 'add_to_cart']);
392
+ *
393
+ * // 带共享的事件数据
394
+ * triggerTrackBatch(['event1', 'event2'], {
395
+ * eventData: { sessionId: '12345' }
396
+ * });
397
+ * ```
398
+ */
399
+ declare function triggerTrackBatch(trackPoints: string[], options?: TriggerTrackOptions): void;
400
+ /**
401
+ * 设置 trackTags 到 sessionStorage
402
+ *
403
+ * @param trackTags - TrackTags 配置对象
404
+ * @param storageKey - 存储键名,默认为 'trackTags'
405
+ *
406
+ * @example
407
+ * ```typescript
408
+ * setTrackTags({
409
+ * 'add_to_cart': ['fbq:atc:123456', 'gtag:atc:AW-123/abc'],
410
+ * 'purchase': ['fbq:purchase:123456', 'gtag:purchase:AW-123/xyz']
411
+ * });
412
+ * ```
413
+ */
414
+ declare function setTrackTags(trackTags: TrackTagsConfig, storageKey?: string): void;
415
+ /**
416
+ * 清除 trackTags
417
+ *
418
+ * @param storageKey - 存储键名,默认为 'trackTags'
419
+ */
420
+ declare function clearTrackTags(storageKey?: string): void;
421
+ /**
422
+ * 检查某个 trackPoint 是否存在
423
+ *
424
+ * @param trackPoint - 埋点标识
425
+ * @param storageKey - 存储键名,默认为 'trackTags'
426
+ * @returns 是否存在对应的标签配置
427
+ */
428
+ declare function hasTrackPoint(trackPoint: string, storageKey?: string): boolean;
429
+
328
430
  /**
329
431
  * Google Analytics / gtag.js 适配器
330
432
  * 使用标准的 window.gtag() API
@@ -384,4 +486,4 @@ declare const _default: {
384
486
  updateScriptsType: typeof updateScriptsType;
385
487
  };
386
488
 
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 };
489
+ 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
  * 解析后的标签结构(内部使用)
@@ -262,17 +261,17 @@ declare function withTracking<T extends (...args: any[]) => any>(fn: T, config:
262
261
  declare function useTracking(config: WithTrackingConfig): <T extends (...args: any[]) => any>(fn: T) => T;
263
262
 
264
263
  /**
265
- * 基于标签进行埋点上报
264
+ * 基于标签进行埋点上报(简化版)
266
265
  *
267
266
  * @param tags - 标签数组,格式: ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123']
268
- * @param data - 事件数据数组,每个元素包含 event 字段用于匹配标签
267
+ * @param data - 事件数据数组,包含事件相关的额外数据
269
268
  *
270
269
  * @example
271
270
  * ```typescript
272
- * trackByTags(
273
- * ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123'],
274
- * [{ event: 'atc' }]
275
- * );
271
+ * trackByTags({
272
+ * tags: ['fbq:atc:1234567890', 'gtag:atc:AW-123456789/abc123'],
273
+ * data: [{ event: 'custom' }]
274
+ * });
276
275
  * ```
277
276
  */
278
277
  declare function trackByTags({ tags, data }: TrackByTagsParams): void;
@@ -325,6 +324,109 @@ declare function updateScriptsType(scriptIds: string[] | ((index: number) => str
325
324
  */
326
325
  declare const isPlatformAvailable: (platform: PlatformType) => boolean;
327
326
 
327
+ /**
328
+ * 触发埋点上报工具
329
+ *
330
+ * 从 sessionStorage 读取 trackTags 配置,并根据 trackPoint 触发对应的埋点上报
331
+ */
332
+ /**
333
+ * TrackTags 配置类型
334
+ * key: trackPoint 标识
335
+ * value: 标签数组
336
+ */
337
+ interface TrackTagsConfig {
338
+ [trackPoint: string]: string[];
339
+ }
340
+ /**
341
+ * 埋点触发选项
342
+ */
343
+ interface TriggerTrackOptions {
344
+ tags?: Array<string>;
345
+ /** 自定义事件数据 */
346
+ eventData?: Record<string, unknown>;
347
+ /** 自定义存储键名,默认为 'trackTags' */
348
+ storageKey?: string;
349
+ /** 是否静默失败(不输出警告日志),默认为 false */
350
+ silent?: boolean;
351
+ }
352
+ /**
353
+ * 触发埋点上报
354
+ *
355
+ * 从 sessionStorage 读取 trackTags 配置,根据 trackPoint 获取对应的标签数组,
356
+ * 然后调用 trackByTags 进行埋点上报。
357
+ *
358
+ * @param trackPoint - 埋点标识,对应 trackTags 中的 key
359
+ * @param options - 可选配置项
360
+ *
361
+ * @example
362
+ * ```typescript
363
+ * // 基础用法
364
+ * triggerTrack('add_to_cart');
365
+ *
366
+ * // 带自定义数据
367
+ * triggerTrack('purchase', {
368
+ * eventData: {
369
+ * value: 99.99,
370
+ * currency: 'USD',
371
+ * transactionId: 'ORDER-123'
372
+ * }
373
+ * });
374
+ *
375
+ * // 使用自定义存储键
376
+ * triggerTrack('custom_event', {
377
+ * storageKey: 'customTrackTags'
378
+ * });
379
+ * ```
380
+ */
381
+ declare function triggerTrack(trackPoint: string, options?: TriggerTrackOptions): void;
382
+ /**
383
+ * 批量触发多个埋点
384
+ *
385
+ * @param trackPoints - 埋点标识数组
386
+ * @param options - 可选配置项(应用到所有埋点)
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * // 批量触发多个埋点
391
+ * triggerTrackBatch(['view_item', 'add_to_cart']);
392
+ *
393
+ * // 带共享的事件数据
394
+ * triggerTrackBatch(['event1', 'event2'], {
395
+ * eventData: { sessionId: '12345' }
396
+ * });
397
+ * ```
398
+ */
399
+ declare function triggerTrackBatch(trackPoints: string[], options?: TriggerTrackOptions): void;
400
+ /**
401
+ * 设置 trackTags 到 sessionStorage
402
+ *
403
+ * @param trackTags - TrackTags 配置对象
404
+ * @param storageKey - 存储键名,默认为 'trackTags'
405
+ *
406
+ * @example
407
+ * ```typescript
408
+ * setTrackTags({
409
+ * 'add_to_cart': ['fbq:atc:123456', 'gtag:atc:AW-123/abc'],
410
+ * 'purchase': ['fbq:purchase:123456', 'gtag:purchase:AW-123/xyz']
411
+ * });
412
+ * ```
413
+ */
414
+ declare function setTrackTags(trackTags: TrackTagsConfig, storageKey?: string): void;
415
+ /**
416
+ * 清除 trackTags
417
+ *
418
+ * @param storageKey - 存储键名,默认为 'trackTags'
419
+ */
420
+ declare function clearTrackTags(storageKey?: string): void;
421
+ /**
422
+ * 检查某个 trackPoint 是否存在
423
+ *
424
+ * @param trackPoint - 埋点标识
425
+ * @param storageKey - 存储键名,默认为 'trackTags'
426
+ * @returns 是否存在对应的标签配置
427
+ */
428
+ declare function hasTrackPoint(trackPoint: string, storageKey?: string): boolean;
429
+
328
430
  /**
329
431
  * Google Analytics / gtag.js 适配器
330
432
  * 使用标准的 window.gtag() API
@@ -384,4 +486,4 @@ declare const _default: {
384
486
  updateScriptsType: typeof updateScriptsType;
385
487
  };
386
488
 
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 };
489
+ 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.js CHANGED
@@ -123,6 +123,239 @@ var isPlatformAvailable = /* @__PURE__ */ __name((platform) => {
123
123
  }
124
124
  }, "isPlatformAvailable");
125
125
 
126
+ // src/constants/tagsMap.ts
127
+ var TrackTagsVersionMap = {
128
+ "fbq:act": "fbq:atc",
129
+ "gtag:conversion": "gtag:atc"
130
+ };
131
+
132
+ // src/autoTrack/trackByTags.ts
133
+ function parseTag(tag) {
134
+ const parts = tag.split(":");
135
+ if (parts.length < 2) {
136
+ return null;
137
+ }
138
+ return {
139
+ media: parts[0]?.toLowerCase() || "",
140
+ event: parts[1]?.toLowerCase() || "",
141
+ target: parts[2] || null
142
+ };
143
+ }
144
+ __name(parseTag, "parseTag");
145
+ function adaptEventName(tags) {
146
+ for (let i = 0; i < tags.length; i++) {
147
+ if (!tags[i]) {
148
+ continue;
149
+ }
150
+ for (const [oldEvent, newEvent] of Object.entries(TrackTagsVersionMap)) {
151
+ if (tags[i]?.includes(oldEvent)) {
152
+ tags[i] = tags[i]?.replace(oldEvent, newEvent) ?? "";
153
+ break;
154
+ }
155
+ }
156
+ }
157
+ }
158
+ __name(adaptEventName, "adaptEventName");
159
+ function handleTagTracking(parsedTag, eventData) {
160
+ const { media, event, target } = parsedTag;
161
+ if (!target) {
162
+ logger.warn(`Tag missing target: ${media}:${event}`);
163
+ return;
164
+ }
165
+ try {
166
+ switch (media) {
167
+ case "fbq":
168
+ case "meta": {
169
+ const config = {
170
+ platform: "meta",
171
+ event: target,
172
+ // target 作为事件名
173
+ data: eventData
174
+ };
175
+ track(config);
176
+ break;
177
+ }
178
+ case "gtag": {
179
+ const config = {
180
+ platform: "gtag",
181
+ eventName: "conversion",
182
+ send_to: target,
183
+ // target 作为转化目标ID
184
+ value: eventData?.value ?? 1,
185
+ currency: eventData?.currency,
186
+ transactionId: eventData?.transactionId
187
+ };
188
+ track(config);
189
+ break;
190
+ }
191
+ default:
192
+ logger.warn(`Unsupported media platform: ${media}`);
193
+ }
194
+ } catch (error) {
195
+ logger.error(`Failed to track tag ${media}:${event}:${target}:`, error);
196
+ }
197
+ }
198
+ __name(handleTagTracking, "handleTagTracking");
199
+ function trackByTags({ tags, data }) {
200
+ if (!tags || tags.length === 0) {
201
+ logger.warn("trackByTags: tags array is empty");
202
+ return;
203
+ }
204
+ const adaptedTags = [...tags];
205
+ adaptEventName(adaptedTags);
206
+ const firstData = data && data.length > 0 ? data[0] : void 0;
207
+ const { event, ...trackingData } = firstData || {};
208
+ adaptedTags.forEach((tag) => {
209
+ const parsed = parseTag(tag);
210
+ if (!parsed) {
211
+ logger.warn(`trackByTags: Invalid tag format: ${tag}`);
212
+ return;
213
+ }
214
+ handleTagTracking(parsed, trackingData);
215
+ });
216
+ }
217
+ __name(trackByTags, "trackByTags");
218
+
219
+ // src/core/helpers/triggerTrack.ts
220
+ function getTrackTagsFromStorage(storageKey) {
221
+ if (typeof window === "undefined" || !window.sessionStorage) {
222
+ logger.warn("sessionStorage is not available");
223
+ return null;
224
+ }
225
+ try {
226
+ const trackTagsRaw = sessionStorage.getItem(storageKey);
227
+ if (!trackTagsRaw) {
228
+ return null;
229
+ }
230
+ const trackTags = JSON.parse(trackTagsRaw);
231
+ if (!trackTags || typeof trackTags !== "object") {
232
+ logger.warn(
233
+ `Invalid trackTags format in sessionStorage key: ${storageKey}`
234
+ );
235
+ return null;
236
+ }
237
+ return trackTags;
238
+ } catch (error) {
239
+ logger.error(`Failed to parse trackTags from sessionStorage:`, error);
240
+ return null;
241
+ }
242
+ }
243
+ __name(getTrackTagsFromStorage, "getTrackTagsFromStorage");
244
+ function triggerTrack(trackPoint, options = {}) {
245
+ const {
246
+ tags,
247
+ eventData = {},
248
+ storageKey = "trackTags",
249
+ silent = false
250
+ } = options;
251
+ if (!trackPoint || typeof trackPoint !== "string") {
252
+ if (!silent) {
253
+ logger.warn("triggerTrack: trackPoint is required and must be a string");
254
+ }
255
+ return;
256
+ }
257
+ const trackTagsRow = getTrackTagsFromStorage(storageKey);
258
+ if (!trackTagsRow) {
259
+ if (!silent) {
260
+ logger.warn(
261
+ `triggerTrack: trackTags not found in sessionStorage (key: ${storageKey})`
262
+ );
263
+ }
264
+ return;
265
+ }
266
+ const trackTags = tags || trackTagsRow[trackPoint];
267
+ if (!trackTags) {
268
+ if (!silent) {
269
+ logger.warn(`triggerTrack: No tags found for trackPoint: ${trackPoint}`);
270
+ }
271
+ return;
272
+ }
273
+ if (!Array.isArray(trackTags)) {
274
+ if (!silent) {
275
+ logger.warn(
276
+ `triggerTrack: Tags for trackPoint "${trackPoint}" is not an array`
277
+ );
278
+ }
279
+ return;
280
+ }
281
+ if (trackTags.length === 0) {
282
+ if (!silent) {
283
+ logger.log(
284
+ `triggerTrack: Tags array is empty for trackPoint: ${trackPoint}`
285
+ );
286
+ }
287
+ return;
288
+ }
289
+ try {
290
+ trackByTags({
291
+ tags: trackTags,
292
+ data: [{ event: "custom", ...eventData }]
293
+ });
294
+ logger.log(
295
+ `triggerTrack: Successfully triggered for trackPoint: ${trackPoint}`,
296
+ {
297
+ tagsCount: trackTags.length,
298
+ trackTags
299
+ }
300
+ );
301
+ } catch (error) {
302
+ logger.error(
303
+ `triggerTrack: Failed to track for trackPoint: ${trackPoint}`,
304
+ error
305
+ );
306
+ }
307
+ }
308
+ __name(triggerTrack, "triggerTrack");
309
+ function triggerTrackBatch(trackPoints, options = {}) {
310
+ if (!Array.isArray(trackPoints)) {
311
+ logger.warn("triggerTrackBatch: trackPoints must be an array");
312
+ return;
313
+ }
314
+ trackPoints.forEach((trackPoint) => {
315
+ triggerTrack(trackPoint, options);
316
+ });
317
+ }
318
+ __name(triggerTrackBatch, "triggerTrackBatch");
319
+ function setTrackTags(trackTags, storageKey = "trackTags") {
320
+ if (typeof window === "undefined" || !window.sessionStorage) {
321
+ logger.warn("sessionStorage is not available");
322
+ return;
323
+ }
324
+ try {
325
+ const trackTagsJson = JSON.stringify(trackTags);
326
+ sessionStorage.setItem(storageKey, trackTagsJson);
327
+ logger.log(
328
+ `setTrackTags: Successfully saved to sessionStorage (key: ${storageKey})`
329
+ );
330
+ } catch (error) {
331
+ logger.error("setTrackTags: Failed to save to sessionStorage", error);
332
+ }
333
+ }
334
+ __name(setTrackTags, "setTrackTags");
335
+ function clearTrackTags(storageKey = "trackTags") {
336
+ if (typeof window === "undefined" || !window.sessionStorage) {
337
+ return;
338
+ }
339
+ try {
340
+ sessionStorage.removeItem(storageKey);
341
+ logger.log(
342
+ `clearTrackTags: Successfully removed from sessionStorage (key: ${storageKey})`
343
+ );
344
+ } catch (error) {
345
+ logger.error("clearTrackTags: Failed to remove from sessionStorage", error);
346
+ }
347
+ }
348
+ __name(clearTrackTags, "clearTrackTags");
349
+ function hasTrackPoint(trackPoint, storageKey = "trackTags") {
350
+ const trackTags = getTrackTagsFromStorage(storageKey);
351
+ if (!trackTags) {
352
+ return false;
353
+ }
354
+ const tags = trackTags[trackPoint];
355
+ return Array.isArray(tags) && tags.length > 0;
356
+ }
357
+ __name(hasTrackPoint, "hasTrackPoint");
358
+
126
359
  // src/core/adapters/gtag.ts
127
360
  var gtagTrack = /* @__PURE__ */ __name((command, targetOrEventName, params) => {
128
361
  if (typeof window === "undefined") {
@@ -215,121 +448,6 @@ function handleMetaTrack(params) {
215
448
  }
216
449
  __name(handleMetaTrack, "handleMetaTrack");
217
450
 
218
- // src/constants/tagsMap.ts
219
- var TrackTagsVersionMap = {
220
- "fbq:act": "fbq:atc",
221
- "gtag:conversion": "gtag:atc"
222
- };
223
-
224
- // src/autoTrack/trackByTags.ts
225
- function parseTag(tag) {
226
- const parts = tag.split(":");
227
- if (parts.length < 2) {
228
- return null;
229
- }
230
- return {
231
- media: parts[0]?.toLowerCase() || "",
232
- event: parts[1]?.toLowerCase() || "",
233
- target: parts[2] || null
234
- };
235
- }
236
- __name(parseTag, "parseTag");
237
- function adaptEventName(tags) {
238
- for (let i = 0; i < tags.length; i++) {
239
- if (!tags[i]) {
240
- continue;
241
- }
242
- for (const [oldEvent, newEvent] of Object.entries(TrackTagsVersionMap)) {
243
- if (tags[i]?.includes(oldEvent)) {
244
- tags[i] = tags[i]?.replace(oldEvent, newEvent) ?? "";
245
- break;
246
- }
247
- }
248
- }
249
- }
250
- __name(adaptEventName, "adaptEventName");
251
- function filterTagsByEvent(tags, eventSymbol) {
252
- return tags.filter((tag) => {
253
- const parsed = parseTag(tag);
254
- return parsed?.event === eventSymbol.toLowerCase();
255
- });
256
- }
257
- __name(filterTagsByEvent, "filterTagsByEvent");
258
- function handleTagTracking(parsedTag, eventData) {
259
- const { media, event, target } = parsedTag;
260
- if (!target) {
261
- logger.warn(`Tag missing target: ${media}:${event}`);
262
- return;
263
- }
264
- try {
265
- switch (media) {
266
- case "fbq":
267
- case "meta": {
268
- const config = {
269
- platform: "meta",
270
- event: target,
271
- // target 作为事件名
272
- data: eventData
273
- };
274
- track(config);
275
- break;
276
- }
277
- case "gtag": {
278
- const config = {
279
- platform: "gtag",
280
- eventName: "conversion",
281
- send_to: target,
282
- // target 作为转化目标ID
283
- value: eventData?.value ?? 1,
284
- currency: eventData?.currency,
285
- transactionId: eventData?.transactionId
286
- };
287
- track(config);
288
- break;
289
- }
290
- default:
291
- logger.warn(`Unsupported media platform: ${media}`);
292
- }
293
- } catch (error) {
294
- logger.error(`Failed to track tag ${media}:${event}:${target}:`, error);
295
- }
296
- }
297
- __name(handleTagTracking, "handleTagTracking");
298
- function trackByTags({ tags, data }) {
299
- if (!tags || tags.length === 0) {
300
- logger.warn("trackByTags: tags array is empty");
301
- return;
302
- }
303
- if (!data || data.length === 0) {
304
- logger.warn("trackByTags: data array is empty");
305
- return;
306
- }
307
- const adaptedTags = [...tags];
308
- adaptEventName(adaptedTags);
309
- data.forEach((trackData) => {
310
- const eventSymbol = trackData.event?.toLowerCase();
311
- if (!eventSymbol) {
312
- logger.warn("trackByTags: event symbol is missing in trackData");
313
- return;
314
- }
315
- const matchedTags = filterTagsByEvent(adaptedTags, eventSymbol);
316
- if (matchedTags.length === 0) {
317
- logger.log(`trackByTags: No tags found for event: ${eventSymbol}`);
318
- return;
319
- }
320
- const { event, ...eventData } = trackData;
321
- matchedTags.forEach((tag) => {
322
- const parsed = parseTag(tag);
323
- if (!parsed) {
324
- logger.warn(`trackByTags: Invalid tag format: ${tag}`);
325
- return;
326
- }
327
- handleTagTracking(parsed, eventData);
328
- });
329
- });
330
- }
331
- __name(trackByTags, "trackByTags");
332
-
333
451
  // src/core/tracking/with-tracking.ts
334
452
  function executeTracking(trackPoint, trackConfig) {
335
453
  const configs = Array.isArray(trackConfig) ? trackConfig : [trackConfig ?? {}];
@@ -634,13 +752,18 @@ export {
634
752
  MetaPixel_default as MetaPixel,
635
753
  PixelsManager_default as PixelsManager,
636
754
  TrackTagsVersionMap,
755
+ clearTrackTags,
637
756
  index_default as default,
638
757
  gtagTrack,
758
+ hasTrackPoint,
639
759
  isPlatformAvailable,
640
760
  logger,
641
761
  metaTrack,
762
+ setTrackTags,
642
763
  track,
643
764
  trackByTags,
765
+ triggerTrack,
766
+ triggerTrackBatch,
644
767
  updateScriptType,
645
768
  updateScriptsType,
646
769
  useTracking,