@aranova/tracking-react 0.14.0 → 0.14.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.mjs CHANGED
@@ -180,9 +180,10 @@ function isValidGtagId(id) {
180
180
  function ensureGtagFunction() {
181
181
  window.dataLayer = window.dataLayer || [];
182
182
  if (typeof window.gtag === "function") return window.gtag;
183
- window.gtag = (...args) => {
184
- window.dataLayer?.push(args);
185
- };
183
+ function gtag() {
184
+ window.dataLayer?.push(arguments);
185
+ }
186
+ window.gtag = gtag;
186
187
  return window.gtag;
187
188
  }
188
189
  var SEND_TO_RE = /^AW-[A-Za-z0-9]+\/[A-Za-z0-9_-]+$/;
@@ -560,19 +561,32 @@ function resolveConversionConfig(options) {
560
561
  let current = cached?.config ?? options.baked ?? null;
561
562
  let etag = cached?.etag ?? null;
562
563
  const goalsByKey = /* @__PURE__ */ new Map();
564
+ const resolveListeners = /* @__PURE__ */ new Set();
563
565
  function rebuildIndex() {
564
566
  goalsByKey.clear();
565
567
  for (const goal of current?.goals ?? []) {
566
568
  goalsByKey.set(goal.key, goal);
567
569
  }
568
570
  }
571
+ function notifyResolved() {
572
+ const listeners = [...resolveListeners];
573
+ resolveListeners.clear();
574
+ for (const listener of listeners) {
575
+ try {
576
+ listener();
577
+ } catch {
578
+ }
579
+ }
580
+ }
569
581
  function adopt(next, nextEtag) {
570
582
  if (!next) return;
571
583
  if (current && next.config_version <= current.config_version) return;
584
+ const wasEmpty = current === null;
572
585
  current = next;
573
586
  etag = nextEtag;
574
587
  rebuildIndex();
575
588
  writeCache(options.cdnUrl, { etag, config: next });
589
+ if (wasEmpty) notifyResolved();
576
590
  }
577
591
  async function revalidate() {
578
592
  if (typeof window === "undefined") return;
@@ -597,6 +611,16 @@ function resolveConversionConfig(options) {
597
611
  getGoal: (key) => goalsByKey.get(key) ?? null,
598
612
  listGoals: () => [...goalsByKey.values()],
599
613
  current: () => current,
614
+ isReady: () => current !== null,
615
+ onResolve: (listener) => {
616
+ if (current !== null) {
617
+ listener();
618
+ return () => {
619
+ };
620
+ }
621
+ resolveListeners.add(listener);
622
+ return () => resolveListeners.delete(listener);
623
+ },
600
624
  revalidate
601
625
  };
602
626
  }
@@ -658,22 +682,39 @@ function thresholdMet(goal, eventType, metadata) {
658
682
  function currentPath() {
659
683
  return typeof window === "undefined" ? "" : window.location.pathname;
660
684
  }
685
+ var MAX_BUFFERED_EVENTS = 50;
661
686
  function createConversionAutoFire(store) {
687
+ const pending = [];
688
+ let subscribed = false;
689
+ function fireMatching(eventType, metadata) {
690
+ for (const goal of store.listGoals()) {
691
+ if (goal.kind !== "event" || !goal.firing) continue;
692
+ if (!thresholdMet(goal, eventType, metadata)) continue;
693
+ const firing = goal.firing;
694
+ const cents = firing.value_cents ?? null;
695
+ const currency = firing.currency ?? null;
696
+ fireConversionWithConsent({
697
+ sendTo: firing.send_to,
698
+ value: cents != null && currency ? fromMinor(cents, currency) : null,
699
+ currency,
700
+ // Page-scoped txn id → fire once per (goal, path) per session; engagement conversions
701
+ // shouldn't re-fire as the visitor scrolls back and forth or re-enters a page.
702
+ transactionId: `auto:${goal.key}:${currentPath()}`
703
+ });
704
+ }
705
+ }
662
706
  return {
663
707
  onAutomaticEvent(eventType, metadata) {
664
- for (const goal of store.listGoals()) {
665
- if (goal.kind !== "event" || !goal.firing) continue;
666
- if (!thresholdMet(goal, eventType, metadata)) continue;
667
- const firing = goal.firing;
668
- const cents = firing.value_cents ?? null;
669
- const currency = firing.currency ?? null;
670
- fireConversionWithConsent({
671
- sendTo: firing.send_to,
672
- value: cents != null && currency ? fromMinor(cents, currency) : null,
673
- currency,
674
- // Page-scoped txn id → fire once per (goal, path) per session; engagement conversions
675
- // shouldn't re-fire as the visitor scrolls back and forth or re-enters a page.
676
- transactionId: `auto:${goal.key}:${currentPath()}`
708
+ if (store.isReady()) {
709
+ fireMatching(eventType, metadata);
710
+ return;
711
+ }
712
+ if (pending.length < MAX_BUFFERED_EVENTS) pending.push({ eventType, metadata });
713
+ if (!subscribed) {
714
+ subscribed = true;
715
+ store.onResolve(() => {
716
+ const buffered = pending.splice(0);
717
+ for (const event of buffered) fireMatching(event.eventType, event.metadata);
677
718
  });
678
719
  }
679
720
  }
@@ -2383,7 +2424,7 @@ function GoogleAdsTracking(props) {
2383
2424
  import { createContext as createContext2, useContext as useContext2, useEffect as useEffect5, useMemo as useMemo4 } from "react";
2384
2425
 
2385
2426
  // package.json
2386
- var version = "0.14.0";
2427
+ var version = "0.14.1";
2387
2428
 
2388
2429
  // ../tracking-core/src/phone-react.tsx
2389
2430
  import {