@aranova/tracking-react 0.24.1 → 0.25.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/client.d.mts +366 -0
- package/dist/client.d.ts +366 -0
- package/dist/client.js +3710 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +3680 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +9 -1726
- package/dist/index.d.ts +9 -1726
- package/dist/index.js +17 -2041
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -2034
- package/dist/index.mjs.map +1 -1
- package/dist/ingest-typed-BioxtBJD.d.mts +1365 -0
- package/dist/ingest-typed-C-SPiigr.d.ts +1365 -0
- package/dist/{phone-utils-B6TYgiYT.d.mts → phone-utils-BVzSNBf1.d.mts} +1 -1
- package/dist/{phone-utils-B6TYgiYT.d.ts → phone-utils-BVzSNBf1.d.ts} +1 -1
- package/dist/phone.d.mts +1 -1
- package/dist/phone.d.ts +1 -1
- package/dist/{sales-BwWnvl8L.d.mts → sales-BIij04IG.d.ts} +2 -190
- package/dist/{sales-BwWnvl8L.d.ts → sales-C3B0BOBQ.d.mts} +2 -190
- package/dist/sales.d.mts +2 -1
- package/dist/sales.d.ts +2 -1
- package/dist/tracking-config-runtime-BnUlS_Ae.d.mts +190 -0
- package/dist/tracking-config-runtime-BnUlS_Ae.d.ts +190 -0
- package/package.json +18 -1
package/dist/index.js
CHANGED
|
@@ -20,22 +20,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
-
AdPlatformTracking: () => AdPlatformTracking,
|
|
23
|
+
AdPlatformTracking: () => import_client.AdPlatformTracking,
|
|
24
24
|
AranovaApiError: () => AranovaApiError,
|
|
25
|
-
ConsentBanner: () => ConsentBanner,
|
|
25
|
+
ConsentBanner: () => import_client.ConsentBanner,
|
|
26
26
|
DEFAULT_DECLINE_TTL_DAYS: () => DEFAULT_DECLINE_TTL_DAYS,
|
|
27
27
|
DEFAULT_PHONE_COUNTRY: () => DEFAULT_PHONE_COUNTRY,
|
|
28
28
|
EVENT_SEMANTICS: () => EVENT_SEMANTICS,
|
|
29
|
-
GoogleAdsTracking: () => GoogleAdsTracking,
|
|
29
|
+
GoogleAdsTracking: () => import_client.GoogleAdsTracking,
|
|
30
30
|
NAMED_RANGES: () => NAMED_RANGES,
|
|
31
|
-
PhoneField: () => PhoneField,
|
|
31
|
+
PhoneField: () => import_client2.PhoneField,
|
|
32
32
|
SUPPORTED_CURRENCIES: () => SUPPORTED_CURRENCIES,
|
|
33
33
|
TRACKING_PARAM_KEYS: () => TRACKING_PARAM_KEYS,
|
|
34
34
|
TRACKING_RANGES: () => TRACKING_RANGES,
|
|
35
35
|
captureTrackingParamsFromLocation: () => captureTrackingParamsFromLocation,
|
|
36
36
|
clearStashedUserData: () => clearStashedUserData,
|
|
37
37
|
createSalesClient: () => createSalesClient,
|
|
38
|
-
createTracking: () => createTracking,
|
|
38
|
+
createTracking: () => import_client.createTracking,
|
|
39
39
|
createTrackingClientContext: () => createTrackingClientContext,
|
|
40
40
|
createTrackingEventCreatePayload: () => createTrackingEventCreatePayload,
|
|
41
41
|
createTrackingSessionUpsertPayload: () => createTrackingSessionUpsertPayload,
|
|
@@ -66,21 +66,16 @@ __export(src_exports, {
|
|
|
66
66
|
stashUserData: () => stashUserData,
|
|
67
67
|
toE164: () => toE164,
|
|
68
68
|
toMinor: () => toMinor,
|
|
69
|
-
useConsent: () => useConsent,
|
|
70
|
-
useConsentState: () => useConsentState,
|
|
71
|
-
useCookiePreferences: () => useCookiePreferences,
|
|
72
|
-
useGclid: () => useGclid,
|
|
73
|
-
usePhoneConfig: () => usePhoneConfig,
|
|
74
|
-
usePhoneField: () => usePhoneField,
|
|
75
|
-
useTrackingParams: () => useTrackingParams
|
|
69
|
+
useConsent: () => import_client.useConsent,
|
|
70
|
+
useConsentState: () => import_client.useConsentState,
|
|
71
|
+
useCookiePreferences: () => import_client.useCookiePreferences,
|
|
72
|
+
useGclid: () => import_client.useGclid,
|
|
73
|
+
usePhoneConfig: () => import_client2.usePhoneConfig,
|
|
74
|
+
usePhoneField: () => import_client2.usePhoneField,
|
|
75
|
+
useTrackingParams: () => import_client.useTrackingParams
|
|
76
76
|
});
|
|
77
77
|
module.exports = __toCommonJS(src_exports);
|
|
78
|
-
|
|
79
|
-
// src/ConsentBanner.tsx
|
|
80
|
-
var import_react2 = require("react");
|
|
81
|
-
|
|
82
|
-
// src/hooks.ts
|
|
83
|
-
var import_react = require("react");
|
|
78
|
+
var import_client = require("@aranova/tracking-react/client");
|
|
84
79
|
|
|
85
80
|
// ../tracking-core/src/phone.ts
|
|
86
81
|
var import_libphonenumber_js = require("libphonenumber-js");
|
|
@@ -124,44 +119,12 @@ function formatPhoneAsTyped(raw, country) {
|
|
|
124
119
|
|
|
125
120
|
// ../tracking-core/src/user-data.ts
|
|
126
121
|
var EMAIL_SHAPE = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;
|
|
127
|
-
var EMAIL_NAME_HINT = /e[-_]?mail/i;
|
|
128
|
-
var PHONE_NAME_HINT = /(^|[^a-z])(phone|tel|mobile|cell)/i;
|
|
129
122
|
var stash = { email: null, phoneNumber: null };
|
|
130
123
|
function normalizeEmail(raw) {
|
|
131
124
|
if (typeof raw !== "string") return null;
|
|
132
125
|
const cleaned = raw.trim().toLowerCase();
|
|
133
126
|
return EMAIL_SHAPE.test(cleaned) ? cleaned : null;
|
|
134
127
|
}
|
|
135
|
-
function fieldText(field, key) {
|
|
136
|
-
const value = field[key];
|
|
137
|
-
return typeof value === "string" ? value : "";
|
|
138
|
-
}
|
|
139
|
-
function extractUserDataFromFormFields(fields, country) {
|
|
140
|
-
const result = { email: null, phoneNumber: null };
|
|
141
|
-
if (!Array.isArray(fields)) return result;
|
|
142
|
-
const passes = [
|
|
143
|
-
(field, _hint, type) => fieldText(field, "type").toLowerCase() === type,
|
|
144
|
-
(field, hint) => hint.test(fieldText(field, "name")) || hint.test(fieldText(field, "label"))
|
|
145
|
-
];
|
|
146
|
-
for (const matches of passes) {
|
|
147
|
-
for (const raw of fields) {
|
|
148
|
-
if (raw === null || typeof raw !== "object") continue;
|
|
149
|
-
const field = raw;
|
|
150
|
-
if (typeof field.value !== "string" || field.value.length === 0) continue;
|
|
151
|
-
if (result.email === null && matches(field, EMAIL_NAME_HINT, "email")) {
|
|
152
|
-
result.email = normalizeEmail(field.value);
|
|
153
|
-
}
|
|
154
|
-
if (result.phoneNumber === null && matches(field, PHONE_NAME_HINT, "tel")) {
|
|
155
|
-
try {
|
|
156
|
-
result.phoneNumber = toE164(field.value, country);
|
|
157
|
-
} catch {
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (result.email !== null && result.phoneNumber !== null) break;
|
|
162
|
-
}
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
128
|
function stashUserData(data, country) {
|
|
166
129
|
const email = normalizeEmail(data.email);
|
|
167
130
|
let phoneNumber = null;
|
|
@@ -177,16 +140,6 @@ function stashUserData(data, country) {
|
|
|
177
140
|
phoneNumber: phoneNumber ?? stash.phoneNumber
|
|
178
141
|
};
|
|
179
142
|
}
|
|
180
|
-
function stashUserDataFromFormFields(fields, country) {
|
|
181
|
-
try {
|
|
182
|
-
const extracted = extractUserDataFromFormFields(fields, country);
|
|
183
|
-
stash = {
|
|
184
|
-
email: extracted.email ?? stash.email,
|
|
185
|
-
phoneNumber: extracted.phoneNumber ?? stash.phoneNumber
|
|
186
|
-
};
|
|
187
|
-
} catch {
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
143
|
function clearStashedUserData() {
|
|
191
144
|
stash = { email: null, phoneNumber: null };
|
|
192
145
|
}
|
|
@@ -458,12 +411,6 @@ function getCookieValueFromDocument(key) {
|
|
|
458
411
|
function setTrackingCookie(key, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
|
|
459
412
|
persistCookieValue(key, value, maxAgeSeconds);
|
|
460
413
|
}
|
|
461
|
-
function mergeTrackingParams(primary, fallback) {
|
|
462
|
-
return TRACKING_PARAM_KEYS.reduce((merged, key) => {
|
|
463
|
-
merged[key] = primary[key] ?? fallback[key];
|
|
464
|
-
return merged;
|
|
465
|
-
}, createEmptyTrackingParams());
|
|
466
|
-
}
|
|
467
414
|
function persistTrackingParamsFromSearchParams(searchParams, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
|
|
468
415
|
const trackingValues = getTrackingQueryValues(searchParams);
|
|
469
416
|
Object.entries(trackingValues).forEach(([key, value]) => {
|
|
@@ -535,133 +482,16 @@ function loadGtagScript(gtagId) {
|
|
|
535
482
|
script.setAttribute(TRACKING_SCRIPT_ATTRIBUTE, marker);
|
|
536
483
|
document.head.append(script);
|
|
537
484
|
}
|
|
538
|
-
function initializeGtag(gtagId) {
|
|
539
|
-
const gtag = ensureGtagFunction();
|
|
540
|
-
gtag("js", /* @__PURE__ */ new Date());
|
|
541
|
-
gtag("config", gtagId);
|
|
542
|
-
}
|
|
543
|
-
function bootstrapGoogleAdsTracking(gtagId) {
|
|
544
|
-
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
545
|
-
if (!isValidGtagId(gtagId)) return;
|
|
546
|
-
applyDefaultConsentState();
|
|
547
|
-
loadGtagScript(gtagId);
|
|
548
|
-
initializeGtag(gtagId);
|
|
549
|
-
}
|
|
550
|
-
function bootstrapMultipleGtags(gtagIds) {
|
|
551
|
-
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
552
|
-
const ids = Object.values(gtagIds).filter(
|
|
553
|
-
(id) => typeof id === "string" && isValidGtagId(id)
|
|
554
|
-
);
|
|
555
|
-
if (ids.length === 0) return;
|
|
556
|
-
applyDefaultConsentState();
|
|
557
|
-
loadGtagScript(ids[0]);
|
|
558
|
-
const gtag = ensureGtagFunction();
|
|
559
|
-
gtag("js", /* @__PURE__ */ new Date());
|
|
560
|
-
for (const id of ids) {
|
|
561
|
-
gtag("config", id);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
485
|
|
|
565
486
|
// ../tracking-core/src/fbq.ts
|
|
566
|
-
var FB_EVENTS_SCRIPT_HOST = "https://connect.facebook.net/en_US/fbevents.js";
|
|
567
487
|
var FBC_COOKIE = "_fbc";
|
|
568
488
|
var FBP_COOKIE = "_fbp";
|
|
569
|
-
var META_PIXEL_ID_PATTERN = /^\d{15,16}$/;
|
|
570
|
-
function isValidMetaPixelId(id) {
|
|
571
|
-
return META_PIXEL_ID_PATTERN.test(id);
|
|
572
|
-
}
|
|
573
|
-
function computeFbSubdomainIndex(hostname) {
|
|
574
|
-
const labels = hostname.split(".").filter(Boolean);
|
|
575
|
-
return Math.max(0, labels.length - 1);
|
|
576
|
-
}
|
|
577
|
-
function buildFbc(fbclid, now, hostname) {
|
|
578
|
-
const host = hostname ?? (typeof window === "undefined" ? "" : window.location.hostname);
|
|
579
|
-
return `fb.${computeFbSubdomainIndex(host)}.${now}.${fbclid}`;
|
|
580
|
-
}
|
|
581
489
|
function getFbcCookie() {
|
|
582
490
|
return readCookieValue(FBC_COOKIE);
|
|
583
491
|
}
|
|
584
492
|
function getFbpCookie() {
|
|
585
493
|
return readCookieValue(FBP_COOKIE);
|
|
586
494
|
}
|
|
587
|
-
function readFbclidFromUrl() {
|
|
588
|
-
if (typeof window === "undefined") return null;
|
|
589
|
-
try {
|
|
590
|
-
const value = new URL(window.location.href).searchParams.get("fbclid");
|
|
591
|
-
return value && value.trim().length > 0 ? value : null;
|
|
592
|
-
} catch {
|
|
593
|
-
return null;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
function captureFbc(now = typeof Date === "undefined" ? 0 : Date.now()) {
|
|
597
|
-
if (typeof window === "undefined") return;
|
|
598
|
-
if (getFbcCookie()) return;
|
|
599
|
-
const fbclid = readFbclidFromUrl() ?? readCookieValue("fbclid");
|
|
600
|
-
if (!fbclid) return;
|
|
601
|
-
persistCookieValue(FBC_COOKIE, buildFbc(fbclid, now), TRACKING_COOKIE_MAX_AGE_SECONDS);
|
|
602
|
-
}
|
|
603
|
-
function getScriptMarker2(id) {
|
|
604
|
-
return `aranova-${id}`;
|
|
605
|
-
}
|
|
606
|
-
function ensureFbqFunction() {
|
|
607
|
-
const w = window;
|
|
608
|
-
if (typeof w.fbq === "function") return w.fbq;
|
|
609
|
-
const fbq = function(...args) {
|
|
610
|
-
if (fbq.callMethod) fbq.callMethod.apply(fbq, args);
|
|
611
|
-
else fbq.queue.push(args);
|
|
612
|
-
};
|
|
613
|
-
fbq.push = fbq;
|
|
614
|
-
fbq.loaded = true;
|
|
615
|
-
fbq.version = "2.0";
|
|
616
|
-
fbq.queue = [];
|
|
617
|
-
w.fbq = fbq;
|
|
618
|
-
if (!w._fbq) w._fbq = fbq;
|
|
619
|
-
return fbq;
|
|
620
|
-
}
|
|
621
|
-
function applyDefaultMetaConsentState() {
|
|
622
|
-
ensureFbqFunction()("consent", getConsentState() === "denied" ? "revoke" : "grant");
|
|
623
|
-
}
|
|
624
|
-
function loadFbeventsScript() {
|
|
625
|
-
if (typeof document === "undefined") return;
|
|
626
|
-
const marker = getScriptMarker2("fbq-loader");
|
|
627
|
-
const existing = document.querySelector(
|
|
628
|
-
`script[${TRACKING_SCRIPT_ATTRIBUTE}="${marker}"]`
|
|
629
|
-
);
|
|
630
|
-
if (existing) return;
|
|
631
|
-
const script = document.createElement("script");
|
|
632
|
-
script.async = true;
|
|
633
|
-
script.src = FB_EVENTS_SCRIPT_HOST;
|
|
634
|
-
script.setAttribute(TRACKING_SCRIPT_ATTRIBUTE, marker);
|
|
635
|
-
document.head.append(script);
|
|
636
|
-
}
|
|
637
|
-
function initializeMetaPixel(pixelId) {
|
|
638
|
-
const fbq = ensureFbqFunction();
|
|
639
|
-
fbq("init", pixelId);
|
|
640
|
-
fbq("track", "PageView");
|
|
641
|
-
}
|
|
642
|
-
function bootstrapMetaPixel(pixelId) {
|
|
643
|
-
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
644
|
-
if (!isValidMetaPixelId(pixelId)) return;
|
|
645
|
-
applyDefaultMetaConsentState();
|
|
646
|
-
loadFbeventsScript();
|
|
647
|
-
initializeMetaPixel(pixelId);
|
|
648
|
-
captureFbc();
|
|
649
|
-
}
|
|
650
|
-
function bootstrapMultiplePixels(pixelIds) {
|
|
651
|
-
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
652
|
-
const ids = Object.values(pixelIds).filter(
|
|
653
|
-
(id) => typeof id === "string" && isValidMetaPixelId(id)
|
|
654
|
-
);
|
|
655
|
-
if (ids.length === 0) return;
|
|
656
|
-
applyDefaultMetaConsentState();
|
|
657
|
-
loadFbeventsScript();
|
|
658
|
-
const fbq = ensureFbqFunction();
|
|
659
|
-
for (const id of ids) {
|
|
660
|
-
fbq("init", id);
|
|
661
|
-
}
|
|
662
|
-
fbq("track", "PageView");
|
|
663
|
-
captureFbc();
|
|
664
|
-
}
|
|
665
495
|
|
|
666
496
|
// ../tracking-core/src/landing.ts
|
|
667
497
|
var LANDING_STORAGE_KEY = "_aranova_track_landing";
|
|
@@ -936,9 +766,9 @@ function resolveConversionConfig(options) {
|
|
|
936
766
|
}
|
|
937
767
|
}
|
|
938
768
|
function notifyResolved() {
|
|
939
|
-
const
|
|
769
|
+
const listeners = [...resolveListeners];
|
|
940
770
|
resolveListeners.clear();
|
|
941
|
-
for (const listener of
|
|
771
|
+
for (const listener of listeners) {
|
|
942
772
|
try {
|
|
943
773
|
listener();
|
|
944
774
|
} catch {
|
|
@@ -1503,124 +1333,8 @@ function getTrackingConfigRuntime(ref, fetchImpl) {
|
|
|
1503
1333
|
return runtime;
|
|
1504
1334
|
}
|
|
1505
1335
|
|
|
1506
|
-
// ../tracking-core/src/resources/conversion-autofire.ts
|
|
1507
|
-
function currentPath() {
|
|
1508
|
-
return typeof window === "undefined" ? "" : window.location.pathname;
|
|
1509
|
-
}
|
|
1510
|
-
var MAX_BUFFERED_EVENTS = 50;
|
|
1511
|
-
function createConversionAutoFire(store) {
|
|
1512
|
-
const pending = [];
|
|
1513
|
-
let subscribed = false;
|
|
1514
|
-
function fireMatching(eventType, metadata, transactionScope) {
|
|
1515
|
-
for (const goal of store.listGoals()) {
|
|
1516
|
-
if (goal.kind !== "event" || !goal.firing) continue;
|
|
1517
|
-
if (!automaticThresholdMet(goal, eventType, metadata)) continue;
|
|
1518
|
-
const transactionId = getAutomaticTransactionId(transactionScope, goal.key, currentPath());
|
|
1519
|
-
if ("queueAutomaticEvent" in store) {
|
|
1520
|
-
store.fireConversion(goal.key, {
|
|
1521
|
-
transactionId
|
|
1522
|
-
});
|
|
1523
|
-
continue;
|
|
1524
|
-
}
|
|
1525
|
-
const firing = goal.firing;
|
|
1526
|
-
const cents = firing.value_cents ?? null;
|
|
1527
|
-
const currency = firing.currency ?? null;
|
|
1528
|
-
fireConversionWithConsent({
|
|
1529
|
-
sendTo: firing.send_to,
|
|
1530
|
-
value: cents != null && currency ? fromMinor(cents, currency) : null,
|
|
1531
|
-
currency,
|
|
1532
|
-
transactionId
|
|
1533
|
-
});
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
return {
|
|
1537
|
-
onAutomaticEvent(eventType, metadata, transactionScope) {
|
|
1538
|
-
if ("queueAutomaticEvent" in store) {
|
|
1539
|
-
store.queueAutomaticEvent(eventType, metadata, currentPath(), transactionScope);
|
|
1540
|
-
return;
|
|
1541
|
-
}
|
|
1542
|
-
if (store.isReady()) {
|
|
1543
|
-
fireMatching(eventType, metadata, transactionScope);
|
|
1544
|
-
return;
|
|
1545
|
-
}
|
|
1546
|
-
if (pending.length < MAX_BUFFERED_EVENTS) {
|
|
1547
|
-
pending.push({ eventType, metadata, transactionScope });
|
|
1548
|
-
}
|
|
1549
|
-
if (!subscribed) {
|
|
1550
|
-
subscribed = true;
|
|
1551
|
-
store.onResolve(() => {
|
|
1552
|
-
const buffered = pending.splice(0);
|
|
1553
|
-
for (const event of buffered) {
|
|
1554
|
-
fireMatching(event.eventType, event.metadata, event.transactionScope);
|
|
1555
|
-
}
|
|
1556
|
-
});
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1561
|
-
function withConversionAutoFire(client, autoFire) {
|
|
1562
|
-
return {
|
|
1563
|
-
...client,
|
|
1564
|
-
trackEvent: (input) => {
|
|
1565
|
-
client.trackEvent(input);
|
|
1566
|
-
try {
|
|
1567
|
-
autoFire.onAutomaticEvent(input.eventType, input.metadata ?? {}, client.getSessionId());
|
|
1568
|
-
} catch {
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
};
|
|
1572
|
-
}
|
|
1573
|
-
|
|
1574
1336
|
// ../tracking-core/src/session.ts
|
|
1575
|
-
var VISITOR_STORAGE_KEY = "aranova_tracking_visitor";
|
|
1576
|
-
var SESSION_STORAGE_KEY = "aranova_tracking_session";
|
|
1577
1337
|
var SESSION_IDLE_MS = 30 * 60 * 1e3;
|
|
1578
|
-
function safeUuid() {
|
|
1579
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function")
|
|
1580
|
-
return crypto.randomUUID();
|
|
1581
|
-
return `${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}-${Math.random().toString(16).slice(2)}`;
|
|
1582
|
-
}
|
|
1583
|
-
function readLocalStorage(key) {
|
|
1584
|
-
try {
|
|
1585
|
-
return window.localStorage.getItem(key);
|
|
1586
|
-
} catch {
|
|
1587
|
-
return null;
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
function writeLocalStorage(key, value) {
|
|
1591
|
-
try {
|
|
1592
|
-
window.localStorage.setItem(key, value);
|
|
1593
|
-
} catch {
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
function getVisitorId() {
|
|
1597
|
-
if (typeof window === "undefined") return safeUuid();
|
|
1598
|
-
const existing = readLocalStorage(VISITOR_STORAGE_KEY);
|
|
1599
|
-
if (existing && existing.length > 0) return existing;
|
|
1600
|
-
const fresh = safeUuid();
|
|
1601
|
-
writeLocalStorage(VISITOR_STORAGE_KEY, fresh);
|
|
1602
|
-
return fresh;
|
|
1603
|
-
}
|
|
1604
|
-
function getOrRotateSessionId(now = Date.now()) {
|
|
1605
|
-
if (typeof window === "undefined") return { id: safeUuid(), isNew: true };
|
|
1606
|
-
const raw = readLocalStorage(SESSION_STORAGE_KEY);
|
|
1607
|
-
if (raw) {
|
|
1608
|
-
try {
|
|
1609
|
-
const parsed = JSON.parse(raw);
|
|
1610
|
-
if (typeof parsed.id === "string" && typeof parsed.last_event_at === "number") {
|
|
1611
|
-
if (now - parsed.last_event_at <= SESSION_IDLE_MS) {
|
|
1612
|
-
const refreshed = { id: parsed.id, last_event_at: now };
|
|
1613
|
-
writeLocalStorage(SESSION_STORAGE_KEY, JSON.stringify(refreshed));
|
|
1614
|
-
return { id: parsed.id, isNew: false };
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
} catch {
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
const fresh = { id: safeUuid(), last_event_at: now };
|
|
1621
|
-
writeLocalStorage(SESSION_STORAGE_KEY, JSON.stringify(fresh));
|
|
1622
|
-
return { id: fresh.id, isNew: true };
|
|
1623
|
-
}
|
|
1624
1338
|
|
|
1625
1339
|
// ../tracking-core/src/events/page-view.ts
|
|
1626
1340
|
var import_zod = require("zod");
|
|
@@ -1642,533 +1356,12 @@ var pageViewMetadataSchema = import_zod.z.object({
|
|
|
1642
1356
|
}).strict();
|
|
1643
1357
|
var pageViewConfigSchema = import_zod.z.object({}).strict();
|
|
1644
1358
|
|
|
1645
|
-
// ../tracking-core/src/page-view.ts
|
|
1646
|
-
var LAST_FIRED_URL_STORAGE_KEY = "aranova_tracking_last_fired_url";
|
|
1647
|
-
var lastFiredUrl = null;
|
|
1648
|
-
var lastFiredUrlHydrated = false;
|
|
1649
|
-
function readSessionStorage(key) {
|
|
1650
|
-
try {
|
|
1651
|
-
if (typeof window === "undefined") return null;
|
|
1652
|
-
return window.sessionStorage.getItem(key);
|
|
1653
|
-
} catch {
|
|
1654
|
-
return null;
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
function writeSessionStorage(key, value) {
|
|
1658
|
-
try {
|
|
1659
|
-
if (typeof window === "undefined") return;
|
|
1660
|
-
window.sessionStorage.setItem(key, value);
|
|
1661
|
-
} catch {
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
function getLastFiredUrl() {
|
|
1665
|
-
if (!lastFiredUrlHydrated) {
|
|
1666
|
-
lastFiredUrlHydrated = true;
|
|
1667
|
-
const stored = readSessionStorage(LAST_FIRED_URL_STORAGE_KEY);
|
|
1668
|
-
if (stored !== null) lastFiredUrl = stored;
|
|
1669
|
-
}
|
|
1670
|
-
return lastFiredUrl;
|
|
1671
|
-
}
|
|
1672
|
-
function setLastFiredUrl(url) {
|
|
1673
|
-
lastFiredUrl = url;
|
|
1674
|
-
lastFiredUrlHydrated = true;
|
|
1675
|
-
writeSessionStorage(LAST_FIRED_URL_STORAGE_KEY, url);
|
|
1676
|
-
}
|
|
1677
|
-
function buildPageViewMetadata(referrerOverride) {
|
|
1678
|
-
if (typeof window === "undefined" || typeof document === "undefined") return null;
|
|
1679
|
-
return pageViewMetadataSchema.parse({
|
|
1680
|
-
page: {
|
|
1681
|
-
title: document.title || null,
|
|
1682
|
-
path: window.location.pathname,
|
|
1683
|
-
search: window.location.search,
|
|
1684
|
-
hash: window.location.hash
|
|
1685
|
-
},
|
|
1686
|
-
referrer: referrerOverride !== void 0 ? referrerOverride : document.referrer || null,
|
|
1687
|
-
viewport: { w: window.innerWidth, h: window.innerHeight }
|
|
1688
|
-
});
|
|
1689
|
-
}
|
|
1690
|
-
function fireManualPageView(client) {
|
|
1691
|
-
if (typeof window === "undefined") return;
|
|
1692
|
-
const currentHref = window.location.href;
|
|
1693
|
-
const previousFiredUrl = getLastFiredUrl();
|
|
1694
|
-
const internalReferrer = previousFiredUrl !== null && previousFiredUrl !== currentHref ? previousFiredUrl : null;
|
|
1695
|
-
const externalReferrer = typeof document !== "undefined" ? document.referrer || null : null;
|
|
1696
|
-
const referrer = internalReferrer ?? externalReferrer;
|
|
1697
|
-
const metadata = buildPageViewMetadata(referrer);
|
|
1698
|
-
client.trackEvent({
|
|
1699
|
-
eventType: "page_view",
|
|
1700
|
-
pageUrl: currentHref,
|
|
1701
|
-
metadata
|
|
1702
|
-
});
|
|
1703
|
-
if (currentHref !== previousFiredUrl) {
|
|
1704
|
-
setLastFiredUrl(currentHref);
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
function attachBfcacheRestore(client) {
|
|
1708
|
-
if (typeof window === "undefined") return () => {
|
|
1709
|
-
};
|
|
1710
|
-
function handlePageShow(event) {
|
|
1711
|
-
if (!event.persisted) return;
|
|
1712
|
-
fireManualPageView(client);
|
|
1713
|
-
}
|
|
1714
|
-
window.addEventListener("pageshow", handlePageShow);
|
|
1715
|
-
return () => {
|
|
1716
|
-
window.removeEventListener("pageshow", handlePageShow);
|
|
1717
|
-
};
|
|
1718
|
-
}
|
|
1719
|
-
function attachAutoPageView(client, options = {}) {
|
|
1720
|
-
if (typeof window === "undefined" || typeof history === "undefined") {
|
|
1721
|
-
return () => {
|
|
1722
|
-
};
|
|
1723
|
-
}
|
|
1724
|
-
let lastPath = window.location.pathname + window.location.search;
|
|
1725
|
-
function maybeFire() {
|
|
1726
|
-
const current = window.location.pathname + window.location.search;
|
|
1727
|
-
if (current === lastPath) return;
|
|
1728
|
-
lastPath = current;
|
|
1729
|
-
fireManualPageView(client);
|
|
1730
|
-
}
|
|
1731
|
-
const originalPushState = history.pushState.bind(history);
|
|
1732
|
-
const originalReplaceState = history.replaceState.bind(history);
|
|
1733
|
-
function patchedPushState(...args) {
|
|
1734
|
-
originalPushState(...args);
|
|
1735
|
-
setTimeout(maybeFire, 0);
|
|
1736
|
-
}
|
|
1737
|
-
function patchedReplaceState(...args) {
|
|
1738
|
-
originalReplaceState(...args);
|
|
1739
|
-
setTimeout(maybeFire, 0);
|
|
1740
|
-
}
|
|
1741
|
-
function handlePageShow(event) {
|
|
1742
|
-
if (!event.persisted) return;
|
|
1743
|
-
fireManualPageView(client);
|
|
1744
|
-
}
|
|
1745
|
-
history.pushState = patchedPushState;
|
|
1746
|
-
history.replaceState = patchedReplaceState;
|
|
1747
|
-
window.addEventListener("popstate", maybeFire);
|
|
1748
|
-
window.addEventListener("pageshow", handlePageShow);
|
|
1749
|
-
if (!options.skipInitial) fireManualPageView(client);
|
|
1750
|
-
return () => {
|
|
1751
|
-
history.pushState = originalPushState;
|
|
1752
|
-
history.replaceState = originalReplaceState;
|
|
1753
|
-
window.removeEventListener("popstate", maybeFire);
|
|
1754
|
-
window.removeEventListener("pageshow", handlePageShow);
|
|
1755
|
-
};
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
// ../tracking-core/src/heartbeat.ts
|
|
1759
|
-
function serializeValue(value) {
|
|
1760
|
-
if (value instanceof RegExp) return value.source;
|
|
1761
|
-
if (Array.isArray(value)) return value.map(serializeValue);
|
|
1762
|
-
if (value !== null && typeof value === "object") {
|
|
1763
|
-
const out = {};
|
|
1764
|
-
for (const [k, v] of Object.entries(value)) {
|
|
1765
|
-
out[k] = serializeValue(v);
|
|
1766
|
-
}
|
|
1767
|
-
return out;
|
|
1768
|
-
}
|
|
1769
|
-
return value;
|
|
1770
|
-
}
|
|
1771
|
-
function buildHeartbeatMetadata(surface, sdkVersion, packageName, triggers, gtagIds = null) {
|
|
1772
|
-
const automaticNames = triggers ? Object.keys(triggers.automatic) : [];
|
|
1773
|
-
const manualNames = triggers?.manual ? Object.keys(triggers.manual) : [];
|
|
1774
|
-
let triggerConfig = null;
|
|
1775
|
-
if (triggers) {
|
|
1776
|
-
const cfg = {};
|
|
1777
|
-
for (const [name, config] of Object.entries(triggers.automatic)) {
|
|
1778
|
-
const serialized = serializeValue(config);
|
|
1779
|
-
if (Object.keys(serialized).length > 0) {
|
|
1780
|
-
cfg[name] = serialized;
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
if (triggers.manual) {
|
|
1784
|
-
for (const [name, config] of Object.entries(triggers.manual)) {
|
|
1785
|
-
if (config === void 0) continue;
|
|
1786
|
-
const serialized = serializeValue(config);
|
|
1787
|
-
if (Object.keys(serialized).length > 0) {
|
|
1788
|
-
cfg[name] = serialized;
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
if (Object.keys(cfg).length > 0) {
|
|
1793
|
-
triggerConfig = cfg;
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
return {
|
|
1797
|
-
sdk_version: sdkVersion ?? "unknown",
|
|
1798
|
-
package_name: packageName,
|
|
1799
|
-
surface,
|
|
1800
|
-
triggers: {
|
|
1801
|
-
automatic: automaticNames,
|
|
1802
|
-
manual: manualNames
|
|
1803
|
-
},
|
|
1804
|
-
trigger_config: triggerConfig,
|
|
1805
|
-
configured_gtag_ids: gtagIds
|
|
1806
|
-
};
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
1359
|
// ../tracking-core/src/ingest.ts
|
|
1810
|
-
var DEFAULT_FLUSH_INTERVAL_MS = 2e3;
|
|
1811
|
-
var DEFAULT_MAX_QUEUE_SIZE = 10;
|
|
1812
|
-
var HARD_MAX_BATCH = 50;
|
|
1813
|
-
var MAX_RETRY_BACKOFF_MS = 6e4;
|
|
1814
|
-
var MAX_BUFFERED_EVENTS2 = 200;
|
|
1815
|
-
var RETRY_BUFFER_KEY_PREFIX = "aranova_tracking_pending_v1";
|
|
1816
1360
|
var API_KEY_HEADER = "X-Aranova-Api-Key";
|
|
1817
1361
|
var SDK_VERSION_HEADER = "X-Aranova-Sdk-Version";
|
|
1818
1362
|
var SDK_PACKAGE_HEADER = "X-Aranova-Sdk-Package";
|
|
1819
1363
|
var SDK_SURFACE_HEADER = "X-Aranova-Sdk-Surface";
|
|
1820
1364
|
var SDK_ENVIRONMENT_HEADER = "X-Aranova-Sdk-Environment";
|
|
1821
|
-
function buildContext(surface, sdkVersion, packageName, environment, activeGtagIds) {
|
|
1822
|
-
return {
|
|
1823
|
-
surface,
|
|
1824
|
-
sdk_version: sdkVersion,
|
|
1825
|
-
package_name: packageName,
|
|
1826
|
-
site_origin: typeof window === "undefined" ? null : window.location.origin,
|
|
1827
|
-
page_title: typeof document === "undefined" ? null : document.title || null,
|
|
1828
|
-
referrer: typeof document === "undefined" ? null : document.referrer || null,
|
|
1829
|
-
environment,
|
|
1830
|
-
active_gtag_ids: activeGtagIds,
|
|
1831
|
-
// Rebuilt per flush (this runs inside the payload builder), so a client
|
|
1832
|
-
// constructed later on a deeper route still gets reported.
|
|
1833
|
-
capabilities: getRegisteredCapabilities()
|
|
1834
|
-
};
|
|
1835
|
-
}
|
|
1836
|
-
function readTrackingParams() {
|
|
1837
|
-
if (typeof window === "undefined") return createEmptyTrackingParams();
|
|
1838
|
-
try {
|
|
1839
|
-
captureTrackingParamsFromLocation();
|
|
1840
|
-
} catch {
|
|
1841
|
-
}
|
|
1842
|
-
return getTrackingParamsFromCookieReader(getCookieValueFromDocument);
|
|
1843
|
-
}
|
|
1844
|
-
function consentSnapshot() {
|
|
1845
|
-
try {
|
|
1846
|
-
const choice = getConsentChoice();
|
|
1847
|
-
return {
|
|
1848
|
-
state: choice.state,
|
|
1849
|
-
source: choice.source,
|
|
1850
|
-
updated_at: choice.updatedAt,
|
|
1851
|
-
expires_at: choice.expiresAt
|
|
1852
|
-
};
|
|
1853
|
-
} catch {
|
|
1854
|
-
return null;
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
async function postWithFetch(url, body, apiKey, identity, keepalive) {
|
|
1858
|
-
if (typeof fetch !== "function") return "drop";
|
|
1859
|
-
try {
|
|
1860
|
-
const response = await fetch(url, {
|
|
1861
|
-
method: "POST",
|
|
1862
|
-
headers: {
|
|
1863
|
-
"Content-Type": "application/json",
|
|
1864
|
-
[API_KEY_HEADER]: apiKey,
|
|
1865
|
-
[SDK_VERSION_HEADER]: identity.sdkVersion,
|
|
1866
|
-
[SDK_PACKAGE_HEADER]: identity.packageName,
|
|
1867
|
-
[SDK_SURFACE_HEADER]: identity.surface,
|
|
1868
|
-
[SDK_ENVIRONMENT_HEADER]: identity.environment
|
|
1869
|
-
},
|
|
1870
|
-
body,
|
|
1871
|
-
keepalive,
|
|
1872
|
-
// CORS is open on the tracking endpoint; never send cookies.
|
|
1873
|
-
credentials: "omit",
|
|
1874
|
-
mode: "cors"
|
|
1875
|
-
});
|
|
1876
|
-
if (response.ok) return "ok";
|
|
1877
|
-
if (response.status === 408 || response.status === 429 || response.status >= 500) {
|
|
1878
|
-
return "retry";
|
|
1879
|
-
}
|
|
1880
|
-
return "drop";
|
|
1881
|
-
} catch {
|
|
1882
|
-
return "retry";
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
function retryBufferKey(apiKey, endpoint) {
|
|
1886
|
-
return `${RETRY_BUFFER_KEY_PREFIX}:${apiKey}:${endpoint}`;
|
|
1887
|
-
}
|
|
1888
|
-
function readPendingBatches(key) {
|
|
1889
|
-
if (typeof window === "undefined") return [];
|
|
1890
|
-
try {
|
|
1891
|
-
const raw = window.localStorage.getItem(key);
|
|
1892
|
-
if (!raw) return [];
|
|
1893
|
-
const parsed = JSON.parse(raw);
|
|
1894
|
-
if (!Array.isArray(parsed)) return [];
|
|
1895
|
-
return parsed.filter(
|
|
1896
|
-
(entry) => typeof entry === "object" && entry !== null && "session" in entry && Array.isArray(entry.events)
|
|
1897
|
-
);
|
|
1898
|
-
} catch {
|
|
1899
|
-
return [];
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
function writePendingBatches(key, batches) {
|
|
1903
|
-
if (typeof window === "undefined") return;
|
|
1904
|
-
try {
|
|
1905
|
-
if (batches.length === 0) window.localStorage.removeItem(key);
|
|
1906
|
-
else window.localStorage.setItem(key, JSON.stringify(batches));
|
|
1907
|
-
} catch {
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
function trimToBufferCap(batches) {
|
|
1911
|
-
let total = batches.reduce((sum, batch) => sum + batch.events.length, 0);
|
|
1912
|
-
const trimmed = batches.slice();
|
|
1913
|
-
while (total > MAX_BUFFERED_EVENTS2 && trimmed.length > 1) {
|
|
1914
|
-
const dropped = trimmed.shift();
|
|
1915
|
-
total -= dropped ? dropped.events.length : 0;
|
|
1916
|
-
}
|
|
1917
|
-
return trimmed;
|
|
1918
|
-
}
|
|
1919
|
-
var globalClient = null;
|
|
1920
|
-
var globalClientKey = null;
|
|
1921
|
-
function clientConfigKey(config) {
|
|
1922
|
-
return `${config.apiKey}@${config.endpoint}#${config.surface}`;
|
|
1923
|
-
}
|
|
1924
|
-
function getOrCreateTrackingClient(config) {
|
|
1925
|
-
const key = clientConfigKey(config);
|
|
1926
|
-
if (globalClient !== null && globalClientKey === key) {
|
|
1927
|
-
return globalClient;
|
|
1928
|
-
}
|
|
1929
|
-
if (globalClient !== null) {
|
|
1930
|
-
globalClient.destroy();
|
|
1931
|
-
}
|
|
1932
|
-
globalClient = createTrackingClient(config);
|
|
1933
|
-
globalClientKey = key;
|
|
1934
|
-
return globalClient;
|
|
1935
|
-
}
|
|
1936
|
-
var clientCaptureRegistry = /* @__PURE__ */ new WeakMap();
|
|
1937
|
-
function attachClientCapturesOnce(client, build) {
|
|
1938
|
-
let entry = clientCaptureRegistry.get(client);
|
|
1939
|
-
if (entry === void 0) {
|
|
1940
|
-
entry = { detach: build(), refCount: 0 };
|
|
1941
|
-
clientCaptureRegistry.set(client, entry);
|
|
1942
|
-
}
|
|
1943
|
-
entry.refCount += 1;
|
|
1944
|
-
let released = false;
|
|
1945
|
-
return () => {
|
|
1946
|
-
if (released) return;
|
|
1947
|
-
released = true;
|
|
1948
|
-
const current = clientCaptureRegistry.get(client);
|
|
1949
|
-
if (current === void 0) return;
|
|
1950
|
-
current.refCount -= 1;
|
|
1951
|
-
if (current.refCount <= 0) {
|
|
1952
|
-
current.detach();
|
|
1953
|
-
clientCaptureRegistry.delete(client);
|
|
1954
|
-
}
|
|
1955
|
-
};
|
|
1956
|
-
}
|
|
1957
|
-
function createTrackingClient(config) {
|
|
1958
|
-
const flushIntervalMs = config.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
|
|
1959
|
-
const maxQueueSize = Math.min(config.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE, HARD_MAX_BATCH);
|
|
1960
|
-
const sdkVersion = config.sdkVersion ?? null;
|
|
1961
|
-
const packageName = config.packageName ?? null;
|
|
1962
|
-
const environment = config.environment ?? "production";
|
|
1963
|
-
const activeGtagIds = config.activeGtagIds ?? null;
|
|
1964
|
-
const endpointBase = config.endpoint.replace(/\/$/, "");
|
|
1965
|
-
const eventsUrl = `${endpointBase}/events`;
|
|
1966
|
-
const identityHeaders2 = {
|
|
1967
|
-
sdkVersion: sdkVersion ?? "",
|
|
1968
|
-
packageName: packageName ?? "",
|
|
1969
|
-
surface: config.surface,
|
|
1970
|
-
environment
|
|
1971
|
-
};
|
|
1972
|
-
let queue = [];
|
|
1973
|
-
let flushTimer = null;
|
|
1974
|
-
const bufferKey = retryBufferKey(config.apiKey, endpointBase);
|
|
1975
|
-
let pending = readPendingBatches(bufferKey);
|
|
1976
|
-
let flushChain = Promise.resolve();
|
|
1977
|
-
let retryAttempt = 0;
|
|
1978
|
-
let firstPage = null;
|
|
1979
|
-
let initialParams = createEmptyTrackingParams();
|
|
1980
|
-
let destroyed = false;
|
|
1981
|
-
const visitorId = getVisitorId();
|
|
1982
|
-
const initialSession = getOrRotateSessionId();
|
|
1983
|
-
let sessionId = initialSession.id;
|
|
1984
|
-
if (typeof window !== "undefined") {
|
|
1985
|
-
firstPage = window.location.href;
|
|
1986
|
-
try {
|
|
1987
|
-
initialParams = captureTrackingParamsFromLocation();
|
|
1988
|
-
} catch {
|
|
1989
|
-
}
|
|
1990
|
-
getOrCaptureLandingParams(sessionId);
|
|
1991
|
-
try {
|
|
1992
|
-
captureFbc();
|
|
1993
|
-
} catch {
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
function enqueueHeartbeat() {
|
|
1997
|
-
const metadata = buildHeartbeatMetadata(
|
|
1998
|
-
config.surface,
|
|
1999
|
-
sdkVersion,
|
|
2000
|
-
packageName,
|
|
2001
|
-
config.triggers ?? null,
|
|
2002
|
-
activeGtagIds
|
|
2003
|
-
);
|
|
2004
|
-
queue.push({
|
|
2005
|
-
event_type: "sdk_heartbeat",
|
|
2006
|
-
page_url: typeof window === "undefined" ? null : window.location.href,
|
|
2007
|
-
metadata,
|
|
2008
|
-
occurred_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2009
|
-
});
|
|
2010
|
-
}
|
|
2011
|
-
if (initialSession.isNew) {
|
|
2012
|
-
enqueueHeartbeat();
|
|
2013
|
-
}
|
|
2014
|
-
if (pending.length > 0) {
|
|
2015
|
-
scheduleFlush();
|
|
2016
|
-
}
|
|
2017
|
-
function buildSessionPayload() {
|
|
2018
|
-
const rotated = getOrRotateSessionId();
|
|
2019
|
-
if (rotated.isNew && rotated.id !== sessionId) {
|
|
2020
|
-
enqueueHeartbeat();
|
|
2021
|
-
}
|
|
2022
|
-
sessionId = rotated.id;
|
|
2023
|
-
const params = mergeTrackingParams(readTrackingParams(), initialParams);
|
|
2024
|
-
const context = buildContext(
|
|
2025
|
-
config.surface,
|
|
2026
|
-
sdkVersion,
|
|
2027
|
-
packageName,
|
|
2028
|
-
environment,
|
|
2029
|
-
activeGtagIds
|
|
2030
|
-
);
|
|
2031
|
-
return {
|
|
2032
|
-
session_id: sessionId,
|
|
2033
|
-
visitor_id: visitorId,
|
|
2034
|
-
gclid: params.gclid,
|
|
2035
|
-
wbraid: params.wbraid,
|
|
2036
|
-
gbraid: params.gbraid,
|
|
2037
|
-
ylpcid: params.ylpcid,
|
|
2038
|
-
fbclid: params.fbclid,
|
|
2039
|
-
fbc: getFbcCookie(),
|
|
2040
|
-
fbp: getFbpCookie(),
|
|
2041
|
-
utm_source: params.utm_source,
|
|
2042
|
-
utm_medium: params.utm_medium,
|
|
2043
|
-
utm_campaign: params.utm_campaign,
|
|
2044
|
-
utm_term: params.utm_term,
|
|
2045
|
-
utm_content: params.utm_content,
|
|
2046
|
-
// Landing params for the CURRENT session id — captured on the spot when
|
|
2047
|
-
// the session just rotated (the current URL is the rotated session's
|
|
2048
|
-
// landing), reused from the stored record otherwise. Keys are omitted
|
|
2049
|
-
// entirely when the landing isn't observable (SSR).
|
|
2050
|
-
...buildLandingPayloadFields(sessionId),
|
|
2051
|
-
first_page: firstPage,
|
|
2052
|
-
consent_state: consentSnapshot(),
|
|
2053
|
-
context
|
|
2054
|
-
};
|
|
2055
|
-
}
|
|
2056
|
-
function scheduleFlush(delayMs = flushIntervalMs) {
|
|
2057
|
-
if (flushTimer !== null || destroyed) return;
|
|
2058
|
-
flushTimer = setTimeout(() => {
|
|
2059
|
-
flushTimer = null;
|
|
2060
|
-
void flush();
|
|
2061
|
-
}, delayMs);
|
|
2062
|
-
}
|
|
2063
|
-
function clearScheduledFlush() {
|
|
2064
|
-
if (flushTimer !== null) {
|
|
2065
|
-
clearTimeout(flushTimer);
|
|
2066
|
-
flushTimer = null;
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
function bufferQueued() {
|
|
2070
|
-
if (queue.length === 0) return;
|
|
2071
|
-
const events = queue.slice(0, HARD_MAX_BATCH);
|
|
2072
|
-
queue = queue.slice(events.length);
|
|
2073
|
-
pending = trimToBufferCap([...pending, { session: buildSessionPayload(), events }]);
|
|
2074
|
-
writePendingBatches(bufferKey, pending);
|
|
2075
|
-
}
|
|
2076
|
-
function flush() {
|
|
2077
|
-
flushChain = flushChain.then(runFlush).catch(() => {
|
|
2078
|
-
});
|
|
2079
|
-
return flushChain;
|
|
2080
|
-
}
|
|
2081
|
-
async function runFlush() {
|
|
2082
|
-
if (destroyed) return;
|
|
2083
|
-
clearScheduledFlush();
|
|
2084
|
-
bufferQueued();
|
|
2085
|
-
if (pending.length === 0) return;
|
|
2086
|
-
try {
|
|
2087
|
-
while (pending.length > 0) {
|
|
2088
|
-
const batch = pending[0];
|
|
2089
|
-
const body = { session: batch.session, events: batch.events };
|
|
2090
|
-
const outcome = await postWithFetch(
|
|
2091
|
-
eventsUrl,
|
|
2092
|
-
JSON.stringify(body),
|
|
2093
|
-
config.apiKey,
|
|
2094
|
-
identityHeaders2,
|
|
2095
|
-
false
|
|
2096
|
-
);
|
|
2097
|
-
if (outcome === "retry") {
|
|
2098
|
-
retryAttempt += 1;
|
|
2099
|
-
return;
|
|
2100
|
-
}
|
|
2101
|
-
pending = pending.slice(1);
|
|
2102
|
-
writePendingBatches(bufferKey, pending);
|
|
2103
|
-
retryAttempt = 0;
|
|
2104
|
-
}
|
|
2105
|
-
} finally {
|
|
2106
|
-
if (pending.length > 0) {
|
|
2107
|
-
const backoff = Math.min(flushIntervalMs * 2 ** retryAttempt, MAX_RETRY_BACKOFF_MS);
|
|
2108
|
-
scheduleFlush(backoff);
|
|
2109
|
-
} else if (queue.length > 0) {
|
|
2110
|
-
scheduleFlush();
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
function trackEvent(input) {
|
|
2115
|
-
if (destroyed) return;
|
|
2116
|
-
if (!input || typeof input.eventType !== "string" || input.eventType.length === 0) return;
|
|
2117
|
-
if (input.eventType === "form_submit" && getConsentState() !== "denied") {
|
|
2118
|
-
try {
|
|
2119
|
-
const fields = input.metadata?.form?.fields;
|
|
2120
|
-
if (fields) stashUserDataFromFormFields(fields, config.phone?.defaultCountry);
|
|
2121
|
-
} catch {
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2124
|
-
const occurredAt = input.occurredAt instanceof Date ? input.occurredAt.toISOString() : typeof input.occurredAt === "string" ? input.occurredAt : (/* @__PURE__ */ new Date()).toISOString();
|
|
2125
|
-
queue.push({
|
|
2126
|
-
event_type: input.eventType,
|
|
2127
|
-
page_url: input.pageUrl ?? (typeof window === "undefined" ? null : window.location.href),
|
|
2128
|
-
metadata: input.metadata ?? null,
|
|
2129
|
-
occurred_at: occurredAt
|
|
2130
|
-
});
|
|
2131
|
-
if (queue.length >= maxQueueSize) {
|
|
2132
|
-
void flush();
|
|
2133
|
-
} else {
|
|
2134
|
-
scheduleFlush();
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
function flushOnUnload() {
|
|
2138
|
-
bufferQueued();
|
|
2139
|
-
clearScheduledFlush();
|
|
2140
|
-
if (pending.length === 0) return;
|
|
2141
|
-
const batch = pending[0];
|
|
2142
|
-
pending = pending.slice(1);
|
|
2143
|
-
writePendingBatches(bufferKey, pending);
|
|
2144
|
-
const body = { session: batch.session, events: batch.events };
|
|
2145
|
-
void postWithFetch(eventsUrl, JSON.stringify(body), config.apiKey, identityHeaders2, true);
|
|
2146
|
-
}
|
|
2147
|
-
if (typeof window !== "undefined") {
|
|
2148
|
-
window.addEventListener("pagehide", flushOnUnload);
|
|
2149
|
-
window.addEventListener("visibilitychange", () => {
|
|
2150
|
-
if (document.visibilityState === "hidden") flushOnUnload();
|
|
2151
|
-
});
|
|
2152
|
-
}
|
|
2153
|
-
return {
|
|
2154
|
-
trackEvent,
|
|
2155
|
-
flush,
|
|
2156
|
-
flushBeacon: flushOnUnload,
|
|
2157
|
-
getSessionId: () => sessionId,
|
|
2158
|
-
getVisitorId: () => visitorId,
|
|
2159
|
-
destroy: () => {
|
|
2160
|
-
destroyed = true;
|
|
2161
|
-
if (queue.length > 0) {
|
|
2162
|
-
flushOnUnload();
|
|
2163
|
-
}
|
|
2164
|
-
clearScheduledFlush();
|
|
2165
|
-
queue = [];
|
|
2166
|
-
if (typeof window !== "undefined") {
|
|
2167
|
-
window.removeEventListener("pagehide", flushOnUnload);
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
|
-
};
|
|
2171
|
-
}
|
|
2172
1365
|
|
|
2173
1366
|
// ../tracking-core/src/events/cta-click.ts
|
|
2174
1367
|
var import_zod2 = require("zod");
|
|
@@ -2497,641 +1690,6 @@ var EVENT_REGISTRY = {
|
|
|
2497
1690
|
var ALL_AUTOMATIC_EVENT_NAMES = Object.entries(EVENT_REGISTRY).filter(([, def]) => def.kind === "automatic").map(([name]) => name);
|
|
2498
1691
|
var ALL_MANUAL_EVENT_NAMES = Object.entries(EVENT_REGISTRY).filter(([, def]) => def.kind === "manual").map(([name]) => name);
|
|
2499
1692
|
var ALL_LEAD_EVENT_NAMES = Object.entries(EVENT_REGISTRY).filter(([, def]) => def.semantics.outcomeRole === "lead").map(([name]) => name);
|
|
2500
|
-
function getEventDefinition(name) {
|
|
2501
|
-
return EVENT_REGISTRY[name];
|
|
2502
|
-
}
|
|
2503
|
-
|
|
2504
|
-
// ../tracking-core/src/ingest-typed.ts
|
|
2505
|
-
function createTypedClient(raw, registry, options = {}) {
|
|
2506
|
-
const debug = options.debug ?? false;
|
|
2507
|
-
if (registry.manual?.form_submit) registerCapability("form_capture");
|
|
2508
|
-
return {
|
|
2509
|
-
trackEvent(eventType, metadata, opts) {
|
|
2510
|
-
if (debug) {
|
|
2511
|
-
const def = getEventDefinition(eventType);
|
|
2512
|
-
def.metadataSchema.parse(metadata);
|
|
2513
|
-
}
|
|
2514
|
-
raw.trackEvent({
|
|
2515
|
-
eventType,
|
|
2516
|
-
metadata,
|
|
2517
|
-
pageUrl: opts?.pageUrl ?? null,
|
|
2518
|
-
occurredAt: opts?.occurredAt ?? null
|
|
2519
|
-
});
|
|
2520
|
-
},
|
|
2521
|
-
flush: raw.flush.bind(raw),
|
|
2522
|
-
getSessionId: raw.getSessionId.bind(raw),
|
|
2523
|
-
getVisitorId: raw.getVisitorId.bind(raw)
|
|
2524
|
-
};
|
|
2525
|
-
}
|
|
2526
|
-
|
|
2527
|
-
// ../tracking-core/src/triggers/time-on-site.ts
|
|
2528
|
-
function attachTimeOnSite(client, config) {
|
|
2529
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2530
|
-
return () => {
|
|
2531
|
-
};
|
|
2532
|
-
}
|
|
2533
|
-
const thresholdMs = config.thresholdSeconds * 1e3;
|
|
2534
|
-
let accumulatedMs = 0;
|
|
2535
|
-
let activeSince = document.visibilityState === "visible" ? Date.now() : null;
|
|
2536
|
-
let timer = null;
|
|
2537
|
-
let fired = false;
|
|
2538
|
-
function fire() {
|
|
2539
|
-
if (fired) return;
|
|
2540
|
-
fired = true;
|
|
2541
|
-
client.trackEvent({
|
|
2542
|
-
eventType: "time_on_site",
|
|
2543
|
-
metadata: {
|
|
2544
|
-
duration_ms: thresholdMs,
|
|
2545
|
-
page: { path: window.location.pathname }
|
|
2546
|
-
},
|
|
2547
|
-
pageUrl: window.location.href,
|
|
2548
|
-
occurredAt: null
|
|
2549
|
-
});
|
|
2550
|
-
}
|
|
2551
|
-
function scheduleNext() {
|
|
2552
|
-
if (fired || activeSince === null) return;
|
|
2553
|
-
const remaining = thresholdMs - accumulatedMs;
|
|
2554
|
-
if (remaining <= 0) {
|
|
2555
|
-
fire();
|
|
2556
|
-
return;
|
|
2557
|
-
}
|
|
2558
|
-
timer = setTimeout(fire, remaining);
|
|
2559
|
-
}
|
|
2560
|
-
function clearTimer() {
|
|
2561
|
-
if (timer !== null) {
|
|
2562
|
-
clearTimeout(timer);
|
|
2563
|
-
timer = null;
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
function onVisibilityChange() {
|
|
2567
|
-
if (fired) return;
|
|
2568
|
-
if (document.visibilityState === "hidden") {
|
|
2569
|
-
if (activeSince !== null) {
|
|
2570
|
-
accumulatedMs += Date.now() - activeSince;
|
|
2571
|
-
activeSince = null;
|
|
2572
|
-
}
|
|
2573
|
-
clearTimer();
|
|
2574
|
-
} else {
|
|
2575
|
-
activeSince = Date.now();
|
|
2576
|
-
scheduleNext();
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
2580
|
-
scheduleNext();
|
|
2581
|
-
return () => {
|
|
2582
|
-
clearTimer();
|
|
2583
|
-
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
2584
|
-
};
|
|
2585
|
-
}
|
|
2586
|
-
|
|
2587
|
-
// ../tracking-core/src/triggers/specific-page-visit.ts
|
|
2588
|
-
function attachSpecificPageVisit(client, config) {
|
|
2589
|
-
if (typeof window === "undefined" || typeof history === "undefined") {
|
|
2590
|
-
return () => {
|
|
2591
|
-
};
|
|
2592
|
-
}
|
|
2593
|
-
const { pages } = config;
|
|
2594
|
-
const firedSet = /* @__PURE__ */ new Set();
|
|
2595
|
-
function check() {
|
|
2596
|
-
const path = window.location.pathname;
|
|
2597
|
-
for (const { name, pathPattern } of pages) {
|
|
2598
|
-
pathPattern.lastIndex = 0;
|
|
2599
|
-
if (!pathPattern.test(path)) continue;
|
|
2600
|
-
const key = `${name}:${path}`;
|
|
2601
|
-
if (firedSet.has(key)) continue;
|
|
2602
|
-
firedSet.add(key);
|
|
2603
|
-
client.trackEvent({
|
|
2604
|
-
eventType: "specific_page_visit",
|
|
2605
|
-
metadata: { page_name: name, page: { path } },
|
|
2606
|
-
pageUrl: window.location.href,
|
|
2607
|
-
occurredAt: null
|
|
2608
|
-
});
|
|
2609
|
-
}
|
|
2610
|
-
}
|
|
2611
|
-
const originalPushState = history.pushState.bind(history);
|
|
2612
|
-
const originalReplaceState = history.replaceState.bind(history);
|
|
2613
|
-
function patchedPushState(...args) {
|
|
2614
|
-
originalPushState(...args);
|
|
2615
|
-
setTimeout(check, 0);
|
|
2616
|
-
}
|
|
2617
|
-
function patchedReplaceState(...args) {
|
|
2618
|
-
originalReplaceState(...args);
|
|
2619
|
-
setTimeout(check, 0);
|
|
2620
|
-
}
|
|
2621
|
-
history.pushState = patchedPushState;
|
|
2622
|
-
history.replaceState = patchedReplaceState;
|
|
2623
|
-
window.addEventListener("popstate", check);
|
|
2624
|
-
check();
|
|
2625
|
-
return () => {
|
|
2626
|
-
history.pushState = originalPushState;
|
|
2627
|
-
history.replaceState = originalReplaceState;
|
|
2628
|
-
window.removeEventListener("popstate", check);
|
|
2629
|
-
};
|
|
2630
|
-
}
|
|
2631
|
-
|
|
2632
|
-
// ../tracking-core/src/triggers/navigation.ts
|
|
2633
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
2634
|
-
var restorePatch = null;
|
|
2635
|
-
function notify() {
|
|
2636
|
-
for (const listener of listeners) listener();
|
|
2637
|
-
}
|
|
2638
|
-
function notifyDeferred() {
|
|
2639
|
-
setTimeout(notify, 0);
|
|
2640
|
-
}
|
|
2641
|
-
function installPatch() {
|
|
2642
|
-
const originalPushState = history.pushState;
|
|
2643
|
-
const originalReplaceState = history.replaceState;
|
|
2644
|
-
function patchedPushState(...args) {
|
|
2645
|
-
originalPushState.apply(this, args);
|
|
2646
|
-
notifyDeferred();
|
|
2647
|
-
}
|
|
2648
|
-
function patchedReplaceState(...args) {
|
|
2649
|
-
originalReplaceState.apply(this, args);
|
|
2650
|
-
notifyDeferred();
|
|
2651
|
-
}
|
|
2652
|
-
history.pushState = patchedPushState;
|
|
2653
|
-
history.replaceState = patchedReplaceState;
|
|
2654
|
-
window.addEventListener("popstate", notify);
|
|
2655
|
-
restorePatch = () => {
|
|
2656
|
-
history.pushState = originalPushState;
|
|
2657
|
-
history.replaceState = originalReplaceState;
|
|
2658
|
-
window.removeEventListener("popstate", notify);
|
|
2659
|
-
restorePatch = null;
|
|
2660
|
-
};
|
|
2661
|
-
}
|
|
2662
|
-
function onHistoryChange(listener) {
|
|
2663
|
-
if (listeners.size === 0) installPatch();
|
|
2664
|
-
listeners.add(listener);
|
|
2665
|
-
return () => {
|
|
2666
|
-
if (!listeners.delete(listener)) return;
|
|
2667
|
-
if (listeners.size === 0) restorePatch?.();
|
|
2668
|
-
};
|
|
2669
|
-
}
|
|
2670
|
-
|
|
2671
|
-
// ../tracking-core/src/triggers/scroll-measurement.ts
|
|
2672
|
-
var BOTTOM_EPSILON_PX = 2;
|
|
2673
|
-
function measureScrollPercent() {
|
|
2674
|
-
const root = document.scrollingElement ?? document.documentElement;
|
|
2675
|
-
const scrollHeight = root.scrollHeight;
|
|
2676
|
-
const clientHeight = root.clientHeight;
|
|
2677
|
-
if (scrollHeight <= 0 || clientHeight <= 0) return null;
|
|
2678
|
-
if (scrollHeight <= clientHeight + BOTTOM_EPSILON_PX) return null;
|
|
2679
|
-
const maxTop = scrollHeight - clientHeight;
|
|
2680
|
-
const scrollTop = Math.min(Math.max(root.scrollTop, 0), maxTop);
|
|
2681
|
-
if (scrollTop + clientHeight >= scrollHeight - BOTTOM_EPSILON_PX) return 100;
|
|
2682
|
-
return Math.max(1, Math.min(100, Math.round((scrollTop + clientHeight) / scrollHeight * 100)));
|
|
2683
|
-
}
|
|
2684
|
-
function scheduleBaselineSnapshot(onSnapshot) {
|
|
2685
|
-
let rafId = requestAnimationFrame(() => {
|
|
2686
|
-
rafId = requestAnimationFrame(() => {
|
|
2687
|
-
onSnapshot(measureScrollPercent());
|
|
2688
|
-
});
|
|
2689
|
-
});
|
|
2690
|
-
return () => cancelAnimationFrame(rafId);
|
|
2691
|
-
}
|
|
2692
|
-
function createBaselineGate() {
|
|
2693
|
-
let baselinePercent = null;
|
|
2694
|
-
let ready = false;
|
|
2695
|
-
let cancelSnapshot = null;
|
|
2696
|
-
return {
|
|
2697
|
-
rebaseline() {
|
|
2698
|
-
cancelSnapshot?.();
|
|
2699
|
-
ready = false;
|
|
2700
|
-
baselinePercent = null;
|
|
2701
|
-
cancelSnapshot = scheduleBaselineSnapshot((b) => {
|
|
2702
|
-
baselinePercent = b;
|
|
2703
|
-
ready = true;
|
|
2704
|
-
});
|
|
2705
|
-
},
|
|
2706
|
-
cancel() {
|
|
2707
|
-
cancelSnapshot?.();
|
|
2708
|
-
},
|
|
2709
|
-
baseline() {
|
|
2710
|
-
return ready ? baselinePercent : null;
|
|
2711
|
-
},
|
|
2712
|
-
sample() {
|
|
2713
|
-
if (!ready) return null;
|
|
2714
|
-
if (baselinePercent === null) {
|
|
2715
|
-
baselinePercent = measureScrollPercent();
|
|
2716
|
-
return null;
|
|
2717
|
-
}
|
|
2718
|
-
return measureScrollPercent();
|
|
2719
|
-
}
|
|
2720
|
-
};
|
|
2721
|
-
}
|
|
2722
|
-
|
|
2723
|
-
// ../tracking-core/src/triggers/scroll-depth.ts
|
|
2724
|
-
function attachScrollDepth(client, config) {
|
|
2725
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2726
|
-
return () => {
|
|
2727
|
-
};
|
|
2728
|
-
}
|
|
2729
|
-
const thresholds = new Set(config.thresholds);
|
|
2730
|
-
let firedForPath = /* @__PURE__ */ new Set();
|
|
2731
|
-
let currentPath2 = window.location.pathname;
|
|
2732
|
-
let rafId = null;
|
|
2733
|
-
const gate = createBaselineGate();
|
|
2734
|
-
function checkThresholds() {
|
|
2735
|
-
const percent = gate.sample();
|
|
2736
|
-
if (percent === null) return;
|
|
2737
|
-
const baseline = gate.baseline();
|
|
2738
|
-
if (baseline === null) return;
|
|
2739
|
-
for (const threshold of thresholds) {
|
|
2740
|
-
if (threshold <= baseline) continue;
|
|
2741
|
-
if (percent >= threshold && !firedForPath.has(threshold)) {
|
|
2742
|
-
firedForPath.add(threshold);
|
|
2743
|
-
client.trackEvent({
|
|
2744
|
-
eventType: "scroll_depth",
|
|
2745
|
-
metadata: {
|
|
2746
|
-
depth_percent: threshold,
|
|
2747
|
-
page: { path: currentPath2 }
|
|
2748
|
-
},
|
|
2749
|
-
pageUrl: window.location.href,
|
|
2750
|
-
occurredAt: null
|
|
2751
|
-
});
|
|
2752
|
-
}
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
function onScroll() {
|
|
2756
|
-
if (rafId !== null) return;
|
|
2757
|
-
rafId = requestAnimationFrame(() => {
|
|
2758
|
-
rafId = null;
|
|
2759
|
-
checkThresholds();
|
|
2760
|
-
});
|
|
2761
|
-
}
|
|
2762
|
-
function resetIfPathChanged() {
|
|
2763
|
-
const newPath = window.location.pathname;
|
|
2764
|
-
if (newPath === currentPath2) return;
|
|
2765
|
-
currentPath2 = newPath;
|
|
2766
|
-
firedForPath = /* @__PURE__ */ new Set();
|
|
2767
|
-
gate.rebaseline();
|
|
2768
|
-
}
|
|
2769
|
-
const unsubscribeNav = onHistoryChange(resetIfPathChanged);
|
|
2770
|
-
window.addEventListener("scroll", onScroll, { passive: true });
|
|
2771
|
-
gate.rebaseline();
|
|
2772
|
-
return () => {
|
|
2773
|
-
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
2774
|
-
gate.cancel();
|
|
2775
|
-
unsubscribeNav();
|
|
2776
|
-
window.removeEventListener("scroll", onScroll);
|
|
2777
|
-
};
|
|
2778
|
-
}
|
|
2779
|
-
|
|
2780
|
-
// ../tracking-core/src/triggers/multi-page-session.ts
|
|
2781
|
-
var STORAGE_KEY2 = "aranova_tracking_mps_paths";
|
|
2782
|
-
var SESSION_KEY = "aranova_tracking_mps_session";
|
|
2783
|
-
var FIRED_KEY = "aranova_tracking_mps_fired";
|
|
2784
|
-
function getSessionStorage() {
|
|
2785
|
-
try {
|
|
2786
|
-
return typeof window !== "undefined" ? window.sessionStorage : null;
|
|
2787
|
-
} catch {
|
|
2788
|
-
return null;
|
|
2789
|
-
}
|
|
2790
|
-
}
|
|
2791
|
-
function attachMultiPageSession(client, config) {
|
|
2792
|
-
if (typeof window === "undefined" || typeof history === "undefined") {
|
|
2793
|
-
return () => {
|
|
2794
|
-
};
|
|
2795
|
-
}
|
|
2796
|
-
const storage = getSessionStorage();
|
|
2797
|
-
if (!storage) return () => {
|
|
2798
|
-
};
|
|
2799
|
-
const { pageThreshold } = config;
|
|
2800
|
-
let lastCheckedPath = "";
|
|
2801
|
-
function getDistinctPaths() {
|
|
2802
|
-
try {
|
|
2803
|
-
const raw = storage.getItem(STORAGE_KEY2);
|
|
2804
|
-
return raw ? new Set(JSON.parse(raw)) : /* @__PURE__ */ new Set();
|
|
2805
|
-
} catch {
|
|
2806
|
-
return /* @__PURE__ */ new Set();
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
function saveDistinctPaths(paths) {
|
|
2810
|
-
try {
|
|
2811
|
-
storage.setItem(STORAGE_KEY2, JSON.stringify([...paths]));
|
|
2812
|
-
} catch {
|
|
2813
|
-
}
|
|
2814
|
-
}
|
|
2815
|
-
function resetIfSessionChanged() {
|
|
2816
|
-
const currentSession = getOrRotateSessionId().id;
|
|
2817
|
-
const storedSession = storage.getItem(SESSION_KEY);
|
|
2818
|
-
if (storedSession !== currentSession) {
|
|
2819
|
-
storage.setItem(SESSION_KEY, currentSession);
|
|
2820
|
-
storage.removeItem(STORAGE_KEY2);
|
|
2821
|
-
storage.removeItem(FIRED_KEY);
|
|
2822
|
-
}
|
|
2823
|
-
}
|
|
2824
|
-
function hasFired() {
|
|
2825
|
-
return storage.getItem(FIRED_KEY) === "1";
|
|
2826
|
-
}
|
|
2827
|
-
function check() {
|
|
2828
|
-
const currentPath2 = window.location.pathname;
|
|
2829
|
-
if (currentPath2 === lastCheckedPath) return;
|
|
2830
|
-
lastCheckedPath = currentPath2;
|
|
2831
|
-
resetIfSessionChanged();
|
|
2832
|
-
if (hasFired()) return;
|
|
2833
|
-
const paths = getDistinctPaths();
|
|
2834
|
-
paths.add(currentPath2);
|
|
2835
|
-
saveDistinctPaths(paths);
|
|
2836
|
-
if (paths.size >= pageThreshold) {
|
|
2837
|
-
storage.setItem(FIRED_KEY, "1");
|
|
2838
|
-
client.trackEvent({
|
|
2839
|
-
eventType: "multi_page_session",
|
|
2840
|
-
metadata: {
|
|
2841
|
-
page_count: paths.size,
|
|
2842
|
-
page: { path: window.location.pathname }
|
|
2843
|
-
},
|
|
2844
|
-
pageUrl: window.location.href,
|
|
2845
|
-
occurredAt: null
|
|
2846
|
-
});
|
|
2847
|
-
}
|
|
2848
|
-
}
|
|
2849
|
-
const originalPushState = history.pushState.bind(history);
|
|
2850
|
-
const originalReplaceState = history.replaceState.bind(history);
|
|
2851
|
-
function patchedPushState(...args) {
|
|
2852
|
-
originalPushState(...args);
|
|
2853
|
-
setTimeout(check, 0);
|
|
2854
|
-
}
|
|
2855
|
-
function patchedReplaceState(...args) {
|
|
2856
|
-
originalReplaceState(...args);
|
|
2857
|
-
setTimeout(check, 0);
|
|
2858
|
-
}
|
|
2859
|
-
history.pushState = patchedPushState;
|
|
2860
|
-
history.replaceState = patchedReplaceState;
|
|
2861
|
-
window.addEventListener("popstate", check);
|
|
2862
|
-
check();
|
|
2863
|
-
return () => {
|
|
2864
|
-
history.pushState = originalPushState;
|
|
2865
|
-
history.replaceState = originalReplaceState;
|
|
2866
|
-
window.removeEventListener("popstate", check);
|
|
2867
|
-
};
|
|
2868
|
-
}
|
|
2869
|
-
|
|
2870
|
-
// ../tracking-core/src/triggers/form-start.ts
|
|
2871
|
-
function attachFormStart(client, config) {
|
|
2872
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2873
|
-
return () => {
|
|
2874
|
-
};
|
|
2875
|
-
}
|
|
2876
|
-
const selector = config.selector ?? "form";
|
|
2877
|
-
let firedForms = /* @__PURE__ */ new Set();
|
|
2878
|
-
let currentPath2 = window.location.pathname;
|
|
2879
|
-
function getFormKey(form) {
|
|
2880
|
-
if (form.id) return `id:${form.id}`;
|
|
2881
|
-
const explicitAction = form.getAttribute("action");
|
|
2882
|
-
if (explicitAction) return `action:${explicitAction}`;
|
|
2883
|
-
const forms = Array.from(document.querySelectorAll(selector));
|
|
2884
|
-
return `index:${forms.indexOf(form)}`;
|
|
2885
|
-
}
|
|
2886
|
-
function onFocusIn(event) {
|
|
2887
|
-
const target = event.target;
|
|
2888
|
-
if (!(target instanceof HTMLElement)) return;
|
|
2889
|
-
const form = target.closest(selector);
|
|
2890
|
-
if (!form || form.tagName !== "FORM") return;
|
|
2891
|
-
const key = getFormKey(form);
|
|
2892
|
-
if (firedForms.has(key)) return;
|
|
2893
|
-
firedForms.add(key);
|
|
2894
|
-
client.trackEvent({
|
|
2895
|
-
eventType: "form_start",
|
|
2896
|
-
metadata: {
|
|
2897
|
-
form: {
|
|
2898
|
-
id: form.id || "",
|
|
2899
|
-
action: form.getAttribute("action") ?? null
|
|
2900
|
-
},
|
|
2901
|
-
page: { path: window.location.pathname }
|
|
2902
|
-
},
|
|
2903
|
-
pageUrl: window.location.href,
|
|
2904
|
-
occurredAt: null
|
|
2905
|
-
});
|
|
2906
|
-
}
|
|
2907
|
-
function resetIfPathChanged() {
|
|
2908
|
-
const newPath = window.location.pathname;
|
|
2909
|
-
if (newPath === currentPath2) return;
|
|
2910
|
-
currentPath2 = newPath;
|
|
2911
|
-
firedForms = /* @__PURE__ */ new Set();
|
|
2912
|
-
}
|
|
2913
|
-
const originalPushState = history.pushState.bind(history);
|
|
2914
|
-
const originalReplaceState = history.replaceState.bind(history);
|
|
2915
|
-
function patchedPushState(...args) {
|
|
2916
|
-
originalPushState(...args);
|
|
2917
|
-
setTimeout(resetIfPathChanged, 0);
|
|
2918
|
-
}
|
|
2919
|
-
function patchedReplaceState(...args) {
|
|
2920
|
-
originalReplaceState(...args);
|
|
2921
|
-
setTimeout(resetIfPathChanged, 0);
|
|
2922
|
-
}
|
|
2923
|
-
history.pushState = patchedPushState;
|
|
2924
|
-
history.replaceState = patchedReplaceState;
|
|
2925
|
-
window.addEventListener("popstate", resetIfPathChanged);
|
|
2926
|
-
document.addEventListener("focusin", onFocusIn);
|
|
2927
|
-
return () => {
|
|
2928
|
-
history.pushState = originalPushState;
|
|
2929
|
-
history.replaceState = originalReplaceState;
|
|
2930
|
-
window.removeEventListener("popstate", resetIfPathChanged);
|
|
2931
|
-
document.removeEventListener("focusin", onFocusIn);
|
|
2932
|
-
};
|
|
2933
|
-
}
|
|
2934
|
-
|
|
2935
|
-
// ../tracking-core/src/triggers/page-exit.ts
|
|
2936
|
-
var MIN_SEGMENT_MS = 50;
|
|
2937
|
-
function attachPageExit(client) {
|
|
2938
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2939
|
-
return () => {
|
|
2940
|
-
};
|
|
2941
|
-
}
|
|
2942
|
-
let currentPath2 = window.location.pathname;
|
|
2943
|
-
let activeSince = document.visibilityState === "visible" ? Date.now() : null;
|
|
2944
|
-
let accumulatedMs = 0;
|
|
2945
|
-
let maxScrollPercent = null;
|
|
2946
|
-
let rafId = null;
|
|
2947
|
-
const gate = createBaselineGate();
|
|
2948
|
-
function onScroll() {
|
|
2949
|
-
if (rafId !== null) return;
|
|
2950
|
-
rafId = requestAnimationFrame(() => {
|
|
2951
|
-
rafId = null;
|
|
2952
|
-
const percent = gate.sample();
|
|
2953
|
-
if (percent !== null && (maxScrollPercent === null || percent > maxScrollPercent)) {
|
|
2954
|
-
maxScrollPercent = percent;
|
|
2955
|
-
}
|
|
2956
|
-
});
|
|
2957
|
-
}
|
|
2958
|
-
function settledDwellMs() {
|
|
2959
|
-
let total = accumulatedMs;
|
|
2960
|
-
if (activeSince !== null) {
|
|
2961
|
-
total += Date.now() - activeSince;
|
|
2962
|
-
}
|
|
2963
|
-
return Math.max(0, Math.round(total));
|
|
2964
|
-
}
|
|
2965
|
-
function emitSegment(path, flush) {
|
|
2966
|
-
const dwell = settledDwellMs();
|
|
2967
|
-
if (dwell < MIN_SEGMENT_MS) return;
|
|
2968
|
-
client.trackEvent({
|
|
2969
|
-
eventType: "page_exit",
|
|
2970
|
-
metadata: {
|
|
2971
|
-
dwell_ms: dwell,
|
|
2972
|
-
max_scroll_percent: maxScrollPercent,
|
|
2973
|
-
// Lets the backend tell "scrolled to the bottom" apart from "the page
|
|
2974
|
-
// was barely scrollable". null = unscrollable page or the segment
|
|
2975
|
-
// ended before the post-paint snapshot landed. For pages that grew
|
|
2976
|
-
// after the snapshot this is the first-scroll position, not the
|
|
2977
|
-
// at-load fraction (see BaselineGate.baseline).
|
|
2978
|
-
scroll_baseline_percent: gate.baseline(),
|
|
2979
|
-
page: { path }
|
|
2980
|
-
},
|
|
2981
|
-
pageUrl: window.location.href,
|
|
2982
|
-
occurredAt: null
|
|
2983
|
-
});
|
|
2984
|
-
if (flush) {
|
|
2985
|
-
client.flushBeacon();
|
|
2986
|
-
}
|
|
2987
|
-
accumulatedMs = 0;
|
|
2988
|
-
activeSince = null;
|
|
2989
|
-
}
|
|
2990
|
-
function onNavigate() {
|
|
2991
|
-
const newPath = window.location.pathname;
|
|
2992
|
-
if (newPath === currentPath2) return;
|
|
2993
|
-
emitSegment(currentPath2, false);
|
|
2994
|
-
currentPath2 = newPath;
|
|
2995
|
-
maxScrollPercent = null;
|
|
2996
|
-
gate.rebaseline();
|
|
2997
|
-
accumulatedMs = 0;
|
|
2998
|
-
activeSince = document.visibilityState === "visible" ? Date.now() : null;
|
|
2999
|
-
}
|
|
3000
|
-
function onVisibilityChange() {
|
|
3001
|
-
if (document.visibilityState === "hidden") {
|
|
3002
|
-
emitSegment(currentPath2, true);
|
|
3003
|
-
} else {
|
|
3004
|
-
activeSince = Date.now();
|
|
3005
|
-
}
|
|
3006
|
-
}
|
|
3007
|
-
function onPageHide() {
|
|
3008
|
-
emitSegment(currentPath2, true);
|
|
3009
|
-
}
|
|
3010
|
-
const unsubscribeNav = onHistoryChange(onNavigate);
|
|
3011
|
-
window.addEventListener("scroll", onScroll, { passive: true });
|
|
3012
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
3013
|
-
window.addEventListener("pagehide", onPageHide);
|
|
3014
|
-
gate.rebaseline();
|
|
3015
|
-
return () => {
|
|
3016
|
-
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
3017
|
-
gate.cancel();
|
|
3018
|
-
unsubscribeNav();
|
|
3019
|
-
window.removeEventListener("scroll", onScroll);
|
|
3020
|
-
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
3021
|
-
window.removeEventListener("pagehide", onPageHide);
|
|
3022
|
-
};
|
|
3023
|
-
}
|
|
3024
|
-
|
|
3025
|
-
// ../tracking-core/src/triggers/cta-click-capture.ts
|
|
3026
|
-
var DEFAULT_CTA_SELECTOR = "[data-aranova-cta]";
|
|
3027
|
-
var CTA_NAME_MAX_LENGTH = 120;
|
|
3028
|
-
function describeElement(el) {
|
|
3029
|
-
const tag = el.tagName.toLowerCase();
|
|
3030
|
-
return el.id ? `${tag}#${el.id}` : tag;
|
|
3031
|
-
}
|
|
3032
|
-
function resolveCtaName(el) {
|
|
3033
|
-
const explicit = el.getAttribute("data-aranova-cta");
|
|
3034
|
-
if (explicit && explicit.trim().length > 0) return explicit.trim();
|
|
3035
|
-
const text = (el.textContent ?? "").trim().replaceAll(/\s+/g, " ");
|
|
3036
|
-
if (text.length > 0) return text.slice(0, CTA_NAME_MAX_LENGTH);
|
|
3037
|
-
return describeElement(el);
|
|
3038
|
-
}
|
|
3039
|
-
function attachCtaClickCapture(client, config) {
|
|
3040
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
3041
|
-
return () => {
|
|
3042
|
-
};
|
|
3043
|
-
}
|
|
3044
|
-
const autoCapture = config.autoCapture;
|
|
3045
|
-
if (!autoCapture) {
|
|
3046
|
-
return () => {
|
|
3047
|
-
};
|
|
3048
|
-
}
|
|
3049
|
-
registerCapability("cta_click_capture");
|
|
3050
|
-
const selector = autoCapture.selector ?? DEFAULT_CTA_SELECTOR;
|
|
3051
|
-
function onClick(event) {
|
|
3052
|
-
const target = event.target;
|
|
3053
|
-
if (!(target instanceof Element)) return;
|
|
3054
|
-
let matched = null;
|
|
3055
|
-
try {
|
|
3056
|
-
matched = target.closest(selector);
|
|
3057
|
-
} catch {
|
|
3058
|
-
return;
|
|
3059
|
-
}
|
|
3060
|
-
if (matched === null) return;
|
|
3061
|
-
const href = matched instanceof HTMLAnchorElement ? matched.href || null : matched.getAttribute("href");
|
|
3062
|
-
client.trackEvent({
|
|
3063
|
-
eventType: "cta_click",
|
|
3064
|
-
metadata: {
|
|
3065
|
-
cta_name: resolveCtaName(matched),
|
|
3066
|
-
page: { path: window.location.pathname },
|
|
3067
|
-
section: matched.getAttribute("data-aranova-section"),
|
|
3068
|
-
destination_url: href,
|
|
3069
|
-
href,
|
|
3070
|
-
element: describeElement(matched)
|
|
3071
|
-
},
|
|
3072
|
-
pageUrl: window.location.href,
|
|
3073
|
-
occurredAt: null
|
|
3074
|
-
});
|
|
3075
|
-
}
|
|
3076
|
-
document.addEventListener("click", onClick, true);
|
|
3077
|
-
return () => {
|
|
3078
|
-
document.removeEventListener("click", onClick, true);
|
|
3079
|
-
};
|
|
3080
|
-
}
|
|
3081
|
-
|
|
3082
|
-
// ../tracking-core/src/triggers/phone-click-capture.ts
|
|
3083
|
-
var DEFAULT_TEL_SELECTOR = 'a[href^="tel:"]';
|
|
3084
|
-
function safeDecodeURIComponent(value) {
|
|
3085
|
-
try {
|
|
3086
|
-
return decodeURIComponent(value);
|
|
3087
|
-
} catch {
|
|
3088
|
-
return value;
|
|
3089
|
-
}
|
|
3090
|
-
}
|
|
3091
|
-
function resolvePhoneNumber(el) {
|
|
3092
|
-
const href = el instanceof HTMLAnchorElement ? el.href : el.getAttribute("href") ?? "";
|
|
3093
|
-
const raw = safeDecodeURIComponent(href.replace(/^tel:/i, "").split(";")[0]).trim();
|
|
3094
|
-
return toE164(raw) ?? raw;
|
|
3095
|
-
}
|
|
3096
|
-
function attachPhoneClickCapture(client, config) {
|
|
3097
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
3098
|
-
return () => {
|
|
3099
|
-
};
|
|
3100
|
-
}
|
|
3101
|
-
const autoCapture = config.autoCapture;
|
|
3102
|
-
if (!autoCapture) {
|
|
3103
|
-
return () => {
|
|
3104
|
-
};
|
|
3105
|
-
}
|
|
3106
|
-
registerCapability("phone_click_capture");
|
|
3107
|
-
const selector = autoCapture.selector ?? DEFAULT_TEL_SELECTOR;
|
|
3108
|
-
function onClick(event) {
|
|
3109
|
-
const target = event.target;
|
|
3110
|
-
if (!(target instanceof Element)) return;
|
|
3111
|
-
let matched = null;
|
|
3112
|
-
try {
|
|
3113
|
-
matched = target.closest(selector);
|
|
3114
|
-
} catch {
|
|
3115
|
-
return;
|
|
3116
|
-
}
|
|
3117
|
-
if (matched === null) return;
|
|
3118
|
-
const metadata = {
|
|
3119
|
-
phone_number: resolvePhoneNumber(matched),
|
|
3120
|
-
page: { path: window.location.pathname },
|
|
3121
|
-
section: matched.getAttribute("data-aranova-section")
|
|
3122
|
-
};
|
|
3123
|
-
client.trackEvent({
|
|
3124
|
-
eventType: "phone_click",
|
|
3125
|
-
metadata,
|
|
3126
|
-
pageUrl: window.location.href,
|
|
3127
|
-
occurredAt: null
|
|
3128
|
-
});
|
|
3129
|
-
}
|
|
3130
|
-
document.addEventListener("click", onClick, true);
|
|
3131
|
-
return () => {
|
|
3132
|
-
document.removeEventListener("click", onClick, true);
|
|
3133
|
-
};
|
|
3134
|
-
}
|
|
3135
1693
|
|
|
3136
1694
|
// ../tracking-core/src/resources/http/errors.ts
|
|
3137
1695
|
var AranovaApiError = class extends Error {
|
|
@@ -3502,590 +2060,8 @@ function phoneField(name, raw, country) {
|
|
|
3502
2060
|
return { name, type: "phone", value: toE164(raw, country) };
|
|
3503
2061
|
}
|
|
3504
2062
|
|
|
3505
|
-
// src/
|
|
3506
|
-
|
|
3507
|
-
const [gclid, setGclid] = (0, import_react.useState)(null);
|
|
3508
|
-
(0, import_react.useEffect)(() => {
|
|
3509
|
-
setGclid(getCookieValueFromDocument("gclid"));
|
|
3510
|
-
}, []);
|
|
3511
|
-
return gclid;
|
|
3512
|
-
}
|
|
3513
|
-
function useTrackingParams() {
|
|
3514
|
-
const [trackingParams, setTrackingParams] = (0, import_react.useState)(createEmptyTrackingParams());
|
|
3515
|
-
(0, import_react.useEffect)(() => {
|
|
3516
|
-
setTrackingParams(getTrackingParamsFromCookieReader(getCookieValueFromDocument));
|
|
3517
|
-
}, []);
|
|
3518
|
-
return trackingParams;
|
|
3519
|
-
}
|
|
3520
|
-
var DEFAULT_CHOICE2 = {
|
|
3521
|
-
state: "granted",
|
|
3522
|
-
source: "default",
|
|
3523
|
-
updatedAt: null,
|
|
3524
|
-
expiresAt: null
|
|
3525
|
-
};
|
|
3526
|
-
function useCookiePreferences(options) {
|
|
3527
|
-
registerCapability("consent_controls");
|
|
3528
|
-
const [choice, setChoice] = (0, import_react.useState)(DEFAULT_CHOICE2);
|
|
3529
|
-
const ttlDays = options?.declineTtlDays;
|
|
3530
|
-
(0, import_react.useEffect)(() => {
|
|
3531
|
-
const sync = () => setChoice(getConsentChoice());
|
|
3532
|
-
sync();
|
|
3533
|
-
const handleStorage = (event) => {
|
|
3534
|
-
if (event.key === null || event.key === CONSENT_STATE_KEY || event.key === CONSENT_EXPIRES_AT_KEY || event.key === CONSENT_TIMESTAMP_KEY)
|
|
3535
|
-
sync();
|
|
3536
|
-
};
|
|
3537
|
-
window.addEventListener("storage", handleStorage);
|
|
3538
|
-
const unsubscribe = onConsentChange(sync);
|
|
3539
|
-
return () => {
|
|
3540
|
-
window.removeEventListener("storage", handleStorage);
|
|
3541
|
-
unsubscribe();
|
|
3542
|
-
};
|
|
3543
|
-
}, []);
|
|
3544
|
-
const optOutAction = (0, import_react.useCallback)(() => {
|
|
3545
|
-
optOut(ttlDays != null ? { declineTtlDays: ttlDays } : void 0);
|
|
3546
|
-
}, [ttlDays]);
|
|
3547
|
-
const optInAction = (0, import_react.useCallback)(() => {
|
|
3548
|
-
optIn();
|
|
3549
|
-
}, []);
|
|
3550
|
-
const reset = (0, import_react.useCallback)(() => {
|
|
3551
|
-
resetConsent();
|
|
3552
|
-
}, []);
|
|
3553
|
-
return {
|
|
3554
|
-
state: choice.state,
|
|
3555
|
-
source: choice.source,
|
|
3556
|
-
isDefault: choice.source === "default",
|
|
3557
|
-
isGranted: choice.state === "granted",
|
|
3558
|
-
isDenied: choice.state === "denied",
|
|
3559
|
-
updatedAt: choice.updatedAt,
|
|
3560
|
-
expiresAt: choice.expiresAt,
|
|
3561
|
-
optOut: optOutAction,
|
|
3562
|
-
optIn: optInAction,
|
|
3563
|
-
reset
|
|
3564
|
-
};
|
|
3565
|
-
}
|
|
3566
|
-
function useConsentState() {
|
|
3567
|
-
return useConsent().state;
|
|
3568
|
-
}
|
|
3569
|
-
function useConsent() {
|
|
3570
|
-
const {
|
|
3571
|
-
state,
|
|
3572
|
-
isGranted,
|
|
3573
|
-
isDenied,
|
|
3574
|
-
optIn: accept,
|
|
3575
|
-
optOut: decline,
|
|
3576
|
-
reset
|
|
3577
|
-
} = useCookiePreferences();
|
|
3578
|
-
return {
|
|
3579
|
-
state,
|
|
3580
|
-
isPending: false,
|
|
3581
|
-
isGranted,
|
|
3582
|
-
isDenied,
|
|
3583
|
-
accept,
|
|
3584
|
-
decline,
|
|
3585
|
-
reset
|
|
3586
|
-
};
|
|
3587
|
-
}
|
|
3588
|
-
|
|
3589
|
-
// src/ConsentBanner.tsx
|
|
3590
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3591
|
-
var LIGHT_THEME = {
|
|
3592
|
-
background: "#ffffff",
|
|
3593
|
-
border: "#e5e7eb",
|
|
3594
|
-
text: "#111827",
|
|
3595
|
-
mutedText: "#4b5563",
|
|
3596
|
-
acceptBg: "#111827",
|
|
3597
|
-
acceptText: "#ffffff",
|
|
3598
|
-
declineBg: "transparent",
|
|
3599
|
-
declineText: "#111827",
|
|
3600
|
-
declineBorder: "#d1d5db",
|
|
3601
|
-
shadow: "0 -4px 16px -2px rgba(15, 23, 42, 0.08), 0 -2px 6px -1px rgba(15, 23, 42, 0.04)",
|
|
3602
|
-
linkColor: "#1f2937"
|
|
3603
|
-
};
|
|
3604
|
-
var DARK_THEME = {
|
|
3605
|
-
background: "#0f172a",
|
|
3606
|
-
border: "#1e293b",
|
|
3607
|
-
text: "#f1f5f9",
|
|
3608
|
-
mutedText: "#cbd5e1",
|
|
3609
|
-
acceptBg: "#f1f5f9",
|
|
3610
|
-
acceptText: "#0f172a",
|
|
3611
|
-
declineBg: "transparent",
|
|
3612
|
-
declineText: "#f1f5f9",
|
|
3613
|
-
declineBorder: "#334155",
|
|
3614
|
-
shadow: "0 -4px 16px -2px rgba(0, 0, 0, 0.5), 0 -2px 6px -1px rgba(0, 0, 0, 0.3)",
|
|
3615
|
-
linkColor: "#e2e8f0"
|
|
3616
|
-
};
|
|
3617
|
-
function useResolvedTheme(theme) {
|
|
3618
|
-
const [prefersDark, setPrefersDark] = (0, import_react2.useState)(false);
|
|
3619
|
-
(0, import_react2.useEffect)(() => {
|
|
3620
|
-
if (theme !== "auto" || typeof window === "undefined" || !window.matchMedia) return;
|
|
3621
|
-
const mql = window.matchMedia("(prefers-color-scheme: dark)");
|
|
3622
|
-
setPrefersDark(mql.matches);
|
|
3623
|
-
const onChange = (e) => setPrefersDark(e.matches);
|
|
3624
|
-
mql.addEventListener("change", onChange);
|
|
3625
|
-
return () => mql.removeEventListener("change", onChange);
|
|
3626
|
-
}, [theme]);
|
|
3627
|
-
if (theme === "dark") return DARK_THEME;
|
|
3628
|
-
if (theme === "auto" && prefersDark) return DARK_THEME;
|
|
3629
|
-
return LIGHT_THEME;
|
|
3630
|
-
}
|
|
3631
|
-
var DEFAULT_MESSAGE = "We use cookies to understand ad performance and improve how our marketing works across visits. You can accept or decline this tracking.";
|
|
3632
|
-
function ConsentBanner({
|
|
3633
|
-
message,
|
|
3634
|
-
title,
|
|
3635
|
-
acceptLabel = "Accept",
|
|
3636
|
-
declineLabel = "Decline",
|
|
3637
|
-
policyHref,
|
|
3638
|
-
policyLabel = "Learn more",
|
|
3639
|
-
onAccept,
|
|
3640
|
-
onDecline,
|
|
3641
|
-
position = "bottom",
|
|
3642
|
-
theme = "light",
|
|
3643
|
-
className,
|
|
3644
|
-
style
|
|
3645
|
-
} = {}) {
|
|
3646
|
-
const { isPending, accept, decline } = useConsent();
|
|
3647
|
-
const tokens = useResolvedTheme(theme);
|
|
3648
|
-
const [hasMounted, setHasMounted] = (0, import_react2.useState)(false);
|
|
3649
|
-
(0, import_react2.useEffect)(() => {
|
|
3650
|
-
setHasMounted(true);
|
|
3651
|
-
}, []);
|
|
3652
|
-
if (!hasMounted || !isPending) return null;
|
|
3653
|
-
const wrapperStyle = {
|
|
3654
|
-
position: "fixed",
|
|
3655
|
-
left: 0,
|
|
3656
|
-
right: 0,
|
|
3657
|
-
[position]: 0,
|
|
3658
|
-
zIndex: 2147483640,
|
|
3659
|
-
background: tokens.background,
|
|
3660
|
-
color: tokens.text,
|
|
3661
|
-
borderTop: position === "bottom" ? `1px solid ${tokens.border}` : "none",
|
|
3662
|
-
borderBottom: position === "top" ? `1px solid ${tokens.border}` : "none",
|
|
3663
|
-
boxShadow: tokens.shadow,
|
|
3664
|
-
padding: "16px 20px",
|
|
3665
|
-
boxSizing: "border-box",
|
|
3666
|
-
animation: `${ANIMATION_NAME}-${position} 200ms ease-out`,
|
|
3667
|
-
fontFamily: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
|
|
3668
|
-
...style
|
|
3669
|
-
};
|
|
3670
|
-
const innerStyle = {
|
|
3671
|
-
maxWidth: 1100,
|
|
3672
|
-
margin: "0 auto",
|
|
3673
|
-
display: "flex",
|
|
3674
|
-
flexWrap: "wrap",
|
|
3675
|
-
gap: 16,
|
|
3676
|
-
alignItems: "center",
|
|
3677
|
-
justifyContent: "space-between"
|
|
3678
|
-
};
|
|
3679
|
-
const messageStyle = {
|
|
3680
|
-
flex: "1 1 320px",
|
|
3681
|
-
margin: 0,
|
|
3682
|
-
fontSize: 14,
|
|
3683
|
-
lineHeight: 1.5,
|
|
3684
|
-
color: tokens.mutedText
|
|
3685
|
-
};
|
|
3686
|
-
const titleStyle = {
|
|
3687
|
-
margin: "0 0 4px 0",
|
|
3688
|
-
fontSize: 14,
|
|
3689
|
-
fontWeight: 600,
|
|
3690
|
-
color: tokens.text
|
|
3691
|
-
};
|
|
3692
|
-
const actionsStyle = {
|
|
3693
|
-
display: "flex",
|
|
3694
|
-
gap: 8,
|
|
3695
|
-
flexShrink: 0
|
|
3696
|
-
};
|
|
3697
|
-
const buttonBase = {
|
|
3698
|
-
appearance: "none",
|
|
3699
|
-
fontFamily: "inherit",
|
|
3700
|
-
fontSize: 14,
|
|
3701
|
-
fontWeight: 500,
|
|
3702
|
-
padding: "8px 16px",
|
|
3703
|
-
borderRadius: 6,
|
|
3704
|
-
cursor: "pointer",
|
|
3705
|
-
border: "1px solid transparent",
|
|
3706
|
-
transition: "opacity 120ms ease"
|
|
3707
|
-
};
|
|
3708
|
-
const declineStyle = {
|
|
3709
|
-
...buttonBase,
|
|
3710
|
-
background: tokens.declineBg,
|
|
3711
|
-
color: tokens.declineText,
|
|
3712
|
-
borderColor: tokens.declineBorder
|
|
3713
|
-
};
|
|
3714
|
-
const acceptStyle = {
|
|
3715
|
-
...buttonBase,
|
|
3716
|
-
background: tokens.acceptBg,
|
|
3717
|
-
color: tokens.acceptText
|
|
3718
|
-
};
|
|
3719
|
-
const linkStyle = {
|
|
3720
|
-
color: tokens.linkColor,
|
|
3721
|
-
textDecoration: "underline",
|
|
3722
|
-
textUnderlineOffset: 2
|
|
3723
|
-
};
|
|
3724
|
-
const handleAccept = () => {
|
|
3725
|
-
accept();
|
|
3726
|
-
onAccept?.();
|
|
3727
|
-
};
|
|
3728
|
-
const handleDecline = () => {
|
|
3729
|
-
decline();
|
|
3730
|
-
onDecline?.();
|
|
3731
|
-
};
|
|
3732
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
3733
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: ANIMATION_KEYFRAMES }),
|
|
3734
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3735
|
-
"div",
|
|
3736
|
-
{
|
|
3737
|
-
role: "dialog",
|
|
3738
|
-
"aria-live": "polite",
|
|
3739
|
-
"aria-label": "Cookie consent",
|
|
3740
|
-
className,
|
|
3741
|
-
style: wrapperStyle,
|
|
3742
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: innerStyle, children: [
|
|
3743
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { flex: "1 1 320px" }, children: [
|
|
3744
|
-
title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: titleStyle, children: title }) : null,
|
|
3745
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { style: messageStyle, children: [
|
|
3746
|
-
message ?? DEFAULT_MESSAGE,
|
|
3747
|
-
policyHref ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
3748
|
-
" ",
|
|
3749
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: policyHref, style: linkStyle, children: policyLabel })
|
|
3750
|
-
] }) : null
|
|
3751
|
-
] })
|
|
3752
|
-
] }),
|
|
3753
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: actionsStyle, children: [
|
|
3754
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: handleDecline, style: declineStyle, children: declineLabel }),
|
|
3755
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: handleAccept, style: acceptStyle, children: acceptLabel })
|
|
3756
|
-
] })
|
|
3757
|
-
] })
|
|
3758
|
-
}
|
|
3759
|
-
)
|
|
3760
|
-
] });
|
|
3761
|
-
}
|
|
3762
|
-
var ANIMATION_NAME = "aranova-consent-banner";
|
|
3763
|
-
var ANIMATION_KEYFRAMES = `
|
|
3764
|
-
@keyframes ${ANIMATION_NAME}-bottom {
|
|
3765
|
-
from { transform: translateY(100%); opacity: 0; }
|
|
3766
|
-
to { transform: translateY(0); opacity: 1; }
|
|
3767
|
-
}
|
|
3768
|
-
@keyframes ${ANIMATION_NAME}-top {
|
|
3769
|
-
from { transform: translateY(-100%); opacity: 0; }
|
|
3770
|
-
to { transform: translateY(0); opacity: 1; }
|
|
3771
|
-
}
|
|
3772
|
-
`;
|
|
3773
|
-
|
|
3774
|
-
// src/AdPlatformTracking.tsx
|
|
3775
|
-
var import_react3 = require("react");
|
|
3776
|
-
function AdPlatformTracking({
|
|
3777
|
-
gtagId,
|
|
3778
|
-
gtagIds,
|
|
3779
|
-
trackingConfig,
|
|
3780
|
-
standalonePageView = false,
|
|
3781
|
-
metaPixelId,
|
|
3782
|
-
metaPixelIds
|
|
3783
|
-
}) {
|
|
3784
|
-
const trackingConfigKey2 = trackingConfig ? `${resolveTrackingConfigUrl(trackingConfig)}:${trackingConfig.businessId}:${trackingConfig.environment}` : "";
|
|
3785
|
-
const gtagIdsKey = (0, import_react3.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
|
|
3786
|
-
const metaPixelIdsKey = (0, import_react3.useMemo)(
|
|
3787
|
-
() => metaPixelIds ? JSON.stringify(metaPixelIds) : "",
|
|
3788
|
-
[metaPixelIds]
|
|
3789
|
-
);
|
|
3790
|
-
if (trackingConfig || gtagId || gtagIds && Object.keys(gtagIds).length > 0) {
|
|
3791
|
-
registerCapability("ad_tags_google");
|
|
3792
|
-
}
|
|
3793
|
-
if (metaPixelId || metaPixelIds && Object.keys(metaPixelIds).length > 0) {
|
|
3794
|
-
registerCapability("ad_tags_meta");
|
|
3795
|
-
}
|
|
3796
|
-
(0, import_react3.useEffect)(() => {
|
|
3797
|
-
if (trackingConfig) {
|
|
3798
|
-
const runtime = getTrackingConfigRuntime(trackingConfig);
|
|
3799
|
-
if (standalonePageView) runtime.queuePageView();
|
|
3800
|
-
else void runtime.revalidate();
|
|
3801
|
-
} else if (gtagIds && Object.keys(gtagIds).length > 0) {
|
|
3802
|
-
bootstrapMultipleGtags(gtagIds);
|
|
3803
|
-
} else if (gtagId) {
|
|
3804
|
-
bootstrapGoogleAdsTracking(gtagId);
|
|
3805
|
-
}
|
|
3806
|
-
}, [gtagId, gtagIdsKey, trackingConfigKey2, standalonePageView]);
|
|
3807
|
-
(0, import_react3.useEffect)(() => {
|
|
3808
|
-
if (metaPixelIds && Object.keys(metaPixelIds).length > 0) {
|
|
3809
|
-
bootstrapMultiplePixels(metaPixelIds);
|
|
3810
|
-
} else if (metaPixelId) {
|
|
3811
|
-
bootstrapMetaPixel(metaPixelId);
|
|
3812
|
-
}
|
|
3813
|
-
}, [metaPixelId, metaPixelIdsKey]);
|
|
3814
|
-
return null;
|
|
3815
|
-
}
|
|
3816
|
-
|
|
3817
|
-
// src/GoogleAdsTracking.tsx
|
|
3818
|
-
var import_react4 = require("react");
|
|
3819
|
-
function GoogleAdsTracking(props) {
|
|
3820
|
-
const { gtagId, gtagIds } = props;
|
|
3821
|
-
const gtagIdsKey = (0, import_react4.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
|
|
3822
|
-
(0, import_react4.useEffect)(() => {
|
|
3823
|
-
if (gtagIds && Object.keys(gtagIds).length > 0) {
|
|
3824
|
-
bootstrapMultipleGtags(gtagIds);
|
|
3825
|
-
} else if (gtagId) {
|
|
3826
|
-
bootstrapGoogleAdsTracking(gtagId);
|
|
3827
|
-
}
|
|
3828
|
-
}, [gtagId, gtagIdsKey]);
|
|
3829
|
-
return null;
|
|
3830
|
-
}
|
|
3831
|
-
|
|
3832
|
-
// src/factory.tsx
|
|
3833
|
-
var import_react6 = require("react");
|
|
3834
|
-
|
|
3835
|
-
// package.json
|
|
3836
|
-
var version = "0.24.1";
|
|
3837
|
-
|
|
3838
|
-
// ../tracking-core/src/phone-react.tsx
|
|
3839
|
-
var import_react5 = require("react");
|
|
3840
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
3841
|
-
var _phoneConfigContext;
|
|
3842
|
-
function phoneConfigContext() {
|
|
3843
|
-
return _phoneConfigContext ?? (_phoneConfigContext = (0, import_react5.createContext)(null));
|
|
3844
|
-
}
|
|
3845
|
-
function PhoneConfigProvider({
|
|
3846
|
-
value,
|
|
3847
|
-
children
|
|
3848
|
-
}) {
|
|
3849
|
-
const Ctx = phoneConfigContext();
|
|
3850
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Ctx.Provider, { value, children });
|
|
3851
|
-
}
|
|
3852
|
-
function usePhoneConfig() {
|
|
3853
|
-
const ctx = (0, import_react5.useContext)(phoneConfigContext());
|
|
3854
|
-
return {
|
|
3855
|
-
defaultCountry: ctx?.defaultCountry ?? DEFAULT_PHONE_COUNTRY,
|
|
3856
|
-
display: ctx?.display ?? "national"
|
|
3857
|
-
};
|
|
3858
|
-
}
|
|
3859
|
-
function usePhoneField(opts = {}) {
|
|
3860
|
-
registerCapability("phone_fields");
|
|
3861
|
-
const cfg = usePhoneConfig();
|
|
3862
|
-
const country = opts.country ?? cfg.defaultCountry;
|
|
3863
|
-
const display = opts.display ?? cfg.display;
|
|
3864
|
-
const { onValueChange } = opts;
|
|
3865
|
-
const [value, setValue] = (0, import_react5.useState)(() => formatPhoneAsTyped(opts.defaultValue ?? "", country));
|
|
3866
|
-
const [touched, setTouched] = (0, import_react5.useState)(false);
|
|
3867
|
-
const parsed = (0, import_react5.useMemo)(() => parsePhone(value, country), [value, country]);
|
|
3868
|
-
const onChange = (0, import_react5.useCallback)(
|
|
3869
|
-
(event) => {
|
|
3870
|
-
const next = formatPhoneAsTyped(event.target.value, country);
|
|
3871
|
-
setValue(next);
|
|
3872
|
-
onValueChange?.(parsePhone(next, country).e164);
|
|
3873
|
-
},
|
|
3874
|
-
[country, onValueChange]
|
|
3875
|
-
);
|
|
3876
|
-
const onBlur = (0, import_react5.useCallback)(
|
|
3877
|
-
(_event) => {
|
|
3878
|
-
setTouched(true);
|
|
3879
|
-
setValue((current) => {
|
|
3880
|
-
const p = parsePhone(current, country);
|
|
3881
|
-
return p.isValid ? formatPhone(current, display, country) : current;
|
|
3882
|
-
});
|
|
3883
|
-
},
|
|
3884
|
-
[country, display]
|
|
3885
|
-
);
|
|
3886
|
-
const error = touched && value.length > 0 && !parsed.isValid ? "Enter a valid phone number" : null;
|
|
3887
|
-
return {
|
|
3888
|
-
value,
|
|
3889
|
-
e164: parsed.e164,
|
|
3890
|
-
isValid: parsed.isValid,
|
|
3891
|
-
error,
|
|
3892
|
-
parsed,
|
|
3893
|
-
inputProps: { value, onChange, onBlur, type: "tel", inputMode: "tel", autoComplete: "tel" }
|
|
3894
|
-
};
|
|
3895
|
-
}
|
|
3896
|
-
var PhoneField = (0, import_react5.forwardRef)(function PhoneField2({ country, value, defaultValue, onChange, onE164Change, ...rest }, ref) {
|
|
3897
|
-
const cfg = usePhoneConfig();
|
|
3898
|
-
const resolvedCountry = country ?? cfg.defaultCountry;
|
|
3899
|
-
const isControlled = value !== void 0;
|
|
3900
|
-
const [internal, setInternal] = (0, import_react5.useState)(
|
|
3901
|
-
() => formatPhoneAsTyped(defaultValue ?? "", resolvedCountry)
|
|
3902
|
-
);
|
|
3903
|
-
const handleChange = (event) => {
|
|
3904
|
-
const formatted = formatPhoneAsTyped(event.target.value, resolvedCountry);
|
|
3905
|
-
event.target.value = formatted;
|
|
3906
|
-
onE164Change?.(parsePhone(formatted, resolvedCountry).e164);
|
|
3907
|
-
if (!isControlled) setInternal(formatted);
|
|
3908
|
-
onChange?.(event);
|
|
3909
|
-
};
|
|
3910
|
-
const shown = isControlled ? formatPhoneAsTyped(value, resolvedCountry) : internal;
|
|
3911
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3912
|
-
"input",
|
|
3913
|
-
{
|
|
3914
|
-
...rest,
|
|
3915
|
-
ref,
|
|
3916
|
-
type: "tel",
|
|
3917
|
-
inputMode: "tel",
|
|
3918
|
-
autoComplete: "tel",
|
|
3919
|
-
value: shown,
|
|
3920
|
-
onChange: handleChange
|
|
3921
|
-
}
|
|
3922
|
-
);
|
|
3923
|
-
});
|
|
3924
|
-
|
|
3925
|
-
// src/factory.tsx
|
|
3926
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
3927
|
-
var NOOP_CLIENT = {
|
|
3928
|
-
trackEvent: () => {
|
|
3929
|
-
},
|
|
3930
|
-
flush: async () => {
|
|
3931
|
-
},
|
|
3932
|
-
getSessionId: () => "",
|
|
3933
|
-
getVisitorId: () => ""
|
|
3934
|
-
};
|
|
3935
|
-
function createTracking(options) {
|
|
3936
|
-
const {
|
|
3937
|
-
apiKey,
|
|
3938
|
-
endpoint,
|
|
3939
|
-
triggers,
|
|
3940
|
-
environment,
|
|
3941
|
-
debug,
|
|
3942
|
-
phone,
|
|
3943
|
-
conversionConfig,
|
|
3944
|
-
trackingConfig
|
|
3945
|
-
} = options;
|
|
3946
|
-
registerCapability("base_tracking");
|
|
3947
|
-
if (trackingConfig) registerCapability("conversion_goals_auto");
|
|
3948
|
-
if (!apiKey || !endpoint) {
|
|
3949
|
-
if (apiKey || endpoint) {
|
|
3950
|
-
console.warn(
|
|
3951
|
-
"[AranovaTracking] createTracking() requires both `apiKey` and `endpoint`. Tracking is disabled for this session."
|
|
3952
|
-
);
|
|
3953
|
-
}
|
|
3954
|
-
const noopTyped = NOOP_CLIENT;
|
|
3955
|
-
return {
|
|
3956
|
-
// Still publish phone config so usePhoneField/<PhoneField> work even when
|
|
3957
|
-
// tracking is disabled (missing apiKey/endpoint).
|
|
3958
|
-
TrackingProvider: ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PhoneConfigProvider, { value: phone ?? null, children }),
|
|
3959
|
-
useTracking: () => noopTyped
|
|
3960
|
-
};
|
|
3961
|
-
}
|
|
3962
|
-
const TrackingContext = (0, import_react6.createContext)(null);
|
|
3963
|
-
function TrackingProvider({
|
|
3964
|
-
gtagId,
|
|
3965
|
-
gtagIds,
|
|
3966
|
-
metaPixelId,
|
|
3967
|
-
metaPixelIds,
|
|
3968
|
-
children
|
|
3969
|
-
}) {
|
|
3970
|
-
const gtagIdsKey = (0, import_react6.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
|
|
3971
|
-
const resolvedGtagIds = (0, import_react6.useMemo)(
|
|
3972
|
-
() => gtagIds ? Object.fromEntries(
|
|
3973
|
-
Object.entries(gtagIds).filter((e) => e[1] != null)
|
|
3974
|
-
) : gtagId ? { default: gtagId } : void 0,
|
|
3975
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- gtagIdsKey is stable proxy
|
|
3976
|
-
[gtagId, gtagIdsKey]
|
|
3977
|
-
);
|
|
3978
|
-
const rawClient = (0, import_react6.useMemo)(
|
|
3979
|
-
() => getOrCreateTrackingClient({
|
|
3980
|
-
apiKey,
|
|
3981
|
-
endpoint,
|
|
3982
|
-
surface: "react",
|
|
3983
|
-
packageName: "@aranova/tracking-react",
|
|
3984
|
-
sdkVersion: version,
|
|
3985
|
-
triggers,
|
|
3986
|
-
environment,
|
|
3987
|
-
activeGtagIds: resolvedGtagIds,
|
|
3988
|
-
debug
|
|
3989
|
-
}),
|
|
3990
|
-
[resolvedGtagIds]
|
|
3991
|
-
);
|
|
3992
|
-
const conversionStore = (0, import_react6.useMemo)(
|
|
3993
|
-
() => trackingConfig ? getTrackingConfigRuntime(trackingConfig) : conversionConfig ? resolveConversionConfig({
|
|
3994
|
-
cdnUrl: conversionConfig.cdnUrl,
|
|
3995
|
-
baked: conversionConfig.baked
|
|
3996
|
-
}) : null,
|
|
3997
|
-
[]
|
|
3998
|
-
);
|
|
3999
|
-
const conversionClient = (0, import_react6.useMemo)(
|
|
4000
|
-
() => conversionStore ? withConversionAutoFire(rawClient, createConversionAutoFire(conversionStore)) : rawClient,
|
|
4001
|
-
[rawClient, conversionStore]
|
|
4002
|
-
);
|
|
4003
|
-
const client = (0, import_react6.useMemo)(
|
|
4004
|
-
() => createTypedClient(conversionClient, triggers, { debug }),
|
|
4005
|
-
[conversionClient]
|
|
4006
|
-
);
|
|
4007
|
-
(0, import_react6.useEffect)(() => {
|
|
4008
|
-
if (trackingConfig) {
|
|
4009
|
-
getTrackingConfigRuntime(trackingConfig).start();
|
|
4010
|
-
} else if (gtagIds && Object.keys(gtagIds).length > 0) {
|
|
4011
|
-
bootstrapMultipleGtags(gtagIds);
|
|
4012
|
-
} else if (gtagId) {
|
|
4013
|
-
bootstrapGoogleAdsTracking(gtagId);
|
|
4014
|
-
}
|
|
4015
|
-
}, [gtagId, gtagIdsKey]);
|
|
4016
|
-
const metaPixelIdsKey = (0, import_react6.useMemo)(
|
|
4017
|
-
() => metaPixelIds ? JSON.stringify(metaPixelIds) : "",
|
|
4018
|
-
[metaPixelIds]
|
|
4019
|
-
);
|
|
4020
|
-
(0, import_react6.useEffect)(() => {
|
|
4021
|
-
if (metaPixelIds && Object.keys(metaPixelIds).length > 0) {
|
|
4022
|
-
bootstrapMultiplePixels(metaPixelIds);
|
|
4023
|
-
} else if (metaPixelId) {
|
|
4024
|
-
bootstrapMetaPixel(metaPixelId);
|
|
4025
|
-
}
|
|
4026
|
-
}, [metaPixelId, metaPixelIdsKey]);
|
|
4027
|
-
(0, import_react6.useEffect)(() => {
|
|
4028
|
-
return attachClientCapturesOnce(rawClient, () => {
|
|
4029
|
-
const detachers = [];
|
|
4030
|
-
const detectorClient = conversionStore ? conversionClient : rawClient;
|
|
4031
|
-
const pageClient = trackingConfig && conversionStore && "queuePageView" in conversionStore ? {
|
|
4032
|
-
...detectorClient,
|
|
4033
|
-
trackEvent: (input) => {
|
|
4034
|
-
detectorClient.trackEvent(input);
|
|
4035
|
-
if (input.eventType === "page_view") conversionStore.queuePageView();
|
|
4036
|
-
}
|
|
4037
|
-
} : detectorClient;
|
|
4038
|
-
detachers.push(attachAutoPageView(pageClient));
|
|
4039
|
-
detachers.push(attachBfcacheRestore(pageClient));
|
|
4040
|
-
detachers.push(attachPageExit(detectorClient));
|
|
4041
|
-
const timeOnSite = triggers.automatic.time_on_site;
|
|
4042
|
-
if (timeOnSite) {
|
|
4043
|
-
detachers.push(attachTimeOnSite(detectorClient, timeOnSite));
|
|
4044
|
-
}
|
|
4045
|
-
const specificPageVisit = triggers.automatic.specific_page_visit;
|
|
4046
|
-
if (specificPageVisit) {
|
|
4047
|
-
detachers.push(attachSpecificPageVisit(detectorClient, specificPageVisit));
|
|
4048
|
-
}
|
|
4049
|
-
const scrollDepth = triggers.automatic.scroll_depth;
|
|
4050
|
-
if (scrollDepth) {
|
|
4051
|
-
detachers.push(attachScrollDepth(detectorClient, scrollDepth));
|
|
4052
|
-
}
|
|
4053
|
-
const multiPageSession = triggers.automatic.multi_page_session;
|
|
4054
|
-
if (multiPageSession) {
|
|
4055
|
-
detachers.push(attachMultiPageSession(detectorClient, multiPageSession));
|
|
4056
|
-
}
|
|
4057
|
-
const formStart = triggers.automatic.form_start;
|
|
4058
|
-
if (formStart) {
|
|
4059
|
-
detachers.push(attachFormStart(detectorClient, formStart));
|
|
4060
|
-
}
|
|
4061
|
-
const ctaClick = triggers.manual?.cta_click;
|
|
4062
|
-
if (ctaClick) {
|
|
4063
|
-
detachers.push(attachCtaClickCapture(detectorClient, ctaClick));
|
|
4064
|
-
}
|
|
4065
|
-
const phoneClick = triggers.manual?.phone_click;
|
|
4066
|
-
if (phoneClick) {
|
|
4067
|
-
detachers.push(attachPhoneClickCapture(detectorClient, phoneClick));
|
|
4068
|
-
}
|
|
4069
|
-
return () => {
|
|
4070
|
-
for (let i = detachers.length - 1; i >= 0; i--) {
|
|
4071
|
-
detachers[i]();
|
|
4072
|
-
}
|
|
4073
|
-
};
|
|
4074
|
-
});
|
|
4075
|
-
}, [conversionClient, conversionStore, rawClient]);
|
|
4076
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TrackingContext.Provider, { value: client, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PhoneConfigProvider, { value: phone ?? null, children }) });
|
|
4077
|
-
}
|
|
4078
|
-
function useTracking() {
|
|
4079
|
-
const client = (0, import_react6.useContext)(TrackingContext);
|
|
4080
|
-
if (client === null) {
|
|
4081
|
-
throw new Error(
|
|
4082
|
-
"useTracking must be called inside a <TrackingProvider> returned by createTracking()"
|
|
4083
|
-
);
|
|
4084
|
-
}
|
|
4085
|
-
return client;
|
|
4086
|
-
}
|
|
4087
|
-
return { TrackingProvider, useTracking };
|
|
4088
|
-
}
|
|
2063
|
+
// src/index.ts
|
|
2064
|
+
var import_client2 = require("@aranova/tracking-react/client");
|
|
4089
2065
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4090
2066
|
0 && (module.exports = {
|
|
4091
2067
|
AdPlatformTracking,
|