@aranova/tracking-next 0.22.4 → 0.23.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/dist/index.mjs CHANGED
@@ -1020,6 +1020,16 @@ function formatMoney(cents, currency, locale) {
1020
1020
  }
1021
1021
 
1022
1022
  // ../tracking-core/src/resources/tracking-config-runtime.ts
1023
+ var DEFAULT_CDN_BASE_URL = "https://demos.aranova.io";
1024
+ function trackingConfigKey(businessId, environment) {
1025
+ return `tracking-config/v1/${businessId}-${environment}.json`;
1026
+ }
1027
+ function resolveTrackingConfigUrl(ref) {
1028
+ if (ref.cdnUrl) return ref.cdnUrl;
1029
+ const configured = ref.cdnBaseUrl?.trim();
1030
+ const base = (configured || DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
1031
+ return `${base}/${trackingConfigKey(ref.businessId, ref.environment)}`;
1032
+ }
1023
1033
  var CACHE_PREFIX2 = "_aranova_cfg_runtime_";
1024
1034
  var AUTHORITY_TTL_MS = 6e4;
1025
1035
  var MAX_QUEUE_LENGTH = 50;
@@ -1125,11 +1135,16 @@ var TrackingConfigRuntime = class {
1125
1135
  this.pageQueue = [];
1126
1136
  this.listeners = /* @__PURE__ */ new Set();
1127
1137
  this.fetchImpl = fetchImpl.bind(globalThis);
1128
- const cached = readCache2(ref.cdnUrl);
1138
+ this.url = resolveTrackingConfigUrl(ref);
1139
+ const cached = readCache2(this.url);
1129
1140
  this.current = cached?.config ?? null;
1130
1141
  this.etag = cached?.etag ?? null;
1131
1142
  this.start();
1132
1143
  }
1144
+ /** The URL this runtime actually fetches (composed or explicit). */
1145
+ configUrl() {
1146
+ return this.url;
1147
+ }
1133
1148
  /**
1134
1149
  * Explicitly start authority resolution and Google-tag bootstrap.
1135
1150
  *
@@ -1218,7 +1233,7 @@ var TrackingConfigRuntime = class {
1218
1233
  try {
1219
1234
  const headers = {};
1220
1235
  if (this.etag) headers["If-None-Match"] = this.etag;
1221
- const response = await this.fetchImpl(this.ref.cdnUrl, {
1236
+ const response = await this.fetchImpl(this.url, {
1222
1237
  method: "GET",
1223
1238
  headers,
1224
1239
  cache: "no-cache"
@@ -1260,7 +1275,7 @@ var TrackingConfigRuntime = class {
1260
1275
  this.authorityFailures = 0;
1261
1276
  this.nextAuthorityAttemptAt = 0;
1262
1277
  this.stateValue = isTombstone(config) ? "tombstone" : "active";
1263
- writeCache2(this.ref.cdnUrl, { etag, config });
1278
+ writeCache2(this.url, { etag, config });
1264
1279
  if (this.stateValue === "tombstone") {
1265
1280
  if (this.retryTimer !== null) {
1266
1281
  window.clearTimeout(this.retryTimer);
@@ -1375,7 +1390,7 @@ var TrackingConfigRuntime = class {
1375
1390
  }
1376
1391
  };
1377
1392
  function getTrackingConfigRuntime(ref, fetchImpl) {
1378
- const key = `${ref.cdnUrl}|${ref.businessId}|${ref.environment}`;
1393
+ const key = `${resolveTrackingConfigUrl(ref)}|${ref.businessId}|${ref.environment}`;
1379
1394
  const existing = runtimes.get(key);
1380
1395
  if (existing) return existing;
1381
1396
  const runtime = new TrackingConfigRuntime(ref, fetchImpl ?? globalThis.fetch);
@@ -3493,13 +3508,13 @@ function AdPlatformTracking({
3493
3508
  metaPixelId,
3494
3509
  metaPixelIds
3495
3510
  }) {
3496
- const trackingConfigKey = trackingConfig ? `${trackingConfig.cdnUrl}:${trackingConfig.businessId}:${trackingConfig.environment}` : "";
3511
+ const trackingConfigKey2 = trackingConfig ? `${resolveTrackingConfigUrl(trackingConfig)}:${trackingConfig.businessId}:${trackingConfig.environment}` : "";
3497
3512
  useEffect3(() => {
3498
3513
  if (!trackingConfig) return;
3499
3514
  const runtime = getTrackingConfigRuntime(trackingConfig);
3500
3515
  if (standalonePageView) runtime.queuePageView();
3501
3516
  else runtime.start();
3502
- }, [trackingConfigKey, standalonePageView]);
3517
+ }, [trackingConfigKey2, standalonePageView]);
3503
3518
  const gtagAll = trackingConfig ? [] : gtagIds ? Object.values(gtagIds).filter((id) => id != null) : gtagId ? [gtagId] : [];
3504
3519
  const metaAll = metaPixelIds ? Object.values(metaPixelIds).filter((id) => id != null) : metaPixelId ? [metaPixelId] : [];
3505
3520
  if (trackingConfig || gtagAll.length > 0) registerCapability("ad_tags_google");
@@ -3552,7 +3567,7 @@ function GoogleAdsTracking(props) {
3552
3567
  import { usePathname, useSearchParams } from "next/navigation";
3553
3568
 
3554
3569
  // package.json
3555
- var version = "0.22.4";
3570
+ var version = "0.23.0";
3556
3571
 
3557
3572
  // src/factory.tsx
3558
3573
  import {
@@ -4335,6 +4350,7 @@ export {
4335
4350
  resetConsent,
4336
4351
  resolveBrowserTimeZone,
4337
4352
  resolveConversionConfig,
4353
+ resolveTrackingConfigUrl,
4338
4354
  saleCreateSchema,
4339
4355
  saleItemSchema,
4340
4356
  saleServiceSchema,