@jwiedeman/gtm-kit 1.2.0 → 1.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.js CHANGED
@@ -668,9 +668,11 @@ var ScriptManager = class {
668
668
  delay
669
669
  });
670
670
  this.retryCounters.set(containerId, currentAttempt + 1);
671
- setTimeout(() => {
671
+ const timerId = setTimeout(() => {
672
+ this.activeTimeouts.delete(containerId);
672
673
  this.loadScript(container, targetParent);
673
674
  }, delay);
675
+ this.activeTimeouts.set(containerId, timerId);
674
676
  }
675
677
  /**
676
678
  * Handle final failure after all retries exhausted.
@@ -729,6 +731,11 @@ var ScriptManager = class {
729
731
  const stringValue = String(value);
730
732
  if (key === "nonce") {
731
733
  script.nonce = stringValue;
734
+ continue;
735
+ }
736
+ const lowerKey = key.toLowerCase();
737
+ if (lowerKey === "src" || lowerKey.startsWith("on")) {
738
+ continue;
732
739
  }
733
740
  script.setAttribute(key, stringValue);
734
741
  }
@@ -808,11 +815,9 @@ var ScriptManager = class {
808
815
  this.insertedScripts.delete(script);
809
816
  this.scheduleRetry(container, targetParent);
810
817
  } else {
811
- settle("failed");
812
- const state = this.loadStates.get(containerId);
813
- if (state) {
814
- state.error = `Script load timeout (${this.scriptTimeout}ms)`;
815
- }
818
+ settled = true;
819
+ this.clearContainerTimeout(containerId);
820
+ this.handleFinalFailure(containerId, url, `Script load timeout (${this.scriptTimeout}ms)`, true);
816
821
  }
817
822
  }
818
823
  }, this.scriptTimeout);
@@ -1191,6 +1196,7 @@ var GtmClientImpl = class {
1191
1196
  this.logger.debug("GTM client already initialized; skipping.");
1192
1197
  return;
1193
1198
  }
1199
+ this.initialized = true;
1194
1200
  this.logger.info("Initializing GTM client.", {
1195
1201
  containers: this.containers.map((container) => container.id),
1196
1202
  dataLayerName: this.resolvedDataLayerName
@@ -1233,7 +1239,6 @@ var GtmClientImpl = class {
1233
1239
  this.pushStartEvent();
1234
1240
  this.flushQueue();
1235
1241
  this.scriptManager.ensure(this.containers);
1236
- this.initialized = true;
1237
1242
  }
1238
1243
  /**
1239
1244
  * Pushes a value to the GTM dataLayer.
@@ -1300,9 +1305,8 @@ var GtmClientImpl = class {
1300
1305
  }
1301
1306
  setConsentDefaults(state, options) {
1302
1307
  if (this.initialized) {
1303
- this.logger.warn(
1304
- "setConsentDefaults() called after init(). Consent defaults should be set BEFORE calling init() to ensure proper tag behavior. The defaults will still be pushed, but GTM may have already fired tags with implied consent.",
1305
- { state, options }
1308
+ throw new Error(
1309
+ "setConsentDefaults() must be called BEFORE init(). Google requires consent defaults to be set before GTM loads to ensure proper tag behavior. Move your setConsentDefaults() call before client.init()."
1306
1310
  );
1307
1311
  }
1308
1312
  if ((options == null ? void 0 : options.waitForUpdate) !== void 0) {
@@ -1691,7 +1695,7 @@ var GtmClientImpl = class {
1691
1695
  criticalIndices.add(i);
1692
1696
  }
1693
1697
  }
1694
- const targetTrimCount = Math.max(1, excess + 1);
1698
+ const targetTrimCount = Math.max(1, excess);
1695
1699
  let trimmedCount = 0;
1696
1700
  let index = 0;
1697
1701
  while (trimmedCount < targetTrimCount && index < dataLayer.length) {