@founderhq/journeys 0.8.1 → 1.0.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/_tsup-dts-rollup.d.cts +156 -1
- package/dist/_tsup-dts-rollup.d.ts +156 -1
- package/dist/index.cjs +337 -44
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +330 -45
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17,6 +17,110 @@ import * as SliderPrimitive from '@radix-ui/react-slider';
|
|
|
17
17
|
import { DotLottieReact } from '@lottiefiles/dotlottie-react';
|
|
18
18
|
import useEmblaCarousel from 'embla-carousel-react';
|
|
19
19
|
|
|
20
|
+
// src/lib/web-fonts.ts
|
|
21
|
+
var FONT_VARIABLE = "--jy-font-family";
|
|
22
|
+
var BUILT_IN_FAMILIES = /* @__PURE__ */ new Set([
|
|
23
|
+
"inter",
|
|
24
|
+
"inter variable",
|
|
25
|
+
"lora",
|
|
26
|
+
"lora variable",
|
|
27
|
+
"google sans",
|
|
28
|
+
"product sans",
|
|
29
|
+
"serif",
|
|
30
|
+
"sans-serif",
|
|
31
|
+
"monospace",
|
|
32
|
+
"cursive",
|
|
33
|
+
"fantasy",
|
|
34
|
+
"system-ui",
|
|
35
|
+
"ui-serif",
|
|
36
|
+
"ui-sans-serif",
|
|
37
|
+
"ui-monospace",
|
|
38
|
+
"ui-rounded",
|
|
39
|
+
"math",
|
|
40
|
+
"emoji",
|
|
41
|
+
"inherit",
|
|
42
|
+
"initial",
|
|
43
|
+
"unset",
|
|
44
|
+
"georgia",
|
|
45
|
+
"times new roman",
|
|
46
|
+
"arial",
|
|
47
|
+
"helvetica",
|
|
48
|
+
"helvetica neue",
|
|
49
|
+
"courier new",
|
|
50
|
+
"segoe ui",
|
|
51
|
+
"sf pro text",
|
|
52
|
+
"blinkmacsystemfont",
|
|
53
|
+
"-apple-system"
|
|
54
|
+
]);
|
|
55
|
+
var FAMILY_NAME = /^[A-Za-z0-9][A-Za-z0-9 ]{0,62}$/;
|
|
56
|
+
function firstFontFamily(stack) {
|
|
57
|
+
var _a;
|
|
58
|
+
const first = (_a = stack == null ? void 0 : stack.split(",", 1)[0]) == null ? void 0 : _a.trim();
|
|
59
|
+
if (!first) return void 0;
|
|
60
|
+
const name = first.replace(/^(['"])(.*)\1$/, "$2").trim();
|
|
61
|
+
return name || void 0;
|
|
62
|
+
}
|
|
63
|
+
function isWebFontFamily(family) {
|
|
64
|
+
if (!family) return false;
|
|
65
|
+
if (!FAMILY_NAME.test(family)) return false;
|
|
66
|
+
return !BUILT_IN_FAMILIES.has(family.toLowerCase());
|
|
67
|
+
}
|
|
68
|
+
function collectFontFamilies(value, found) {
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
for (const item of value) collectFontFamilies(item, found);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!value || typeof value !== "object") return;
|
|
74
|
+
for (const [key, child] of Object.entries(value)) {
|
|
75
|
+
if (key === "fontFamily" && typeof child === "string") {
|
|
76
|
+
const family = firstFontFamily(child);
|
|
77
|
+
if (isWebFontFamily(family)) found.add(family);
|
|
78
|
+
} else {
|
|
79
|
+
collectFontFamilies(child, found);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function getJourneyWebFontFamilies(config) {
|
|
84
|
+
var _a;
|
|
85
|
+
const found = /* @__PURE__ */ new Set();
|
|
86
|
+
const journeyFont = firstFontFamily((_a = config.themeVariables) == null ? void 0 : _a[FONT_VARIABLE]);
|
|
87
|
+
if (isWebFontFamily(journeyFont)) found.add(journeyFont);
|
|
88
|
+
collectFontFamilies(config.steps, found);
|
|
89
|
+
const byName = /* @__PURE__ */ new Map();
|
|
90
|
+
for (const family of found) {
|
|
91
|
+
const key = family.toLowerCase();
|
|
92
|
+
if (!byName.has(key)) byName.set(key, family);
|
|
93
|
+
}
|
|
94
|
+
return [...byName.values()].sort((a, b) => a.localeCompare(b));
|
|
95
|
+
}
|
|
96
|
+
function getWebFontStylesheetUrl(family) {
|
|
97
|
+
const name = family.trim().toLowerCase().replace(/\s+/g, "-");
|
|
98
|
+
return `https://fonts.bunny.net/css?family=${encodeURIComponent(name)}:300,300i,400,400i,500,500i,600,600i,700,700i,800,900&display=swap`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/engine/use-journey-web-fonts.ts
|
|
102
|
+
var LINK_MARK = "data-journey-web-font";
|
|
103
|
+
function useJourneyWebFonts(config) {
|
|
104
|
+
const families = useMemo(() => getJourneyWebFontFamilies(config), [config]);
|
|
105
|
+
const signature = families.join("|");
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
var _a;
|
|
108
|
+
if (typeof document === "undefined" || !signature) return;
|
|
109
|
+
for (const family of signature.split("|")) {
|
|
110
|
+
const key = family.toLowerCase();
|
|
111
|
+
if (document.head.querySelector(`link[${LINK_MARK}="${key}"]`)) continue;
|
|
112
|
+
const onPage = [...(_a = document.fonts) != null ? _a : []].some(
|
|
113
|
+
(face) => face.family.replace(/^(['"])(.*)\1$/, "$2").toLowerCase() === key
|
|
114
|
+
);
|
|
115
|
+
if (onPage) continue;
|
|
116
|
+
const link = document.createElement("link");
|
|
117
|
+
link.rel = "stylesheet";
|
|
118
|
+
link.href = getWebFontStylesheetUrl(family);
|
|
119
|
+
link.setAttribute(LINK_MARK, key);
|
|
120
|
+
document.head.append(link);
|
|
121
|
+
}
|
|
122
|
+
}, [signature]);
|
|
123
|
+
}
|
|
20
124
|
var JourneyPresentationContext = createContext(true);
|
|
21
125
|
function useJourneyPresented() {
|
|
22
126
|
return useContext(JourneyPresentationContext);
|
|
@@ -633,6 +737,7 @@ function useJourneyProviderRuntime({
|
|
|
633
737
|
() => getComputedVariableIds(config.computedVariables),
|
|
634
738
|
[config.computedVariables]
|
|
635
739
|
);
|
|
740
|
+
useJourneyWebFonts(config);
|
|
636
741
|
const providerThemeStyle = useMemo(() => {
|
|
637
742
|
const themeVariables = config.themeVariables ? Object.fromEntries(
|
|
638
743
|
Object.entries(config.themeVariables).filter(
|
|
@@ -2609,7 +2714,7 @@ function resolveJourneyFontFamily(fontFamily) {
|
|
|
2609
2714
|
case "google sans":
|
|
2610
2715
|
return GOOGLE_SANS_STACK;
|
|
2611
2716
|
default:
|
|
2612
|
-
return value
|
|
2717
|
+
return value.includes(",") ? value : `"${value.replace(/^(['"])(.*)\1$/, "$2")}", ${INTER_STACK}`;
|
|
2613
2718
|
}
|
|
2614
2719
|
}
|
|
2615
2720
|
|
|
@@ -10336,6 +10441,190 @@ function JourneyShell({
|
|
|
10336
10441
|
}
|
|
10337
10442
|
);
|
|
10338
10443
|
}
|
|
10444
|
+
|
|
10445
|
+
// src/engine/events-identity.ts
|
|
10446
|
+
var NO_IDENTITY = { source: "none" };
|
|
10447
|
+
function eventsStorageKey(apiKey) {
|
|
10448
|
+
return `founderhq:events:v2:${apiKey.trim().slice(0, 16)}`;
|
|
10449
|
+
}
|
|
10450
|
+
function eventsConsentCookieName(apiKey) {
|
|
10451
|
+
return `fhq_consent_${writeKeyFingerprint(apiKey.trim())}`;
|
|
10452
|
+
}
|
|
10453
|
+
function eventsIdentityCookieName(apiKey) {
|
|
10454
|
+
return `fhq_id_${apiKey.trim().replace(/[^a-zA-Z0-9]/g, "").slice(0, 16)}`;
|
|
10455
|
+
}
|
|
10456
|
+
function writeKeyFingerprint(apiKey) {
|
|
10457
|
+
let hash = 2166136261;
|
|
10458
|
+
for (let index = 0; index < apiKey.length; index++) {
|
|
10459
|
+
hash ^= apiKey.charCodeAt(index);
|
|
10460
|
+
hash = Math.imul(hash, 16777619);
|
|
10461
|
+
}
|
|
10462
|
+
return (hash >>> 0).toString(36).padStart(7, "0");
|
|
10463
|
+
}
|
|
10464
|
+
function readEventsConsent(apiKey) {
|
|
10465
|
+
const value = readCookie(eventsConsentCookieName(apiKey));
|
|
10466
|
+
if (value === "v1.g") return "granted";
|
|
10467
|
+
if (value === "v1.d") return "denied";
|
|
10468
|
+
if (value === "v1.o") return "off";
|
|
10469
|
+
return null;
|
|
10470
|
+
}
|
|
10471
|
+
function findGlobalEventsClient() {
|
|
10472
|
+
const candidate = globalThis.founderhq;
|
|
10473
|
+
return isEventsClient(candidate) ? candidate : null;
|
|
10474
|
+
}
|
|
10475
|
+
function isEventsClient(value) {
|
|
10476
|
+
return Boolean(value) && typeof value === "object" && typeof value.getDistinctId === "function" && typeof value.checkoutMetadata === "function";
|
|
10477
|
+
}
|
|
10478
|
+
function resolveJourneyIdentity(options, storage, now = Date.now) {
|
|
10479
|
+
var _a, _b;
|
|
10480
|
+
const client = options.eventsClient === false ? null : (_a = options.eventsClient) != null ? _a : findGlobalEventsClient();
|
|
10481
|
+
const answer = client ? askEventsClient(client) : "absent";
|
|
10482
|
+
if (typeof answer === "object") return answer;
|
|
10483
|
+
const remembered = readEventsConsent(options.apiKey);
|
|
10484
|
+
if (remembered === "denied" || remembered === "off") return NO_IDENTITY;
|
|
10485
|
+
const key = eventsStorageKey(options.apiKey);
|
|
10486
|
+
if (answer === "silent") {
|
|
10487
|
+
const state2 = readEventsIdentity(options.apiKey, storage, key);
|
|
10488
|
+
return state2 && !state2.opted_out ? identityFromState(state2) : NO_IDENTITY;
|
|
10489
|
+
}
|
|
10490
|
+
const consent = (_b = remembered != null ? remembered : options.consentDefault) != null ? _b : "granted";
|
|
10491
|
+
if (consent !== "granted") return NO_IDENTITY;
|
|
10492
|
+
const state = readOrMintEventsState(options.apiKey, key, storage, now);
|
|
10493
|
+
return state ? identityFromState(state) : NO_IDENTITY;
|
|
10494
|
+
}
|
|
10495
|
+
function askEventsClient(client) {
|
|
10496
|
+
var _a;
|
|
10497
|
+
try {
|
|
10498
|
+
const metadata = client.checkoutMetadata();
|
|
10499
|
+
const anonymousId = cleanId(metadata.fhq_anonymous_id);
|
|
10500
|
+
if (!anonymousId) return "silent";
|
|
10501
|
+
return {
|
|
10502
|
+
anonymousId,
|
|
10503
|
+
distinctId: (_a = cleanId(client.getDistinctId())) != null ? _a : anonymousId,
|
|
10504
|
+
sessionId: cleanId(metadata.fhq_session_id),
|
|
10505
|
+
source: "events"
|
|
10506
|
+
};
|
|
10507
|
+
} catch (e) {
|
|
10508
|
+
return "absent";
|
|
10509
|
+
}
|
|
10510
|
+
}
|
|
10511
|
+
function identityFromState(state) {
|
|
10512
|
+
return {
|
|
10513
|
+
anonymousId: state.anonymous_id,
|
|
10514
|
+
distinctId: state.distinct_id,
|
|
10515
|
+
source: "storage"
|
|
10516
|
+
};
|
|
10517
|
+
}
|
|
10518
|
+
var memoryState = /* @__PURE__ */ new Map();
|
|
10519
|
+
function readOrMintEventsState(apiKey, key, storage, now) {
|
|
10520
|
+
var _a;
|
|
10521
|
+
const existing = (_a = readEventsIdentity(apiKey, storage, key)) != null ? _a : memoryState.get(key);
|
|
10522
|
+
if (existing) return existing.opted_out ? null : existing;
|
|
10523
|
+
const id = createUuid();
|
|
10524
|
+
const state = {
|
|
10525
|
+
anonymous_id: id,
|
|
10526
|
+
anonymous_created_at: now(),
|
|
10527
|
+
distinct_id: id,
|
|
10528
|
+
identified: false,
|
|
10529
|
+
registered: {},
|
|
10530
|
+
pending_set: {},
|
|
10531
|
+
pending_set_once: {},
|
|
10532
|
+
opted_out: false,
|
|
10533
|
+
queue: []
|
|
10534
|
+
};
|
|
10535
|
+
try {
|
|
10536
|
+
storage == null ? void 0 : storage.setItem(key, JSON.stringify(state));
|
|
10537
|
+
} catch (e) {
|
|
10538
|
+
}
|
|
10539
|
+
memoryState.set(key, state);
|
|
10540
|
+
return state;
|
|
10541
|
+
}
|
|
10542
|
+
function readEventsIdentity(apiKey, storage, key) {
|
|
10543
|
+
const stored = readEventsState(storage, key);
|
|
10544
|
+
const cookie = readEventsIdentityCookie(apiKey);
|
|
10545
|
+
if (!cookie) return stored;
|
|
10546
|
+
if (!stored) return cookie;
|
|
10547
|
+
return __spreadProps(__spreadValues({}, stored), {
|
|
10548
|
+
anonymous_id: cookie.anonymous_id,
|
|
10549
|
+
anonymous_created_at: cookie.anonymous_created_at,
|
|
10550
|
+
distinct_id: cookie.distinct_id,
|
|
10551
|
+
identified: cookie.identified,
|
|
10552
|
+
opted_out: stored.opted_out || cookie.opted_out
|
|
10553
|
+
});
|
|
10554
|
+
}
|
|
10555
|
+
function readEventsIdentityCookie(apiKey) {
|
|
10556
|
+
const raw = readCookie(eventsIdentityCookieName(apiKey));
|
|
10557
|
+
if (!raw) return null;
|
|
10558
|
+
try {
|
|
10559
|
+
const value = JSON.parse(raw);
|
|
10560
|
+
if (typeof value.a !== "string" || !value.a) return null;
|
|
10561
|
+
return {
|
|
10562
|
+
anonymous_id: value.a,
|
|
10563
|
+
anonymous_created_at: typeof value.c === "number" ? value.c : 0,
|
|
10564
|
+
distinct_id: typeof value.d === "string" && value.d ? value.d : value.a,
|
|
10565
|
+
identified: value.i === 1,
|
|
10566
|
+
registered: {},
|
|
10567
|
+
pending_set: {},
|
|
10568
|
+
pending_set_once: {},
|
|
10569
|
+
opted_out: value.o === 1,
|
|
10570
|
+
queue: []
|
|
10571
|
+
};
|
|
10572
|
+
} catch (e) {
|
|
10573
|
+
return null;
|
|
10574
|
+
}
|
|
10575
|
+
}
|
|
10576
|
+
function readEventsState(storage, key) {
|
|
10577
|
+
var _a, _b, _c;
|
|
10578
|
+
try {
|
|
10579
|
+
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
10580
|
+
if (!raw) return null;
|
|
10581
|
+
const parsed = JSON.parse(raw);
|
|
10582
|
+
if (typeof parsed.anonymous_id !== "string" || !parsed.anonymous_id) {
|
|
10583
|
+
return null;
|
|
10584
|
+
}
|
|
10585
|
+
return {
|
|
10586
|
+
anonymous_id: parsed.anonymous_id,
|
|
10587
|
+
anonymous_created_at: typeof parsed.anonymous_created_at === "number" ? parsed.anonymous_created_at : 0,
|
|
10588
|
+
distinct_id: typeof parsed.distinct_id === "string" && parsed.distinct_id ? parsed.distinct_id : parsed.anonymous_id,
|
|
10589
|
+
identified: parsed.identified === true,
|
|
10590
|
+
registered: (_a = parsed.registered) != null ? _a : {},
|
|
10591
|
+
pending_set: (_b = parsed.pending_set) != null ? _b : {},
|
|
10592
|
+
pending_set_once: (_c = parsed.pending_set_once) != null ? _c : {},
|
|
10593
|
+
opted_out: parsed.opted_out === true,
|
|
10594
|
+
queue: Array.isArray(parsed.queue) ? parsed.queue : []
|
|
10595
|
+
};
|
|
10596
|
+
} catch (e) {
|
|
10597
|
+
return null;
|
|
10598
|
+
}
|
|
10599
|
+
}
|
|
10600
|
+
function cleanId(value) {
|
|
10601
|
+
const clean = value == null ? void 0 : value.trim();
|
|
10602
|
+
return clean || void 0;
|
|
10603
|
+
}
|
|
10604
|
+
function readCookie(name) {
|
|
10605
|
+
if (typeof document === "undefined") return null;
|
|
10606
|
+
try {
|
|
10607
|
+
const prefix = `${name}=`;
|
|
10608
|
+
for (const part of document.cookie.split(";")) {
|
|
10609
|
+
const trimmed = part.trim();
|
|
10610
|
+
if (trimmed.startsWith(prefix)) {
|
|
10611
|
+
return decodeURIComponent(trimmed.slice(prefix.length));
|
|
10612
|
+
}
|
|
10613
|
+
}
|
|
10614
|
+
} catch (e) {
|
|
10615
|
+
}
|
|
10616
|
+
return null;
|
|
10617
|
+
}
|
|
10618
|
+
function createUuid() {
|
|
10619
|
+
var _a, _b;
|
|
10620
|
+
const cryptoRef = globalThis.crypto;
|
|
10621
|
+
if (cryptoRef == null ? void 0 : cryptoRef.randomUUID) return cryptoRef.randomUUID();
|
|
10622
|
+
const bytes = (_b = (_a = cryptoRef == null ? void 0 : cryptoRef.getRandomValues) == null ? void 0 : _a.call(cryptoRef, new Uint8Array(16))) != null ? _b : Uint8Array.from({ length: 16 }, () => Math.floor(Math.random() * 256));
|
|
10623
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
10624
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
10625
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
10626
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
10627
|
+
}
|
|
10339
10628
|
var FOUNDERHQ_BASE_URL = "https://app.getfounderhq.com";
|
|
10340
10629
|
function resolveJourneyBaseUrl(baseUrl) {
|
|
10341
10630
|
if (!baseUrl) return FOUNDERHQ_BASE_URL;
|
|
@@ -10428,7 +10717,7 @@ function useJourneyConfig({
|
|
|
10428
10717
|
|
|
10429
10718
|
// src/engine/journey-capture.ts
|
|
10430
10719
|
var JOURNEY_LIBRARY_NAME = "@founderhq/journeys";
|
|
10431
|
-
var JOURNEY_LIBRARY_VERSION = "0.
|
|
10720
|
+
var JOURNEY_LIBRARY_VERSION = "1.0.0";
|
|
10432
10721
|
var DEFAULT_QUEUE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
10433
10722
|
var MAX_QUEUED_CAPTURE_EVENTS = 100;
|
|
10434
10723
|
var MAX_BEACON_BYTES = 60 * 1024;
|
|
@@ -10460,7 +10749,8 @@ function safeBrowserStorage(name) {
|
|
|
10460
10749
|
function isQueuedCaptureEvent(value) {
|
|
10461
10750
|
if (!isRecord(value)) return false;
|
|
10462
10751
|
const event = value.event;
|
|
10463
|
-
|
|
10752
|
+
const envelope = value.envelope;
|
|
10753
|
+
return isRecord(event) && typeof event.id === "string" && typeof event.type === "string" && typeof event.occurredAt === "string" && isRecord(envelope) && typeof envelope.clientSessionId === "string" && isRecord(envelope.context) && typeof value.attempts === "number" && typeof value.createdAt === "number";
|
|
10464
10754
|
}
|
|
10465
10755
|
function pruneQueuedEvents(queue, now = Date.now(), ttlMs = DEFAULT_QUEUE_TTL_MS) {
|
|
10466
10756
|
const cutoff = now - ttlMs;
|
|
@@ -10472,25 +10762,12 @@ function readPersistedCaptureQueue(storage, key) {
|
|
|
10472
10762
|
const raw = storage.getItem(key);
|
|
10473
10763
|
if (!raw) return null;
|
|
10474
10764
|
const parsed = JSON.parse(raw);
|
|
10475
|
-
if (typeof parsed.
|
|
10476
|
-
return null;
|
|
10477
|
-
}
|
|
10765
|
+
if (typeof parsed.clientSessionId !== "string") return null;
|
|
10478
10766
|
const queue = Array.isArray(parsed.queue) ? pruneQueuedEvents(parsed.queue.filter(isQueuedCaptureEvent)) : [];
|
|
10479
10767
|
return {
|
|
10480
|
-
visitorId: parsed.visitorId,
|
|
10481
10768
|
clientSessionId: parsed.clientSessionId,
|
|
10482
10769
|
updatedAt: typeof parsed.updatedAt === "number" ? parsed.updatedAt : Date.now(),
|
|
10483
|
-
queue
|
|
10484
|
-
var _a;
|
|
10485
|
-
return __spreadProps(__spreadValues({}, item), {
|
|
10486
|
-
// Legacy persisted headers belong to the original batch, never the new presentation.
|
|
10487
|
-
envelope: (_a = item.envelope) != null ? _a : {
|
|
10488
|
-
visitorId: parsed.visitorId,
|
|
10489
|
-
clientSessionId: parsed.clientSessionId,
|
|
10490
|
-
context: {}
|
|
10491
|
-
}
|
|
10492
|
-
});
|
|
10493
|
-
})
|
|
10770
|
+
queue
|
|
10494
10771
|
};
|
|
10495
10772
|
} catch (e) {
|
|
10496
10773
|
return null;
|
|
@@ -10507,7 +10784,6 @@ function persistCaptureQueue(storage, runtime, queue) {
|
|
|
10507
10784
|
storage.setItem(
|
|
10508
10785
|
runtime.queueKey,
|
|
10509
10786
|
JSON.stringify({
|
|
10510
|
-
visitorId: runtime.visitorId,
|
|
10511
10787
|
clientSessionId: runtime.clientSessionId,
|
|
10512
10788
|
updatedAt: Date.now(),
|
|
10513
10789
|
queue: pruned
|
|
@@ -10606,7 +10882,17 @@ function pageContext(redactUrlParams) {
|
|
|
10606
10882
|
campaign
|
|
10607
10883
|
});
|
|
10608
10884
|
}
|
|
10609
|
-
function
|
|
10885
|
+
function currentIdentity(capture) {
|
|
10886
|
+
return resolveJourneyIdentity(
|
|
10887
|
+
{
|
|
10888
|
+
apiKey: capture.apiKey,
|
|
10889
|
+
eventsClient: capture.eventsClient,
|
|
10890
|
+
consentDefault: capture.consentDefault
|
|
10891
|
+
},
|
|
10892
|
+
safeBrowserStorage("localStorage")
|
|
10893
|
+
);
|
|
10894
|
+
}
|
|
10895
|
+
function captureContext(capture, identity) {
|
|
10610
10896
|
var _a, _b;
|
|
10611
10897
|
const customContext = cleanObject(__spreadValues(__spreadValues({}, (_a = capture.context) != null ? _a : {}), (_b = safeContextFactory(capture.contextFactory)) != null ? _b : {}));
|
|
10612
10898
|
if (capture.captureContext === false) {
|
|
@@ -10621,8 +10907,13 @@ function captureContext(capture, runtime) {
|
|
|
10621
10907
|
name: JOURNEY_LIBRARY_NAME,
|
|
10622
10908
|
version: JOURNEY_LIBRARY_VERSION
|
|
10623
10909
|
},
|
|
10624
|
-
|
|
10625
|
-
|
|
10910
|
+
// The same ids the events SDK sends, so the server joins this session
|
|
10911
|
+
// to the visitor's contact the way it joins an event. Absent when the
|
|
10912
|
+
// visit is cookieless.
|
|
10913
|
+
anonymousId: identity.anonymousId,
|
|
10914
|
+
distinctId: identity.distinctId,
|
|
10915
|
+
sessionId: identity.sessionId,
|
|
10916
|
+
identitySource: identity.source,
|
|
10626
10917
|
locale: navigatorRef == null ? void 0 : navigatorRef.language,
|
|
10627
10918
|
timezone: safeTimezone(),
|
|
10628
10919
|
userAgent: navigatorRef == null ? void 0 : navigatorRef.userAgent,
|
|
@@ -10652,12 +10943,7 @@ function safeSendBeacon() {
|
|
|
10652
10943
|
}
|
|
10653
10944
|
async function sendCaptureBatch(capture, runtime, batch, options = {}) {
|
|
10654
10945
|
var _a, _b;
|
|
10655
|
-
const payload = __spreadProps(__spreadValues(__spreadValues({}, !capture.transport && options.preferBeacon ? { apiKey: capture.apiKey } : {}), (_b = (_a = batch[0]) == null ? void 0 : _a.envelope) != null ? _b : {
|
|
10656
|
-
clientSessionId: runtime.clientSessionId,
|
|
10657
|
-
visitorId: runtime.visitorId,
|
|
10658
|
-
revisionId: capture.revisionId,
|
|
10659
|
-
context: captureContext(capture, runtime)
|
|
10660
|
-
}), {
|
|
10946
|
+
const payload = __spreadProps(__spreadValues(__spreadValues({}, !capture.transport && options.preferBeacon ? { apiKey: capture.apiKey } : {}), (_b = (_a = batch[0]) == null ? void 0 : _a.envelope) != null ? _b : buildEnvelope(capture, runtime)), {
|
|
10661
10947
|
events: batch.map((item) => item.event)
|
|
10662
10948
|
});
|
|
10663
10949
|
const url = captureUrl(capture);
|
|
@@ -10707,6 +10993,15 @@ async function sendCaptureBatch(capture, runtime, batch, options = {}) {
|
|
|
10707
10993
|
return "failed";
|
|
10708
10994
|
}
|
|
10709
10995
|
}
|
|
10996
|
+
function buildEnvelope(capture, runtime) {
|
|
10997
|
+
const identity = currentIdentity(capture);
|
|
10998
|
+
return {
|
|
10999
|
+
visitorId: identity.anonymousId,
|
|
11000
|
+
clientSessionId: runtime.clientSessionId,
|
|
11001
|
+
revisionId: capture.revisionId,
|
|
11002
|
+
context: captureContext(capture, identity)
|
|
11003
|
+
};
|
|
11004
|
+
}
|
|
10710
11005
|
function finiteRetryDelay(value) {
|
|
10711
11006
|
return typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : 0;
|
|
10712
11007
|
}
|
|
@@ -10869,13 +11164,13 @@ function useJourneyCaptureRuntime(params) {
|
|
|
10869
11164
|
);
|
|
10870
11165
|
}, []);
|
|
10871
11166
|
const ensureRuntime = useCallback((capture) => {
|
|
10872
|
-
var _a, _b, _c, _d
|
|
11167
|
+
var _a, _b, _c, _d;
|
|
10873
11168
|
if (typeof window === "undefined") return null;
|
|
10874
11169
|
const queueKey = `fhq_journey_queue:v2:${capture.apiKey.slice(
|
|
10875
11170
|
0,
|
|
10876
11171
|
16
|
|
10877
11172
|
)}:${capture.journeyId}`;
|
|
10878
|
-
const presentationKey = `${(_a = capture.clientSessionId) != null ? _a : "
|
|
11173
|
+
const presentationKey = `${(_a = capture.clientSessionId) != null ? _a : "runtime"}:${(_b = capture.revisionId) != null ? _b : ""}`;
|
|
10879
11174
|
const existing = runtimeRef.current;
|
|
10880
11175
|
if ((existing == null ? void 0 : existing.queueKey) === queueKey && existing.presentationKey === presentationKey) {
|
|
10881
11176
|
return existing;
|
|
@@ -10884,22 +11179,20 @@ function useJourneyCaptureRuntime(params) {
|
|
|
10884
11179
|
const session = safeBrowserStorage("sessionStorage");
|
|
10885
11180
|
if (existing) persistCaptureQueue(local, existing, queueRef.current);
|
|
10886
11181
|
const persisted = readPersistedCaptureQueue(local, queueKey);
|
|
10887
|
-
const visitorId = (_c = persisted == null ? void 0 : persisted.visitorId) != null ? _c : local ? getStoredId(local, "fhq_journey_visitor_id", "fhqv") : randomId("fhqv");
|
|
10888
11182
|
const sessionKey = `fhq_journey_session:${capture.journeyId}`;
|
|
10889
|
-
const clientSessionId = (
|
|
11183
|
+
const clientSessionId = (_c = capture.clientSessionId) != null ? _c : session ? getStoredId(session, sessionKey, "fhqs") : randomId("fhqs");
|
|
10890
11184
|
try {
|
|
10891
11185
|
session == null ? void 0 : session.setItem(sessionKey, clientSessionId);
|
|
10892
11186
|
} catch (e) {
|
|
10893
11187
|
}
|
|
10894
11188
|
const runtime = {
|
|
10895
11189
|
journeyId: capture.journeyId,
|
|
10896
|
-
visitorId,
|
|
10897
11190
|
clientSessionId,
|
|
10898
11191
|
queueKey,
|
|
10899
11192
|
presentationKey
|
|
10900
11193
|
};
|
|
10901
11194
|
runtimeRef.current = runtime;
|
|
10902
|
-
queueRef.current = (
|
|
11195
|
+
queueRef.current = (_d = persisted == null ? void 0 : persisted.queue) != null ? _d : [];
|
|
10903
11196
|
return runtime;
|
|
10904
11197
|
}, []);
|
|
10905
11198
|
const flush = useCallback(
|
|
@@ -10916,10 +11209,7 @@ function useJourneyCaptureRuntime(params) {
|
|
|
10916
11209
|
if (first && ((_b = first.retryAt) != null ? _b : 0) > Date.now()) return;
|
|
10917
11210
|
const envelope = first == null ? void 0 : first.envelope;
|
|
10918
11211
|
const batch = queueRef.current.filter(
|
|
10919
|
-
(item) =>
|
|
10920
|
-
var _a2, _b2;
|
|
10921
|
-
return ((_a2 = item.envelope) == null ? void 0 : _a2.clientSessionId) === (envelope == null ? void 0 : envelope.clientSessionId) && ((_b2 = item.envelope) == null ? void 0 : _b2.revisionId) === (envelope == null ? void 0 : envelope.revisionId);
|
|
10922
|
-
}
|
|
11212
|
+
(item) => item.envelope.clientSessionId === (envelope == null ? void 0 : envelope.clientSessionId) && item.envelope.revisionId === (envelope == null ? void 0 : envelope.revisionId)
|
|
10923
11213
|
).slice(0, options.preferBeacon ? Math.min(batchSize, 5) : batchSize);
|
|
10924
11214
|
if (batch.length === 0) {
|
|
10925
11215
|
persistQueue();
|
|
@@ -11001,12 +11291,7 @@ function useJourneyCaptureRuntime(params) {
|
|
|
11001
11291
|
if (!runtime) return;
|
|
11002
11292
|
sequenceRef.current += 1;
|
|
11003
11293
|
queueRef.current.push({
|
|
11004
|
-
envelope:
|
|
11005
|
-
visitorId: runtime.visitorId,
|
|
11006
|
-
clientSessionId: runtime.clientSessionId,
|
|
11007
|
-
revisionId: capture.revisionId,
|
|
11008
|
-
context: captureContext(capture, runtime)
|
|
11009
|
-
},
|
|
11294
|
+
envelope: buildEnvelope(capture, runtime),
|
|
11010
11295
|
event: toCaptureEvent(
|
|
11011
11296
|
config,
|
|
11012
11297
|
event,
|
|
@@ -11152,4 +11437,4 @@ function Journey({
|
|
|
11152
11437
|
);
|
|
11153
11438
|
}
|
|
11154
11439
|
|
|
11155
|
-
export { BLOCK_META, DiscountCodeDialog, GravityBin, Journey, JourneyBlobLayer, JourneyContext, JourneyHapticContext, JourneyProvider, JourneyShell, SegmentedProgress, StepRenderer, TimelineBlock, arePageInputsValid, evaluateCondition, hasVisibleProgress, resolveJourneyBlobDefaultSize, resolveJourneyFontFamily, resolveStepBackgroundMode, useJourneyActions, useJourneyCaptureRuntime, useJourneyConfig, useJourneyState };
|
|
11440
|
+
export { BLOCK_META, DiscountCodeDialog, GravityBin, Journey, JourneyBlobLayer, JourneyContext, JourneyHapticContext, JourneyProvider, JourneyShell, SegmentedProgress, StepRenderer, TimelineBlock, arePageInputsValid, evaluateCondition, eventsStorageKey, firstFontFamily, getJourneyWebFontFamilies, getWebFontStylesheetUrl, hasVisibleProgress, isWebFontFamily, resolveJourneyBlobDefaultSize, resolveJourneyFontFamily, resolveJourneyIdentity, resolveStepBackgroundMode, useJourneyActions, useJourneyCaptureRuntime, useJourneyConfig, useJourneyState, useJourneyWebFonts };
|