@aranova/tracking-next 0.22.3 → 0.22.4

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
@@ -1022,6 +1022,9 @@ function formatMoney(cents, currency, locale) {
1022
1022
  // ../tracking-core/src/resources/tracking-config-runtime.ts
1023
1023
  var CACHE_PREFIX2 = "_aranova_cfg_runtime_";
1024
1024
  var AUTHORITY_TTL_MS = 6e4;
1025
+ var MAX_QUEUE_LENGTH = 50;
1026
+ var RETRY_BASE_MS = 5e3;
1027
+ var RETRY_MAX_MS = 5 * 6e4;
1025
1028
  var runtimes = /* @__PURE__ */ new Map();
1026
1029
  var configuredIds = /* @__PURE__ */ new Set();
1027
1030
  var scriptLoad = null;
@@ -1029,6 +1032,10 @@ var jsInitialized = false;
1029
1032
  function cacheKey2(url) {
1030
1033
  return `${CACHE_PREFIX2}${url}`;
1031
1034
  }
1035
+ function pushBounded(queue, item) {
1036
+ queue.push(item);
1037
+ if (queue.length > MAX_QUEUE_LENGTH) queue.splice(0, queue.length - MAX_QUEUE_LENGTH);
1038
+ }
1032
1039
  function readCache2(url) {
1033
1040
  if (typeof window === "undefined") return null;
1034
1041
  try {
@@ -1109,6 +1116,10 @@ var TrackingConfigRuntime = class {
1109
1116
  this.flushRequested = false;
1110
1117
  this.retryTimer = null;
1111
1118
  this.started = false;
1119
+ /** Consecutive failed authority attempts — drives the revalidate backoff. */
1120
+ this.authorityFailures = 0;
1121
+ /** Epoch ms before which `ensureAuthority` must not issue another request. */
1122
+ this.nextAuthorityAttemptAt = 0;
1112
1123
  this.conversionQueue = [];
1113
1124
  this.automaticQueue = [];
1114
1125
  this.pageQueue = [];
@@ -1147,6 +1158,15 @@ var TrackingConfigRuntime = class {
1147
1158
  }
1148
1159
  __unsafeExpireAuthorityForTests() {
1149
1160
  this.confirmedAt = Number.NEGATIVE_INFINITY;
1161
+ this.nextAuthorityAttemptAt = 0;
1162
+ }
1163
+ /** Queue depths — asserted by tests to pin the bound. */
1164
+ __queueDepthsForTests() {
1165
+ return {
1166
+ conversions: this.conversionQueue.length,
1167
+ automatic: this.automaticQueue.length,
1168
+ pages: this.pageQueue.length
1169
+ };
1150
1170
  }
1151
1171
  subscribe(listener) {
1152
1172
  this.listeners.add(listener);
@@ -1156,10 +1176,12 @@ var TrackingConfigRuntime = class {
1156
1176
  if (this.stateValue !== "unconfirmed" && Date.now() - this.confirmedAt < AUTHORITY_TTL_MS) {
1157
1177
  return true;
1158
1178
  }
1179
+ if (Date.now() < this.nextAuthorityAttemptAt) return false;
1159
1180
  await this.revalidateAuthority();
1160
1181
  return this.stateValue !== "unconfirmed" && Date.now() - this.confirmedAt < AUTHORITY_TTL_MS;
1161
1182
  }
1162
1183
  async revalidate() {
1184
+ this.nextAuthorityAttemptAt = 0;
1163
1185
  await this.revalidateAuthority();
1164
1186
  await this.flush();
1165
1187
  }
@@ -1173,15 +1195,20 @@ var TrackingConfigRuntime = class {
1173
1195
  }
1174
1196
  queuePageView(snapshot = pageViewSnapshot()) {
1175
1197
  if (!snapshot) return;
1176
- this.pageQueue.push(snapshot);
1198
+ pushBounded(this.pageQueue, snapshot);
1177
1199
  void this.flush();
1178
1200
  }
1179
1201
  fireConversion(key, options) {
1180
- this.conversionQueue.push({ key, ...options });
1202
+ pushBounded(this.conversionQueue, { key, ...options });
1181
1203
  void this.flush();
1182
1204
  }
1183
1205
  queueAutomaticEvent(eventType, metadata, transactionPath, transactionScope) {
1184
- this.automaticQueue.push({ eventType, metadata, transactionPath, transactionScope });
1206
+ pushBounded(this.automaticQueue, {
1207
+ eventType,
1208
+ metadata,
1209
+ transactionPath,
1210
+ transactionScope
1211
+ });
1185
1212
  void this.flush();
1186
1213
  }
1187
1214
  listGoals() {
@@ -1221,12 +1248,17 @@ var TrackingConfigRuntime = class {
1221
1248
  expireAuthority() {
1222
1249
  this.authorityGeneration += 1;
1223
1250
  if (this.stateValue !== "unconfirmed") this.stateValue = "unconfirmed";
1251
+ this.authorityFailures += 1;
1252
+ const delay = Math.min(RETRY_MAX_MS, RETRY_BASE_MS * 2 ** (this.authorityFailures - 1));
1253
+ this.nextAuthorityAttemptAt = Date.now() + delay;
1224
1254
  }
1225
1255
  confirm(config, etag) {
1226
1256
  this.authorityGeneration += 1;
1227
1257
  this.current = config;
1228
1258
  this.etag = etag;
1229
1259
  this.confirmedAt = Date.now();
1260
+ this.authorityFailures = 0;
1261
+ this.nextAuthorityAttemptAt = 0;
1230
1262
  this.stateValue = isTombstone(config) ? "tombstone" : "active";
1231
1263
  writeCache2(this.ref.cdnUrl, { etag, config });
1232
1264
  if (this.stateValue === "tombstone") {
@@ -1307,7 +1339,7 @@ var TrackingConfigRuntime = class {
1307
1339
  for (const goal of config.goals) {
1308
1340
  if (goal.kind !== "event" || !goal.firing) continue;
1309
1341
  if (!automaticThresholdMet(goal, event.eventType, event.metadata)) continue;
1310
- this.conversionQueue.push({
1342
+ pushBounded(this.conversionQueue, {
1311
1343
  key: goal.key,
1312
1344
  transactionId: getAutomaticTransactionId(
1313
1345
  event.transactionScope,
@@ -3520,7 +3552,7 @@ function GoogleAdsTracking(props) {
3520
3552
  import { usePathname, useSearchParams } from "next/navigation";
3521
3553
 
3522
3554
  // package.json
3523
- var version = "0.22.3";
3555
+ var version = "0.22.4";
3524
3556
 
3525
3557
  // src/factory.tsx
3526
3558
  import {