@aranova/tracking-next 0.14.0 → 0.14.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.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +54 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -14
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/phone.js.map +1 -1
- package/dist/phone.mjs.map +1 -1
- package/dist/{sales-BsJodmh0.d.mts → sales-Bq7H-Vym.d.mts} +14 -5
- package/dist/{sales-BsJodmh0.d.ts → sales-Bq7H-Vym.d.ts} +14 -5
- package/dist/sales.d.mts +1 -1
- package/dist/sales.d.ts +1 -1
- package/dist/sales.js.map +1 -1
- package/dist/sales.mjs.map +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -497,19 +497,32 @@ function resolveConversionConfig(options) {
|
|
|
497
497
|
let current = cached?.config ?? options.baked ?? null;
|
|
498
498
|
let etag = cached?.etag ?? null;
|
|
499
499
|
const goalsByKey = /* @__PURE__ */ new Map();
|
|
500
|
+
const resolveListeners = /* @__PURE__ */ new Set();
|
|
500
501
|
function rebuildIndex() {
|
|
501
502
|
goalsByKey.clear();
|
|
502
503
|
for (const goal of current?.goals ?? []) {
|
|
503
504
|
goalsByKey.set(goal.key, goal);
|
|
504
505
|
}
|
|
505
506
|
}
|
|
507
|
+
function notifyResolved() {
|
|
508
|
+
const listeners = [...resolveListeners];
|
|
509
|
+
resolveListeners.clear();
|
|
510
|
+
for (const listener of listeners) {
|
|
511
|
+
try {
|
|
512
|
+
listener();
|
|
513
|
+
} catch {
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
506
517
|
function adopt(next, nextEtag) {
|
|
507
518
|
if (!next) return;
|
|
508
519
|
if (current && next.config_version <= current.config_version) return;
|
|
520
|
+
const wasEmpty = current === null;
|
|
509
521
|
current = next;
|
|
510
522
|
etag = nextEtag;
|
|
511
523
|
rebuildIndex();
|
|
512
524
|
writeCache(options.cdnUrl, { etag, config: next });
|
|
525
|
+
if (wasEmpty) notifyResolved();
|
|
513
526
|
}
|
|
514
527
|
async function revalidate() {
|
|
515
528
|
if (typeof window === "undefined") return;
|
|
@@ -534,6 +547,16 @@ function resolveConversionConfig(options) {
|
|
|
534
547
|
getGoal: (key) => goalsByKey.get(key) ?? null,
|
|
535
548
|
listGoals: () => [...goalsByKey.values()],
|
|
536
549
|
current: () => current,
|
|
550
|
+
isReady: () => current !== null,
|
|
551
|
+
onResolve: (listener) => {
|
|
552
|
+
if (current !== null) {
|
|
553
|
+
listener();
|
|
554
|
+
return () => {
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
resolveListeners.add(listener);
|
|
558
|
+
return () => resolveListeners.delete(listener);
|
|
559
|
+
},
|
|
537
560
|
revalidate
|
|
538
561
|
};
|
|
539
562
|
}
|
|
@@ -595,22 +618,39 @@ function thresholdMet(goal, eventType, metadata) {
|
|
|
595
618
|
function currentPath() {
|
|
596
619
|
return typeof window === "undefined" ? "" : window.location.pathname;
|
|
597
620
|
}
|
|
621
|
+
var MAX_BUFFERED_EVENTS = 50;
|
|
598
622
|
function createConversionAutoFire(store) {
|
|
623
|
+
const pending = [];
|
|
624
|
+
let subscribed = false;
|
|
625
|
+
function fireMatching(eventType, metadata) {
|
|
626
|
+
for (const goal of store.listGoals()) {
|
|
627
|
+
if (goal.kind !== "event" || !goal.firing) continue;
|
|
628
|
+
if (!thresholdMet(goal, eventType, metadata)) continue;
|
|
629
|
+
const firing = goal.firing;
|
|
630
|
+
const cents = firing.value_cents ?? null;
|
|
631
|
+
const currency = firing.currency ?? null;
|
|
632
|
+
fireConversionWithConsent({
|
|
633
|
+
sendTo: firing.send_to,
|
|
634
|
+
value: cents != null && currency ? fromMinor(cents, currency) : null,
|
|
635
|
+
currency,
|
|
636
|
+
// Page-scoped txn id → fire once per (goal, path) per session; engagement conversions
|
|
637
|
+
// shouldn't re-fire as the visitor scrolls back and forth or re-enters a page.
|
|
638
|
+
transactionId: `auto:${goal.key}:${currentPath()}`
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
}
|
|
599
642
|
return {
|
|
600
643
|
onAutomaticEvent(eventType, metadata) {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
// Page-scoped txn id → fire once per (goal, path) per session; engagement conversions
|
|
612
|
-
// shouldn't re-fire as the visitor scrolls back and forth or re-enters a page.
|
|
613
|
-
transactionId: `auto:${goal.key}:${currentPath()}`
|
|
644
|
+
if (store.isReady()) {
|
|
645
|
+
fireMatching(eventType, metadata);
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
if (pending.length < MAX_BUFFERED_EVENTS) pending.push({ eventType, metadata });
|
|
649
|
+
if (!subscribed) {
|
|
650
|
+
subscribed = true;
|
|
651
|
+
store.onResolve(() => {
|
|
652
|
+
const buffered = pending.splice(0);
|
|
653
|
+
for (const event of buffered) fireMatching(event.eventType, event.metadata);
|
|
614
654
|
});
|
|
615
655
|
}
|
|
616
656
|
}
|
|
@@ -2164,7 +2204,7 @@ function GoogleAdsTracking(props) {
|
|
|
2164
2204
|
import { usePathname, useSearchParams } from "next/navigation";
|
|
2165
2205
|
|
|
2166
2206
|
// package.json
|
|
2167
|
-
var version = "0.14.
|
|
2207
|
+
var version = "0.14.2";
|
|
2168
2208
|
|
|
2169
2209
|
// src/factory.tsx
|
|
2170
2210
|
import { createContext as createContext2, useContext as useContext2, useEffect as useEffect3, useMemo as useMemo2, useRef } from "react";
|