@founderhq/journeys 0.3.67 → 0.4.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/index.js CHANGED
@@ -651,6 +651,8 @@ function JourneyProvider({
651
651
  const { trigger } = useWebHaptics();
652
652
  const onEventRef = useRef(onEvent);
653
653
  const rawAnswersRef = useRef({});
654
+ const sessionStartEmittedRef = useRef(false);
655
+ const lastViewedStepIdRef = useRef(null);
654
656
  const [discountCodeDialog, setDiscountCodeDialog] = useState(null);
655
657
  useEffect(() => {
656
658
  onEventRef.current = onEvent;
@@ -710,6 +712,39 @@ function JourneyProvider({
710
712
  () => normalizedConfig.steps.flatMap(getStepVariables),
711
713
  [normalizedConfig.steps]
712
714
  );
715
+ useEffect(() => {
716
+ var _a, _b;
717
+ const currentStep = config.steps[currentStepIndex];
718
+ if (!currentStep) return;
719
+ const eventAnswers = getEventAnswers(
720
+ config.computedVariables,
721
+ rawAnswersRef.current
722
+ );
723
+ const strippedStep = stripOptionsFromEventStep(currentStep);
724
+ if (!sessionStartEmittedRef.current) {
725
+ sessionStartEmittedRef.current = true;
726
+ (_a = onEventRef.current) == null ? void 0 : _a.call(onEventRef, __spreadProps(__spreadValues({
727
+ type: "session_start",
728
+ step: strippedStep
729
+ }, eventAnswers), {
730
+ variables: allVariables
731
+ }));
732
+ }
733
+ if (lastViewedStepIdRef.current !== currentStep.id) {
734
+ lastViewedStepIdRef.current = currentStep.id;
735
+ (_b = onEventRef.current) == null ? void 0 : _b.call(onEventRef, __spreadProps(__spreadValues({
736
+ type: "step_view",
737
+ step: strippedStep
738
+ }, eventAnswers), {
739
+ variables: allVariables
740
+ }));
741
+ }
742
+ }, [
743
+ allVariables,
744
+ config.computedVariables,
745
+ config.steps,
746
+ currentStepIndex
747
+ ]);
713
748
  const setAnswer = useCallback((stepId, answer) => {
714
749
  if (computedVariableIds.has(stepId)) return;
715
750
  setRawAnswers((prev) => {
@@ -9610,19 +9645,454 @@ function JourneyShell({ className, theme } = {}) {
9610
9645
  ) })
9611
9646
  ] });
9612
9647
  }
9648
+ var JOURNEY_LIBRARY_NAME = "@founderhq/journeys";
9649
+ var JOURNEY_LIBRARY_VERSION = "0.4.0";
9650
+ function randomId(prefix) {
9651
+ const cryptoRef = globalThis.crypto;
9652
+ if (cryptoRef == null ? void 0 : cryptoRef.randomUUID) return `${prefix}_${cryptoRef.randomUUID()}`;
9653
+ return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`;
9654
+ }
9655
+ function readJson(storage, key, fallback) {
9656
+ try {
9657
+ const raw = storage.getItem(key);
9658
+ return raw ? JSON.parse(raw) : fallback;
9659
+ } catch (e) {
9660
+ return fallback;
9661
+ }
9662
+ }
9663
+ function getStoredId(storage, key, prefix) {
9664
+ try {
9665
+ const existing = storage.getItem(key);
9666
+ if (existing) return existing;
9667
+ const next = randomId(prefix);
9668
+ storage.setItem(key, next);
9669
+ return next;
9670
+ } catch (e) {
9671
+ return randomId(prefix);
9672
+ }
9673
+ }
9674
+ function isRecord(value) {
9675
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
9676
+ }
9677
+ function cleanObject(value) {
9678
+ if (!value || typeof value !== "object") return {};
9679
+ return __spreadValues({}, value);
9680
+ }
9681
+ var DEFAULT_REDACTED_URL_PARAMS = [
9682
+ "access_token",
9683
+ "api_key",
9684
+ "auth",
9685
+ "code",
9686
+ "email",
9687
+ "key",
9688
+ "otp",
9689
+ "password",
9690
+ "phone",
9691
+ "secret",
9692
+ "signature",
9693
+ "token"
9694
+ ];
9695
+ function safeContextFactory(factory) {
9696
+ if (typeof factory !== "function") return void 0;
9697
+ try {
9698
+ const value = factory();
9699
+ return isRecord(value) ? value : void 0;
9700
+ } catch (e) {
9701
+ return void 0;
9702
+ }
9703
+ }
9704
+ function safeTimezone() {
9705
+ try {
9706
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
9707
+ } catch (e) {
9708
+ return void 0;
9709
+ }
9710
+ }
9711
+ function campaignContext(params) {
9712
+ var _a, _b, _c, _d, _e;
9713
+ return cleanObject({
9714
+ source: (_a = params.get("utm_source")) != null ? _a : void 0,
9715
+ medium: (_b = params.get("utm_medium")) != null ? _b : void 0,
9716
+ name: (_c = params.get("utm_campaign")) != null ? _c : void 0,
9717
+ term: (_d = params.get("utm_term")) != null ? _d : void 0,
9718
+ content: (_e = params.get("utm_content")) != null ? _e : void 0
9719
+ });
9720
+ }
9721
+ function redactedSearch(params, redactUrlParams) {
9722
+ if ([...params.keys()].length === 0) return "";
9723
+ const next = new URLSearchParams(params);
9724
+ const redactAll = redactUrlParams === true;
9725
+ const names = Array.isArray(redactUrlParams) && redactUrlParams.length > 0 ? redactUrlParams : DEFAULT_REDACTED_URL_PARAMS;
9726
+ const redactedNames = new Set(names.map((name) => name.toLowerCase()));
9727
+ for (const key of [...next.keys()]) {
9728
+ if (redactAll || redactedNames.has(key.toLowerCase())) {
9729
+ next.set(key, "[redacted]");
9730
+ }
9731
+ }
9732
+ const value = next.toString();
9733
+ return value ? `?${value}` : "";
9734
+ }
9735
+ function pageContext(redactUrlParams) {
9736
+ if (typeof window === "undefined") return void 0;
9737
+ const params = new URLSearchParams(window.location.search);
9738
+ const campaign = campaignContext(params);
9739
+ const search = redactedSearch(params, redactUrlParams);
9740
+ return cleanObject({
9741
+ url: `${window.location.origin}${window.location.pathname}${search}${window.location.hash}`,
9742
+ path: window.location.pathname,
9743
+ search: search || void 0,
9744
+ title: document.title,
9745
+ referrer: document.referrer,
9746
+ campaign
9747
+ });
9748
+ }
9749
+ function captureContext(capture, runtime) {
9750
+ var _a, _b;
9751
+ const customContext = cleanObject(__spreadValues(__spreadValues({}, (_a = capture.context) != null ? _a : {}), (_b = safeContextFactory(capture.contextFactory)) != null ? _b : {}));
9752
+ if (capture.captureContext === false) {
9753
+ return customContext;
9754
+ }
9755
+ const page = pageContext(capture.redactUrlParams);
9756
+ const navigatorRef = typeof window !== "undefined" ? window.navigator : void 0;
9757
+ const screenRef = typeof window !== "undefined" ? window.screen : void 0;
9758
+ return cleanObject(__spreadValues({
9759
+ source: { type: "embed", product: "journeys" },
9760
+ library: {
9761
+ name: JOURNEY_LIBRARY_NAME,
9762
+ version: JOURNEY_LIBRARY_VERSION
9763
+ },
9764
+ anonymousId: runtime.visitorId,
9765
+ sessionId: runtime.clientSessionId,
9766
+ locale: navigatorRef == null ? void 0 : navigatorRef.language,
9767
+ timezone: safeTimezone(),
9768
+ userAgent: navigatorRef == null ? void 0 : navigatorRef.userAgent,
9769
+ page,
9770
+ campaign: isRecord(page) ? page.campaign : void 0,
9771
+ screen: screenRef ? { width: screenRef.width, height: screenRef.height } : void 0
9772
+ }, customContext));
9773
+ }
9774
+ function toJsonRecord(value) {
9775
+ return isRecord(value) ? value : {};
9776
+ }
9777
+ function answerValue(answers, variable) {
9778
+ return Object.prototype.hasOwnProperty.call(answers, variable) ? answers[variable] : void 0;
9779
+ }
9780
+ function stepAnswerVariables(step) {
9781
+ var _a, _b, _c, _d, _e;
9782
+ if (step.type === "swipe_cards") {
9783
+ return ((_a = step.swipeCards) != null ? _a : []).map((card) => ({
9784
+ stepId: step.id,
9785
+ variable: card.variable,
9786
+ label: card.text
9787
+ }));
9788
+ }
9789
+ if (step.type === "input") {
9790
+ return ((_b = step.fields) != null ? _b : []).map((field) => {
9791
+ var _a2;
9792
+ return {
9793
+ stepId: step.id,
9794
+ variable: (_a2 = field.variable) != null ? _a2 : field.id,
9795
+ label: field.label,
9796
+ fieldType: field.type
9797
+ };
9798
+ });
9799
+ }
9800
+ return [
9801
+ {
9802
+ stepId: step.id,
9803
+ variable: (_c = step.variable) != null ? _c : step.id,
9804
+ label: (_e = (_d = step.question) != null ? _d : step.preface) != null ? _e : step.id
9805
+ }
9806
+ ];
9807
+ }
9808
+ function buildAnswerSnapshot(config, answers) {
9809
+ const items = [];
9810
+ for (const step of config.steps) {
9811
+ for (const item of stepAnswerVariables(step)) {
9812
+ const value = answerValue(answers, item.variable);
9813
+ if (value === void 0) continue;
9814
+ items.push({
9815
+ stepId: item.stepId,
9816
+ variable: item.variable,
9817
+ label: item.label,
9818
+ value
9819
+ });
9820
+ }
9821
+ }
9822
+ return { items };
9823
+ }
9824
+ function buildRespondentSnapshot(config, answers) {
9825
+ var _a, _b;
9826
+ const snapshot = {};
9827
+ for (const step of config.steps) {
9828
+ if (step.type !== "input") continue;
9829
+ for (const field of (_a = step.fields) != null ? _a : []) {
9830
+ const variable = (_b = field.variable) != null ? _b : field.id;
9831
+ const value = answerValue(answers, variable);
9832
+ if (value !== void 0) snapshot[variable] = value;
9833
+ }
9834
+ }
9835
+ return snapshot;
9836
+ }
9837
+ function buildContactRef(config, answers) {
9838
+ var _a, _b;
9839
+ const contact = {};
9840
+ for (const step of config.steps) {
9841
+ if (step.type !== "input") continue;
9842
+ for (const field of (_a = step.fields) != null ? _a : []) {
9843
+ const variable = (_b = field.variable) != null ? _b : field.id;
9844
+ const value = answerValue(answers, variable);
9845
+ if (typeof value !== "string" || !value.trim()) continue;
9846
+ const normalizedVariable = variable.toLowerCase().replace(/[-_\s]/g, "");
9847
+ if (field.type === "email" || normalizedVariable.includes("email")) {
9848
+ contact.email = value;
9849
+ } else if (field.type === "tel" || normalizedVariable.includes("phone")) {
9850
+ contact.phone = value;
9851
+ } else if (normalizedVariable === "externalid") {
9852
+ contact.externalId = value;
9853
+ }
9854
+ }
9855
+ }
9856
+ return Object.keys(contact).length > 0 ? contact : void 0;
9857
+ }
9858
+ function eventStepId(event) {
9859
+ if ("step" in event) return event.step.id;
9860
+ if (event.type === "navigate") return event.to.id;
9861
+ if (event.type === "purchase_intent") return event.stepId;
9862
+ return void 0;
9863
+ }
9864
+ function eventProperties(event) {
9865
+ if (event.type === "step_submit") {
9866
+ return { submitted: event.submitted };
9867
+ }
9868
+ if (event.type === "navigate") {
9869
+ return {
9870
+ fromStepId: event.from.id,
9871
+ toStepId: event.to.id,
9872
+ direction: event.direction
9873
+ };
9874
+ }
9875
+ if (event.type === "purchase_intent") {
9876
+ return __spreadValues({
9877
+ variable: event.variable,
9878
+ plan: event.plan
9879
+ }, event.discount ? { discount: event.discount } : {});
9880
+ }
9881
+ return {};
9882
+ }
9883
+ function toCaptureEvent(config, event, sequence, runtime) {
9884
+ const answers = "answers" in event ? event.answers : {};
9885
+ const payload = {
9886
+ id: createCaptureEventId(runtime, event, sequence),
9887
+ type: event.type,
9888
+ occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
9889
+ stepId: eventStepId(event),
9890
+ properties: eventProperties(event),
9891
+ answers: toJsonRecord(answers),
9892
+ computedVariables: "computedVariables" in event ? toJsonRecord(event.computedVariables) : void 0
9893
+ };
9894
+ if (event.type === "complete") {
9895
+ payload.respondentSnapshot = buildRespondentSnapshot(config, answers);
9896
+ payload.answerSnapshot = buildAnswerSnapshot(config, answers);
9897
+ payload.contact = buildContactRef(config, answers);
9898
+ }
9899
+ return payload;
9900
+ }
9901
+ function createCaptureEventId(runtime, event, sequence) {
9902
+ return `${runtime.clientSessionId}:${event.type}:${sequence.toString(
9903
+ 36
9904
+ )}:${randomId("fhqe")}`;
9905
+ }
9906
+ function useJourneyCapture(params) {
9907
+ const onEventRef = useRef(params.onEvent);
9908
+ const configRef = useRef(params.config);
9909
+ const captureRef = useRef(params.capture);
9910
+ const runtimeRef = useRef(null);
9911
+ const queueRef = useRef([]);
9912
+ const sequenceRef = useRef(0);
9913
+ const flushingRef = useRef(false);
9914
+ onEventRef.current = params.onEvent;
9915
+ configRef.current = params.config;
9916
+ captureRef.current = params.capture;
9917
+ const persistQueue = useCallback(() => {
9918
+ const runtime = runtimeRef.current;
9919
+ if (!runtime || typeof window === "undefined") return;
9920
+ try {
9921
+ sessionStorage.setItem(
9922
+ runtime.queueKey,
9923
+ JSON.stringify(queueRef.current)
9924
+ );
9925
+ } catch (e) {
9926
+ }
9927
+ }, []);
9928
+ const ensureRuntime = useCallback((capture) => {
9929
+ if (typeof window === "undefined") return null;
9930
+ const existing = runtimeRef.current;
9931
+ if ((existing == null ? void 0 : existing.journeyId) === capture.journeyId) return existing;
9932
+ const visitorId = getStoredId(
9933
+ localStorage,
9934
+ "fhq_journey_visitor_id",
9935
+ "fhqv"
9936
+ );
9937
+ const clientSessionId = getStoredId(
9938
+ sessionStorage,
9939
+ `fhq_journey_session:${capture.journeyId}`,
9940
+ "fhqs"
9941
+ );
9942
+ const queueKey = `fhq_journey_queue:${capture.journeyId}:${clientSessionId}`;
9943
+ const runtime = {
9944
+ journeyId: capture.journeyId,
9945
+ visitorId,
9946
+ clientSessionId,
9947
+ queueKey
9948
+ };
9949
+ runtimeRef.current = runtime;
9950
+ queueRef.current = readJson(
9951
+ sessionStorage,
9952
+ queueKey,
9953
+ []
9954
+ );
9955
+ return runtime;
9956
+ }, []);
9957
+ const flush = useCallback(async () => {
9958
+ var _a, _b, _c;
9959
+ const capture = captureRef.current;
9960
+ if (!capture || !configRef.current || flushingRef.current) return;
9961
+ const runtime = ensureRuntime(capture);
9962
+ if (!runtime || queueRef.current.length === 0) return;
9963
+ flushingRef.current = true;
9964
+ const batchSize = Math.max(1, (_a = capture.batchSize) != null ? _a : 10);
9965
+ const maxRetries = Math.max(1, (_b = capture.maxRetries) != null ? _b : 3);
9966
+ const batch = queueRef.current.slice(0, batchSize);
9967
+ const baseUrl = (_c = capture.baseUrl) != null ? _c : "https://getfounderhq.com";
9968
+ try {
9969
+ const response = await fetch(
9970
+ `${baseUrl}/api/v1/journeys/${encodeURIComponent(
9971
+ capture.journeyId
9972
+ )}/capture`,
9973
+ {
9974
+ method: "POST",
9975
+ headers: {
9976
+ Authorization: `Bearer ${capture.apiKey}`,
9977
+ "Content-Type": "application/json"
9978
+ },
9979
+ body: JSON.stringify({
9980
+ clientSessionId: runtime.clientSessionId,
9981
+ visitorId: runtime.visitorId,
9982
+ context: captureContext(capture, runtime),
9983
+ events: batch.map((item) => item.event)
9984
+ }),
9985
+ keepalive: batch.length <= 5
9986
+ }
9987
+ );
9988
+ if (!response.ok) throw new Error(`Capture failed: ${response.status}`);
9989
+ queueRef.current = queueRef.current.slice(batch.length);
9990
+ } catch (e) {
9991
+ const failedIds = new Set(batch.map((item) => item.event.id));
9992
+ queueRef.current = queueRef.current.map(
9993
+ (item) => failedIds.has(item.event.id) ? __spreadProps(__spreadValues({}, item), { attempts: item.attempts + 1 }) : item
9994
+ ).filter((item) => item.attempts < maxRetries);
9995
+ } finally {
9996
+ persistQueue();
9997
+ flushingRef.current = false;
9998
+ }
9999
+ }, [ensureRuntime, persistQueue]);
10000
+ useEffect(() => {
10001
+ var _a;
10002
+ const capture = captureRef.current;
10003
+ if (!capture || typeof window === "undefined") return;
10004
+ ensureRuntime(capture);
10005
+ const interval = window.setInterval(
10006
+ () => void flush(),
10007
+ Math.max(1e3, (_a = capture.flushIntervalMs) != null ? _a : 3e3)
10008
+ );
10009
+ const handleVisibility = () => {
10010
+ if (document.visibilityState === "hidden") void flush();
10011
+ };
10012
+ window.addEventListener("beforeunload", persistQueue);
10013
+ document.addEventListener("visibilitychange", handleVisibility);
10014
+ void flush();
10015
+ return () => {
10016
+ window.clearInterval(interval);
10017
+ window.removeEventListener("beforeunload", persistQueue);
10018
+ document.removeEventListener("visibilitychange", handleVisibility);
10019
+ persistQueue();
10020
+ };
10021
+ }, [ensureRuntime, flush, persistQueue, params.capture]);
10022
+ return useCallback(
10023
+ (event) => {
10024
+ var _a, _b;
10025
+ (_a = onEventRef.current) == null ? void 0 : _a.call(onEventRef, event);
10026
+ const capture = captureRef.current;
10027
+ const config = configRef.current;
10028
+ if (!capture || !config) return;
10029
+ const runtime = ensureRuntime(capture);
10030
+ if (!runtime) return;
10031
+ sequenceRef.current += 1;
10032
+ queueRef.current.push({
10033
+ event: toCaptureEvent(config, event, sequenceRef.current, runtime),
10034
+ attempts: 0
10035
+ });
10036
+ persistQueue();
10037
+ const batchSize = Math.max(1, (_b = capture.batchSize) != null ? _b : 10);
10038
+ if (queueRef.current.length >= batchSize) void flush();
10039
+ },
10040
+ [ensureRuntime, flush, persistQueue]
10041
+ );
10042
+ }
10043
+ var FOUNDERHQ_BASE_URL = "https://getfounderhq.com";
10044
+ function resolveJourneyBaseUrl(baseUrl) {
10045
+ if (!baseUrl) return FOUNDERHQ_BASE_URL;
10046
+ try {
10047
+ const parsed = new URL(baseUrl);
10048
+ const hostname = parsed.hostname.toLowerCase();
10049
+ const isLocal = hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname === "[::1]";
10050
+ return isLocal ? parsed.origin : FOUNDERHQ_BASE_URL;
10051
+ } catch (e) {
10052
+ return FOUNDERHQ_BASE_URL;
10053
+ }
10054
+ }
9613
10055
  function useJourneyConfig({
9614
10056
  apiKey,
9615
10057
  journeyId,
9616
- baseUrl = "http://localhost:3002"
10058
+ baseUrl,
10059
+ config,
10060
+ capture = true
9617
10061
  }) {
9618
10062
  const [state, setState] = useState({ status: "loading" });
9619
10063
  useEffect(() => {
9620
10064
  let cancelled = false;
9621
- async function fetchConfig() {
9622
- var _a;
10065
+ const resolvedBaseUrl = resolveJourneyBaseUrl(baseUrl);
10066
+ async function loadConfig() {
10067
+ var _a, _b;
9623
10068
  setState({ status: "loading" });
9624
10069
  try {
9625
- const url = `${baseUrl}/api/v1/journeys/${encodeURIComponent(journeyId)}`;
10070
+ const validateUrl = `${resolvedBaseUrl}/api/v1/journeys/${encodeURIComponent(
10071
+ journeyId
10072
+ )}/validate`;
10073
+ const validateRes = await fetch(validateUrl, {
10074
+ method: "POST",
10075
+ headers: {
10076
+ Authorization: `Bearer ${apiKey}`,
10077
+ "Content-Type": "application/json"
10078
+ },
10079
+ body: JSON.stringify({ capture })
10080
+ });
10081
+ if (!validateRes.ok) {
10082
+ const body = await validateRes.json().catch(() => ({}));
10083
+ throw new Error(
10084
+ (_a = body.error) != null ? _a : `Journey is unavailable (HTTP ${validateRes.status})`
10085
+ );
10086
+ }
10087
+ if (config) {
10088
+ if (!cancelled) {
10089
+ setState({ status: "ready", config });
10090
+ }
10091
+ return;
10092
+ }
10093
+ const url = `${resolvedBaseUrl}/api/v1/journeys/${encodeURIComponent(
10094
+ journeyId
10095
+ )}`;
9626
10096
  const res = await fetch(url, {
9627
10097
  headers: {
9628
10098
  Authorization: `Bearer ${apiKey}`,
@@ -9632,7 +10102,7 @@ function useJourneyConfig({
9632
10102
  if (!res.ok) {
9633
10103
  const body = await res.json().catch(() => ({}));
9634
10104
  throw new Error(
9635
- (_a = body.error) != null ? _a : `Failed to fetch journey config (HTTP ${res.status})`
10105
+ (_b = body.error) != null ? _b : `Failed to fetch journey config (HTTP ${res.status})`
9636
10106
  );
9637
10107
  }
9638
10108
  const data = await res.json();
@@ -9648,11 +10118,11 @@ function useJourneyConfig({
9648
10118
  }
9649
10119
  }
9650
10120
  }
9651
- fetchConfig();
10121
+ loadConfig();
9652
10122
  return () => {
9653
10123
  cancelled = true;
9654
10124
  };
9655
- }, [apiKey, journeyId, baseUrl]);
10125
+ }, [apiKey, journeyId, baseUrl, config, capture]);
9656
10126
  return state;
9657
10127
  }
9658
10128
  function DefaultLoading() {
@@ -9701,15 +10171,16 @@ function DefaultError({ error }) {
9701
10171
  textAlign: "center"
9702
10172
  },
9703
10173
  children: [
9704
- /* @__PURE__ */ jsx("p", { style: { fontSize: "1.125rem", fontWeight: 600 }, children: "Failed to load journey" }),
10174
+ /* @__PURE__ */ jsx("p", { style: { fontSize: "1.125rem", fontWeight: 600 }, children: "This Journey is unavailable" }),
9705
10175
  /* @__PURE__ */ jsx("p", { style: { fontSize: "0.875rem", marginTop: "0.5rem", opacity: 0.7 }, children: error.message })
9706
10176
  ]
9707
10177
  }
9708
10178
  );
9709
10179
  }
9710
- function JourneyRemote({
10180
+ function Journey({
9711
10181
  apiKey,
9712
10182
  journeyId,
10183
+ config,
9713
10184
  baseUrl,
9714
10185
  storageKey,
9715
10186
  onEvent,
@@ -9719,9 +10190,28 @@ function JourneyRemote({
9719
10190
  initialOptions,
9720
10191
  onDiscountCodeApply,
9721
10192
  loadingComponent,
9722
- errorComponent
10193
+ errorComponent,
10194
+ capture
9723
10195
  }) {
9724
- const state = useJourneyConfig({ apiKey, journeyId, baseUrl });
10196
+ const resolvedBaseUrl = resolveJourneyBaseUrl(baseUrl);
10197
+ const captureEnabled = capture !== false;
10198
+ const state = useJourneyConfig({
10199
+ apiKey,
10200
+ journeyId,
10201
+ baseUrl: resolvedBaseUrl,
10202
+ config,
10203
+ capture: captureEnabled
10204
+ });
10205
+ const captureOption = capture === false ? false : __spreadValues({
10206
+ apiKey,
10207
+ journeyId,
10208
+ baseUrl: resolvedBaseUrl
10209
+ }, capture != null ? capture : {});
10210
+ const capturedOnEvent = useJourneyCapture({
10211
+ config: state.status === "ready" ? state.config : null,
10212
+ capture: captureOption,
10213
+ onEvent
10214
+ });
9725
10215
  if (state.status === "loading") {
9726
10216
  return /* @__PURE__ */ jsx(Fragment, { children: loadingComponent != null ? loadingComponent : /* @__PURE__ */ jsx(DefaultLoading, {}) });
9727
10217
  }
@@ -9734,35 +10224,7 @@ function JourneyRemote({
9734
10224
  config: state.config,
9735
10225
  storageKey,
9736
10226
  theme,
9737
- onEvent,
9738
- initialAnswers,
9739
- initialOptions,
9740
- onDiscountCodeApply,
9741
- children: /* @__PURE__ */ jsx(JourneyShell, { className, theme })
9742
- }
9743
- );
9744
- }
9745
- function Journey(props) {
9746
- if ("apiKey" in props && props.apiKey) {
9747
- return /* @__PURE__ */ jsx(JourneyRemote, __spreadValues({}, props));
9748
- }
9749
- const {
9750
- config,
9751
- storageKey,
9752
- onEvent,
9753
- className,
9754
- theme,
9755
- initialAnswers,
9756
- initialOptions,
9757
- onDiscountCodeApply
9758
- } = props;
9759
- return /* @__PURE__ */ jsx(
9760
- JourneyProvider,
9761
- {
9762
- config,
9763
- storageKey,
9764
- theme,
9765
- onEvent,
10227
+ onEvent: capturedOnEvent,
9766
10228
  initialAnswers,
9767
10229
  initialOptions,
9768
10230
  onDiscountCodeApply,