@veroxm/react-sdk 1.5.0 → 1.7.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/CHANGELOG.md +16 -0
- package/README.md +19 -0
- package/dist/client-slots.js +12 -2
- package/dist/client.js +6 -2
- package/dist/form.d.ts +6 -0
- package/dist/form.js +11 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/journey.d.ts +76 -0
- package/dist/journey.js +114 -0
- package/dist/site/map-math.js +2 -1
- package/dist/site/nav-menu.js +8 -1
- package/dist/slots-core.js +8 -1
- package/dist/tracking.d.ts +42 -0
- package/dist/tracking.js +26 -0
- package/dist/types.d.ts +5 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.7.0
|
|
4
|
+
|
|
5
|
+
- Product journeys: `<VeroxmJourney src="https://buy.example.com/ar/sports-insurance" />` (or `baseUrl` + `journey`)
|
|
6
|
+
shows a VeroXM quote-and-buy journey in your page, as published: its screens, shared blocks, brand and colours. It
|
|
7
|
+
runs in a frame of the hosted page, so prices, eligibility and payment links stay with VeroXM. `lang`, `chrome={false}`
|
|
8
|
+
(only the journey, for a page with its own header), `height`, and `onReady`, `onScreen`, `onLocaleChange`,
|
|
9
|
+
`onComplete`, `onEvent` (screen ids and steps, never what the person typed). The finish is recorded as
|
|
10
|
+
`$journey_completed` with the `<VeroxmTrackerProvider>`'s tracker (`track={false}` to skip). The journey must list
|
|
11
|
+
your site under Embedding; needs the VeroXM version with embeddable journeys (2026-10-27).
|
|
12
|
+
|
|
13
|
+
## 1.6.0
|
|
14
|
+
|
|
15
|
+
- Query text: `useEntries(collection, { q })`, `listEntries` and the server helpers take `q`, one readable line instead
|
|
16
|
+
of `where` and `sort`: `city = "Riyadh" AND area >= 500 ORDER BY area DESC`. `q` is only sent when given, so other
|
|
17
|
+
requests (and servers from before query text) are unchanged.
|
|
18
|
+
|
|
3
19
|
## 1.5.0
|
|
4
20
|
|
|
5
21
|
- Content in Server Components, from `@veroxm/react-sdk/next`: `getEntries`, `getEntry`, `getCollection`,
|
package/README.md
CHANGED
|
@@ -282,6 +282,25 @@ function Account() {
|
|
|
282
282
|
</SignedIn>;
|
|
283
283
|
```
|
|
284
284
|
|
|
285
|
+
## Product journeys
|
|
286
|
+
|
|
287
|
+
A VeroXM quote-and-buy journey in your page, as published (its screens, shared blocks, brand and colours):
|
|
288
|
+
|
|
289
|
+
```tsx
|
|
290
|
+
import { VeroxmJourney } from '@veroxm/react-sdk';
|
|
291
|
+
|
|
292
|
+
<VeroxmJourney src="https://buy.example.com/ar/sports-insurance" />
|
|
293
|
+
|
|
294
|
+
// Or by its link, without the brand around it, for a page with its own header:
|
|
295
|
+
<VeroxmJourney baseUrl="https://cms.example.com" journey="j_Ab3dEf7hJk9mNpQr2sTu" lang="en" chrome={false}
|
|
296
|
+
height={720} onScreen={(e) => console.log(e.step)} onComplete={() => router.push('/thank-you')} />
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
It runs in a frame of the hosted journey: prices, eligibility and payment links stay with VeroXM, and events carry
|
|
300
|
+
screen ids and steps only, never what the person typed. List your site's origin under **Embedding** in the journey's
|
|
301
|
+
Look and brand (or in its page layout), or the browser refuses to show it. Works the same in Next.js (a client
|
|
302
|
+
component). The finish is recorded as `$journey_completed` with the `<VeroxmTrackerProvider>`'s tracker.
|
|
303
|
+
|
|
285
304
|
## Visitor tracking
|
|
286
305
|
|
|
287
306
|
Pair with `@veroxm/sdk`'s `createTracker()` (see that package's README for
|
package/dist/client-slots.js
CHANGED
|
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore
|
|
|
4
4
|
import { fallbackValues, field, mergeSlotValues } from './slots-core.js';
|
|
5
5
|
import { EDITING_FLAG_COOKIE, PREVIEW_COOKIE, ROUTE_BASE } from './editor/constants.js';
|
|
6
6
|
import { VeroxmEditorOverlay, resetSentFallbacksForTests } from './editor/overlay.js';
|
|
7
|
+
import { useSlotImpression } from './tracking.js';
|
|
7
8
|
// @veroxm/react-sdk/client -- visual slots for client-rendered React apps
|
|
8
9
|
// (Vite, CRA...) whose server runs the /api/veroxm middleware from
|
|
9
10
|
// '@veroxm/react-sdk/node'. The browser never holds an API key: published
|
|
@@ -45,7 +46,7 @@ let routeBase = ROUTE_BASE;
|
|
|
45
46
|
/** Where the server mounted veroxmMiddleware. Default '/api/veroxm'. */
|
|
46
47
|
export function configureClientSlots(options) {
|
|
47
48
|
if (options.routeBase)
|
|
48
|
-
routeBase = options.routeBase
|
|
49
|
+
routeBase = withoutTrailingSlashes(options.routeBase);
|
|
49
50
|
}
|
|
50
51
|
const pending = new Map();
|
|
51
52
|
let scheduled = false;
|
|
@@ -154,7 +155,9 @@ export function useVeroxmSlot(name, options) {
|
|
|
154
155
|
* it loads), or the draft plus the on-page editor during "Edit on page".
|
|
155
156
|
*/
|
|
156
157
|
export function VeroxmSlot({ name, children, ...options }) {
|
|
157
|
-
const { values, slot, editing } = useVeroxmSlot(name, options);
|
|
158
|
+
const { values, slot, editing, loading } = useVeroxmSlot(name, options);
|
|
159
|
+
// $slot_impression once what the visitor sees is known (needs a <VeroxmTrackerProvider>; nothing while editing).
|
|
160
|
+
useSlotImpression(editing || loading ? null : name, slot.test);
|
|
158
161
|
if (!editing)
|
|
159
162
|
return children(values, slot);
|
|
160
163
|
return (_jsxs(_Fragment, { children: [_jsx("div", { "data-veroxm-slot": name, "data-veroxm-label": options.label ?? '', "data-veroxm-locale": options.locale ?? '', "data-veroxm-shown": JSON.stringify(values), "data-veroxm-fallback": JSON.stringify(fallbackValues(options.fields, options.fallback)), style: { display: 'contents' }, children: children(values, slot) }), _jsx(VeroxmEditorOverlay, { onChange: bump })] }));
|
|
@@ -167,3 +170,10 @@ export function resetClientSlotsForTests() {
|
|
|
167
170
|
routeBase = ROUTE_BASE;
|
|
168
171
|
resetSentFallbacksForTests();
|
|
169
172
|
}
|
|
173
|
+
/** `url` without trailing slashes (a loop: /\/+$/ goes over a long run of slashes again from each position). */
|
|
174
|
+
function withoutTrailingSlashes(url) {
|
|
175
|
+
let end = url.length;
|
|
176
|
+
while (end > 0 && url[end - 1] === '/')
|
|
177
|
+
end--;
|
|
178
|
+
return url.slice(0, end);
|
|
179
|
+
}
|
package/dist/client.js
CHANGED
|
@@ -113,14 +113,18 @@ export class VeroxmClient {
|
|
|
113
113
|
// query -- see EntriesQueryOptions.withTotalCount and
|
|
114
114
|
// content.resolver.ts's @ResolveField.
|
|
115
115
|
const totalCountField = options.withTotalCount ? ' totalCount' : '';
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
// q only when given: a server from before query text doesn't know the argument, and every other request stays
|
|
117
|
+
// exactly as it was.
|
|
118
|
+
const q = options.q ? { declare: ', $q: String', pass: ', q: $q' } : { declare: '', pass: '' };
|
|
119
|
+
const data = await this.request(`query Entries($collection: String!, $where: [WhereClauseInput!], $sort: String, $locale: String, $state: String, $offset: Int, $limit: Int, $timestamps: Boolean${q.declare}) {
|
|
120
|
+
entries(collection: $collection, where: $where, sort: $sort, locale: $locale, state: $state, offset: $offset, limit: $limit, timestamps: $timestamps${q.pass}) {
|
|
118
121
|
items { ${ENTRY_FIELDS} }${totalCountField}
|
|
119
122
|
}
|
|
120
123
|
}`, {
|
|
121
124
|
collection,
|
|
122
125
|
where: options.where,
|
|
123
126
|
sort: options.sort,
|
|
127
|
+
...(options.q ? { q: options.q } : {}),
|
|
124
128
|
locale: options.locale,
|
|
125
129
|
state: options.state,
|
|
126
130
|
offset: options.offset,
|
package/dist/form.d.ts
CHANGED
|
@@ -43,6 +43,12 @@ export interface VeroxmFormOptions {
|
|
|
43
43
|
endingId: string | null;
|
|
44
44
|
}) => void;
|
|
45
45
|
onClose?: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Record the send as `$form_submitted` (usable as an experience's goal) with the `<VeroxmTrackerProvider>`'s
|
|
48
|
+
* tracker -- or, without one, the VeroXM script tag's. Default true; false records nothing.
|
|
49
|
+
* @since 1.5.0
|
|
50
|
+
*/
|
|
51
|
+
track?: boolean;
|
|
46
52
|
}
|
|
47
53
|
type EmbedApi = {
|
|
48
54
|
embed(options: Record<string, unknown>): VeroxmFormHandle;
|
package/dist/form.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { useTracker } from './tracking.js';
|
|
4
5
|
const embedApi = () => window.VeroXMForms;
|
|
5
6
|
const loading = new Map();
|
|
6
7
|
/** Loads <baseUrl>/f/embed.js once per page. @internal */
|
|
@@ -45,9 +46,12 @@ export function useVeroxmForm(options, refs = {}) {
|
|
|
45
46
|
// Callbacks change on every render; the embed keeps calling the latest ones.
|
|
46
47
|
const latest = useRef(options);
|
|
47
48
|
latest.current = options;
|
|
49
|
+
const current = useTracker();
|
|
50
|
+
const tracker = useRef(current);
|
|
51
|
+
tracker.current = current;
|
|
48
52
|
const { baseUrl, form, mode = 'inline' } = options;
|
|
49
53
|
// What the embed is made from: a change re-creates it.
|
|
50
|
-
const key = JSON.stringify([baseUrl, form, mode, options.hidden, options.lang, options.height, options.autoHeight, options.size, options.position, options.openOn, options.rememberDismissDays, options.autoCloseSeconds, options.title]);
|
|
54
|
+
const key = JSON.stringify([baseUrl, form, mode, options.hidden, options.lang, options.height, options.autoHeight, options.size, options.position, options.openOn, options.rememberDismissDays, options.autoCloseSeconds, options.title, options.track]);
|
|
51
55
|
const { container, trigger } = refs;
|
|
52
56
|
const needsContainer = mode === 'inline';
|
|
53
57
|
useEffect(() => {
|
|
@@ -71,6 +75,12 @@ export function useVeroxmForm(options, refs = {}) {
|
|
|
71
75
|
},
|
|
72
76
|
onStarted: () => latest.current.onStarted?.(),
|
|
73
77
|
onSubmit: (r) => latest.current.onSubmit?.(r),
|
|
78
|
+
// $form_submitted through the <VeroxmTrackerProvider>'s tracker (unless track={false}).
|
|
79
|
+
tracker: latest.current.track === false
|
|
80
|
+
? false
|
|
81
|
+
: tracker.current.formSubmitted
|
|
82
|
+
? { formSubmitted: (f, r) => tracker.current.formSubmitted?.(f, r) }
|
|
83
|
+
: undefined,
|
|
74
84
|
onClose: () => latest.current.onClose?.(),
|
|
75
85
|
});
|
|
76
86
|
}, (e) => !cancelled && setError(e));
|
package/dist/index.d.ts
CHANGED
|
@@ -42,8 +42,10 @@ export type { VideoRef, VideoProvider } from './site/video.js';
|
|
|
42
42
|
export type { CollectionFieldMeta, CollectionMeta, Entry, EntryConnection, EntriesQueryOptions, MediaView, MediaHotspot, WhereClause, } from './types.js';
|
|
43
43
|
export { VeroxmForm, useVeroxmForm } from './form.js';
|
|
44
44
|
export type { VeroxmFormProps, VeroxmFormOptions, VeroxmFormMode, VeroxmFormHandle } from './form.js';
|
|
45
|
-
export {
|
|
46
|
-
export type {
|
|
45
|
+
export { VeroxmJourney } from './journey.js';
|
|
46
|
+
export type { VeroxmJourneyProps, VeroxmJourneyEvent } from './journey.js';
|
|
47
|
+
export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, useSlotImpression, VeroxmSlotImpression, } from './tracking.js';
|
|
48
|
+
export type { VeroxmTrackerProviderProps, VeroxmTrackerLike, ExperienceDecision, ExperienceState, ExperienceProps, RecommendationsState, VeroxmSlotImpressionProps, } from './tracking.js';
|
|
47
49
|
export { VeroxmSlot, useSlot, field, configureSlots, loadSlot, mergeSlotValues } from './slots.js';
|
|
48
50
|
export { defineComponent } from './slots.js';
|
|
49
51
|
export { VeroxmRegion, renderComponent, regionSlotProps } from './components.js';
|
package/dist/index.js
CHANGED
|
@@ -28,8 +28,10 @@ export { chartSvg, chartSummary, formatChartNumber, chartFromRows, chartDataFrom
|
|
|
28
28
|
export { parseVideoUrl, videoEmbedUrl, videoThumbnailUrl } from './site/video.js';
|
|
29
29
|
// Forms: inline, popup, full page or toast, through the embed script of your VeroXM address.
|
|
30
30
|
export { VeroxmForm, useVeroxmForm } from './form.js';
|
|
31
|
+
// Product journeys: a quote-and-buy journey in your page, in a frame of its hosted page.
|
|
32
|
+
export { VeroxmJourney } from './journey.js';
|
|
31
33
|
// Experience OS visitor tracking -- pair with @veroxm/sdk's createTracker().
|
|
32
|
-
export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, } from './tracking.js';
|
|
34
|
+
export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, useSlotImpression, VeroxmSlotImpression, } from './tracking.js';
|
|
33
35
|
// Visual slots (Experience Layer): named regions marketers edit from VeroXM.
|
|
34
36
|
export { VeroxmSlot, useSlot, field, configureSlots, loadSlot, mergeSlotValues } from './slots.js';
|
|
35
37
|
// Registered components: marketers choose which one shows in a region, and fill in its fields.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
/** What the journey tells your page (never what the person typed). */
|
|
3
|
+
export type VeroxmJourneyEvent = {
|
|
4
|
+
event: 'ready';
|
|
5
|
+
journey: string;
|
|
6
|
+
locale: string;
|
|
7
|
+
} | {
|
|
8
|
+
event: 'screen';
|
|
9
|
+
journey: string;
|
|
10
|
+
screen: string;
|
|
11
|
+
step: string | null;
|
|
12
|
+
dialog: string | null;
|
|
13
|
+
} | {
|
|
14
|
+
event: 'locale';
|
|
15
|
+
journey: string;
|
|
16
|
+
locale: string;
|
|
17
|
+
} | {
|
|
18
|
+
event: 'complete';
|
|
19
|
+
journey: string;
|
|
20
|
+
};
|
|
21
|
+
export interface VeroxmJourneyProps {
|
|
22
|
+
/**
|
|
23
|
+
* The journey's address: its readable one (`https://buy.example.com/en/sports-insurance`) or its link
|
|
24
|
+
* (`https://cms.example.com/j/j_Ab3dEf7hJk9mNpQr2sTu`).
|
|
25
|
+
*/
|
|
26
|
+
src?: string;
|
|
27
|
+
/** Or your VeroXM address and the journey's public id (j_...). */
|
|
28
|
+
baseUrl?: string;
|
|
29
|
+
journey?: string;
|
|
30
|
+
/** The language to show ("ar"), when the journey has it; otherwise the address's, then the visitor's browser's. */
|
|
31
|
+
lang?: string;
|
|
32
|
+
/** false: only the journey -- no logo, side stepper, footer links or top icons -- for a page with its own header. */
|
|
33
|
+
chrome?: boolean;
|
|
34
|
+
/** The frame's height: pixels or any CSS length (default 760). `"100%"` fills a sized parent. */
|
|
35
|
+
height?: number | string;
|
|
36
|
+
/** The frame's name for screen readers (default "Insurance quote"). */
|
|
37
|
+
title?: string;
|
|
38
|
+
className?: string;
|
|
39
|
+
style?: CSSProperties;
|
|
40
|
+
onReady?: (e: Extract<VeroxmJourneyEvent, {
|
|
41
|
+
event: 'ready';
|
|
42
|
+
}>) => void;
|
|
43
|
+
onScreen?: (e: Extract<VeroxmJourneyEvent, {
|
|
44
|
+
event: 'screen';
|
|
45
|
+
}>) => void;
|
|
46
|
+
onLocaleChange?: (e: Extract<VeroxmJourneyEvent, {
|
|
47
|
+
event: 'locale';
|
|
48
|
+
}>) => void;
|
|
49
|
+
onComplete?: (e: Extract<VeroxmJourneyEvent, {
|
|
50
|
+
event: 'complete';
|
|
51
|
+
}>) => void;
|
|
52
|
+
/** Every event, as it comes. */
|
|
53
|
+
onEvent?: (e: VeroxmJourneyEvent) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Record the finish as `$journey_completed` (usable as an experience's goal) with the `<VeroxmTrackerProvider>`'s
|
|
56
|
+
* tracker. Default true; false records nothing.
|
|
57
|
+
*/
|
|
58
|
+
track?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The frame's address: the journey's, with ?embed=1, the language, chrome=0 and the page's own origin (where the
|
|
62
|
+
* journey sends its events). Null when neither src nor baseUrl + journey make an http(s) address. @internal
|
|
63
|
+
*/
|
|
64
|
+
export declare function journeyFrameUrl(p: Pick<VeroxmJourneyProps, 'src' | 'baseUrl' | 'journey' | 'lang' | 'chrome'>, parent: string | null): URL | null;
|
|
65
|
+
/** A message from the journey's frame, checked: from its origin and window, in the journey's own format. @internal */
|
|
66
|
+
export declare function journeyEventOf(data: unknown): VeroxmJourneyEvent | null;
|
|
67
|
+
/**
|
|
68
|
+
* A VeroXM product journey in your page.
|
|
69
|
+
*
|
|
70
|
+
* ```tsx
|
|
71
|
+
* <VeroxmJourney src="https://buy.example.com/ar/sports-insurance" />
|
|
72
|
+
* <VeroxmJourney baseUrl="https://cms.example.com" journey="j_Ab3dEf7hJk9mNpQr2sTu" lang="en" chrome={false}
|
|
73
|
+
* onComplete={() => router.push('/thank-you')} />
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function VeroxmJourney({ src, baseUrl, journey, lang, chrome, height, title, className, style, track, ...handlers }: VeroxmJourneyProps): import("react").JSX.Element;
|
package/dist/journey.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { useTracker } from './tracking.js';
|
|
5
|
+
const LANG_PATH = /^\/([a-z]{2,3}(?:-[A-Za-z]{2,4})?)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)\/?$/;
|
|
6
|
+
/**
|
|
7
|
+
* The frame's address: the journey's, with ?embed=1, the language, chrome=0 and the page's own origin (where the
|
|
8
|
+
* journey sends its events). Null when neither src nor baseUrl + journey make an http(s) address. @internal
|
|
9
|
+
*/
|
|
10
|
+
export function journeyFrameUrl(p, parent) {
|
|
11
|
+
let url;
|
|
12
|
+
try {
|
|
13
|
+
if (p.src)
|
|
14
|
+
url = new URL(p.src);
|
|
15
|
+
else if (p.baseUrl && p.journey && /^j_[A-Za-z0-9]{20}$/.test(p.journey))
|
|
16
|
+
url = new URL(`/j/${p.journey}`, p.baseUrl);
|
|
17
|
+
else
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:')
|
|
24
|
+
return null;
|
|
25
|
+
if (p.lang) {
|
|
26
|
+
// A readable address carries the language in its path (/ar/sports-insurance); a link takes ?lang=.
|
|
27
|
+
const at = LANG_PATH.exec(url.pathname);
|
|
28
|
+
if (at)
|
|
29
|
+
url.pathname = `/${p.lang}/${at[2]}`;
|
|
30
|
+
else
|
|
31
|
+
url.searchParams.set('lang', p.lang);
|
|
32
|
+
}
|
|
33
|
+
url.searchParams.set('embed', '1');
|
|
34
|
+
if (p.chrome === false)
|
|
35
|
+
url.searchParams.set('chrome', '0');
|
|
36
|
+
if (parent)
|
|
37
|
+
url.searchParams.set('parent', parent);
|
|
38
|
+
return url;
|
|
39
|
+
}
|
|
40
|
+
/** A message from the journey's frame, checked: from its origin and window, in the journey's own format. @internal */
|
|
41
|
+
export function journeyEventOf(data) {
|
|
42
|
+
const d = data;
|
|
43
|
+
if (!d || typeof d !== 'object' || d.source !== 'veroxm-journey' || d.version !== 1 || typeof d.journey !== 'string')
|
|
44
|
+
return null;
|
|
45
|
+
const journey = d.journey;
|
|
46
|
+
const str = (v) => (typeof v === 'string' ? v : null);
|
|
47
|
+
switch (d.event) {
|
|
48
|
+
case 'ready':
|
|
49
|
+
return { event: 'ready', journey, locale: str(d.locale) ?? '' };
|
|
50
|
+
case 'screen':
|
|
51
|
+
return typeof d.screen === 'string' ? { event: 'screen', journey, screen: d.screen, step: str(d.step), dialog: str(d.dialog) } : null;
|
|
52
|
+
case 'locale':
|
|
53
|
+
return { event: 'locale', journey, locale: str(d.locale) ?? '' };
|
|
54
|
+
case 'complete':
|
|
55
|
+
return { event: 'complete', journey };
|
|
56
|
+
default:
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A VeroXM product journey in your page.
|
|
62
|
+
*
|
|
63
|
+
* ```tsx
|
|
64
|
+
* <VeroxmJourney src="https://buy.example.com/ar/sports-insurance" />
|
|
65
|
+
* <VeroxmJourney baseUrl="https://cms.example.com" journey="j_Ab3dEf7hJk9mNpQr2sTu" lang="en" chrome={false}
|
|
66
|
+
* onComplete={() => router.push('/thank-you')} />
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function VeroxmJourney({ src, baseUrl, journey, lang, chrome, height = 760, title = 'Insurance quote', className, style, track = true, ...handlers }) {
|
|
70
|
+
const frame = useRef(null);
|
|
71
|
+
// The page's own origin is known only in the browser: the frame is made there.
|
|
72
|
+
const [parent, setParent] = useState(null);
|
|
73
|
+
useEffect(() => setParent(window.location.origin), []);
|
|
74
|
+
const url = useMemo(() => (parent ? journeyFrameUrl({ src, baseUrl, journey, lang, chrome }, parent) : null), [src, baseUrl, journey, lang, chrome, parent]);
|
|
75
|
+
// Handlers change on every render; the listener calls the latest ones.
|
|
76
|
+
const latest = useRef({ handlers, track });
|
|
77
|
+
latest.current = { handlers, track };
|
|
78
|
+
const tracker = useTracker();
|
|
79
|
+
const trackerRef = useRef(tracker);
|
|
80
|
+
trackerRef.current = tracker;
|
|
81
|
+
const origin = url?.origin;
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!origin)
|
|
84
|
+
return;
|
|
85
|
+
const onMessage = (m) => {
|
|
86
|
+
if (m.origin !== origin || m.source !== frame.current?.contentWindow)
|
|
87
|
+
return;
|
|
88
|
+
const e = journeyEventOf(m.data);
|
|
89
|
+
if (!e)
|
|
90
|
+
return;
|
|
91
|
+
const h = latest.current.handlers;
|
|
92
|
+
h.onEvent?.(e);
|
|
93
|
+
if (e.event === 'ready')
|
|
94
|
+
h.onReady?.(e);
|
|
95
|
+
else if (e.event === 'screen')
|
|
96
|
+
h.onScreen?.(e);
|
|
97
|
+
else if (e.event === 'locale')
|
|
98
|
+
h.onLocaleChange?.(e);
|
|
99
|
+
else if (e.event === 'complete') {
|
|
100
|
+
if (latest.current.track)
|
|
101
|
+
trackerRef.current.track('$journey_completed', { journey: e.journey });
|
|
102
|
+
h.onComplete?.(e);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
window.addEventListener('message', onMessage);
|
|
106
|
+
return () => window.removeEventListener('message', onMessage);
|
|
107
|
+
}, [origin]);
|
|
108
|
+
const box = { display: 'block', width: '100%', height: typeof height === 'number' ? `${height}px` : height, border: 0, ...style };
|
|
109
|
+
if (!url)
|
|
110
|
+
return _jsx("div", { className: className, style: box, "data-veroxm-journey-box": "" });
|
|
111
|
+
return (_jsx("iframe", { ref: frame, src: url.toString(), title: title, className: className, style: box,
|
|
112
|
+
// Payment links open in a new tab; copy-link buttons use the clipboard.
|
|
113
|
+
allow: "clipboard-write", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", referrerPolicy: "strict-origin-when-cross-origin", "data-veroxm-journey": "" }));
|
|
114
|
+
}
|
package/dist/site/map-math.js
CHANGED
|
@@ -17,7 +17,8 @@ const round6 = (v) => Math.round(v * 1e6) / 1e6;
|
|
|
17
17
|
*/
|
|
18
18
|
export function parseMapLink(input) {
|
|
19
19
|
const text = input.trim();
|
|
20
|
-
|
|
20
|
+
// "lat, lng" or "lat lng": a comma with any spaces, or spaces alone (one way to match each, so no slow backtracking).
|
|
21
|
+
const pair = /^(-?\d{1,2}(?:\.\d+)?)(?:\s*,\s*|\s+)(-?\d{1,3}(?:\.\d+)?)$/.exec(text);
|
|
21
22
|
if (pair) {
|
|
22
23
|
const lat = Number(pair[1]);
|
|
23
24
|
const lng = Number(pair[2]);
|
package/dist/site/nav-menu.js
CHANGED
|
@@ -12,7 +12,7 @@ export function isSafeMenuHref(href) {
|
|
|
12
12
|
const samePage = (href, current) => {
|
|
13
13
|
if (!current || !href.startsWith('/'))
|
|
14
14
|
return false;
|
|
15
|
-
const clean = (p) => p.split(/[?#]/)[0]
|
|
15
|
+
const clean = (p) => withoutTrailingSlashes(p.split(/[?#]/)[0]) || '/';
|
|
16
16
|
return clean(href) === clean(current);
|
|
17
17
|
};
|
|
18
18
|
function MenuLink({ item, currentPath, Link, onNavigate }) {
|
|
@@ -79,3 +79,10 @@ export function NavMenu({ items, label = 'Main', currentPath, linkComponent = 'a
|
|
|
79
79
|
return null;
|
|
80
80
|
return (_jsxs("nav", { ref: navRef, "aria-label": label, className: `vxs-nav${className ? ` ${className}` : ''}`, ...editProps, children: [_jsxs("button", { type: "button", className: "vxs-nav-toggle", "aria-expanded": mobileOpen, "aria-controls": `${id}-list`, onClick: () => setMobileOpen((v) => !v), children: [_jsx("span", { className: "vxs-burger", "aria-hidden": "true" }), _jsx("span", { className: "vxs-nav-toggle-text", children: toggleLabel })] }), list(items, '', 1)] }));
|
|
81
81
|
}
|
|
82
|
+
/** `url` without trailing slashes (a loop: /\/+$/ goes over a long run of slashes again from each position). */
|
|
83
|
+
function withoutTrailingSlashes(url) {
|
|
84
|
+
let end = url.length;
|
|
85
|
+
while (end > 0 && url[end - 1] === '/')
|
|
86
|
+
end--;
|
|
87
|
+
return url.slice(0, end);
|
|
88
|
+
}
|
package/dist/slots-core.js
CHANGED
|
@@ -62,7 +62,7 @@ function env(name) {
|
|
|
62
62
|
}
|
|
63
63
|
/** The effective slots configuration (configureSlots over environment variables). */
|
|
64
64
|
export function resolveSlotsConfig() {
|
|
65
|
-
const baseUrl = (config.baseUrl ?? env('VEROXM_API_BASE') ?? '')
|
|
65
|
+
const baseUrl = withoutTrailingSlashes(config.baseUrl ?? env('VEROXM_API_BASE') ?? '');
|
|
66
66
|
const projectId = config.projectId ?? env('VEROXM_PROJECT_ID') ?? '';
|
|
67
67
|
const apiKey = config.apiKey ?? env('VEROXM_API_KEY') ?? '';
|
|
68
68
|
return {
|
|
@@ -423,3 +423,10 @@ export function resetSlotsForTests() {
|
|
|
423
423
|
flushScheduled = false;
|
|
424
424
|
reportScheduled = false;
|
|
425
425
|
}
|
|
426
|
+
/** `url` without trailing slashes (a loop: /\/+$/ goes over a long run of slashes again from each position). */
|
|
427
|
+
function withoutTrailingSlashes(url) {
|
|
428
|
+
let end = url.length;
|
|
429
|
+
while (end > 0 && url[end - 1] === '/')
|
|
430
|
+
end--;
|
|
431
|
+
return url.slice(0, end);
|
|
432
|
+
}
|
package/dist/tracking.d.ts
CHANGED
|
@@ -33,6 +33,20 @@ export interface VeroxmTrackerLike {
|
|
|
33
33
|
subscribe?(listener: () => void): () => void;
|
|
34
34
|
/** Recommendations (Phase 3). Optional like getExperience. */
|
|
35
35
|
viewContent?(contentId: number, properties?: Record<string, unknown>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Standard events (@veroxm/sdk 1.10): `$slot_impression` and `$form_submitted`. Optional so older trackers still
|
|
38
|
+
* type-check; without them nothing is recorded.
|
|
39
|
+
* @since 1.5.0
|
|
40
|
+
*/
|
|
41
|
+
slotImpression?(slot: string, test?: {
|
|
42
|
+
experienceId: number;
|
|
43
|
+
variantId: number;
|
|
44
|
+
} | null): void;
|
|
45
|
+
/** @since 1.5.0 */
|
|
46
|
+
formSubmitted?(form: string, submission?: {
|
|
47
|
+
responseId?: string;
|
|
48
|
+
endingId?: string | null;
|
|
49
|
+
}): void;
|
|
36
50
|
getRecommendations?<TEntry = Record<string, unknown>>(collection: string, options?: {
|
|
37
51
|
limit?: number;
|
|
38
52
|
exclude?: number[];
|
|
@@ -125,6 +139,34 @@ export interface ExperienceProps<TContent, TConfig> {
|
|
|
125
139
|
* the fallback, so "control = the current site" needs no extra code.
|
|
126
140
|
*/
|
|
127
141
|
export declare function Experience<TContent = Record<string, unknown>, TConfig = Record<string, unknown>>({ placement, fallback, loading, timeoutMs, children, }: ExperienceProps<TContent, TConfig>): ReactElement;
|
|
142
|
+
/**
|
|
143
|
+
* Records that a slot was shown (`$slot_impression`), with the visitor's variant when it is under test. Pass null
|
|
144
|
+
* while there is nothing to count yet (still loading, or in the on-page editor). The tracker counts each slot and
|
|
145
|
+
* variant once per page view. `<VeroxmSlot>` from '@veroxm/react-sdk/client' does this for you.
|
|
146
|
+
* @since 1.5.0
|
|
147
|
+
*/
|
|
148
|
+
export declare function useSlotImpression(slot: string | null | undefined, test?: {
|
|
149
|
+
experienceId: number;
|
|
150
|
+
variantId: number;
|
|
151
|
+
} | null): void;
|
|
152
|
+
export interface VeroxmSlotImpressionProps {
|
|
153
|
+
/** The slot's name (`slot.name`). */
|
|
154
|
+
name: string;
|
|
155
|
+
/** The visitor's variant (`slot.test`), when the slot is under test. */
|
|
156
|
+
test?: {
|
|
157
|
+
experienceId: number;
|
|
158
|
+
variantId: number;
|
|
159
|
+
} | null;
|
|
160
|
+
/** True in VeroXM's on-page editor (`slot.editing`): nothing is recorded. */
|
|
161
|
+
editing?: boolean;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Records a `$slot_impression` for a slot rendered by a Server Component, which can't use the tracker itself:
|
|
165
|
+
* `{(values, slot) => <><Hero {...values} /><VeroxmSlotImpression name={slot.name} test={slot.test} editing={slot.editing} /></>}`.
|
|
166
|
+
* Renders nothing. Needs a `<VeroxmTrackerProvider>` above it.
|
|
167
|
+
* @since 1.5.0
|
|
168
|
+
*/
|
|
169
|
+
export declare function VeroxmSlotImpression({ name, test, editing }: VeroxmSlotImpressionProps): null;
|
|
128
170
|
/** Records one view of a CMS entry when it is shown (the signal behind recommendations). */
|
|
129
171
|
export declare function useContentView(contentId: number | null | undefined, properties?: Record<string, unknown>): void;
|
|
130
172
|
export interface RecommendationsState<TEntry> {
|
package/dist/tracking.js
CHANGED
|
@@ -104,6 +104,32 @@ export function Experience({ placement, fallback, loading, timeoutMs, children,
|
|
|
104
104
|
return _jsx(_Fragment, { children: fallback });
|
|
105
105
|
return _jsx(_Fragment, { children: children(d) });
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Records that a slot was shown (`$slot_impression`), with the visitor's variant when it is under test. Pass null
|
|
109
|
+
* while there is nothing to count yet (still loading, or in the on-page editor). The tracker counts each slot and
|
|
110
|
+
* variant once per page view. `<VeroxmSlot>` from '@veroxm/react-sdk/client' does this for you.
|
|
111
|
+
* @since 1.5.0
|
|
112
|
+
*/
|
|
113
|
+
export function useSlotImpression(slot, test) {
|
|
114
|
+
const tracker = useTracker();
|
|
115
|
+
const experienceId = test?.experienceId;
|
|
116
|
+
const variantId = test?.variantId;
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (!slot)
|
|
119
|
+
return;
|
|
120
|
+
tracker.slotImpression?.(slot, experienceId && variantId ? { experienceId, variantId } : null);
|
|
121
|
+
}, [slot, experienceId, variantId, tracker]);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Records a `$slot_impression` for a slot rendered by a Server Component, which can't use the tracker itself:
|
|
125
|
+
* `{(values, slot) => <><Hero {...values} /><VeroxmSlotImpression name={slot.name} test={slot.test} editing={slot.editing} /></>}`.
|
|
126
|
+
* Renders nothing. Needs a `<VeroxmTrackerProvider>` above it.
|
|
127
|
+
* @since 1.5.0
|
|
128
|
+
*/
|
|
129
|
+
export function VeroxmSlotImpression({ name, test, editing }) {
|
|
130
|
+
useSlotImpression(editing ? null : name, test);
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
107
133
|
/** Records one view of a CMS entry when it is shown (the signal behind recommendations). */
|
|
108
134
|
export function useContentView(contentId, properties) {
|
|
109
135
|
const tracker = useTracker();
|
package/dist/types.d.ts
CHANGED
|
@@ -57,6 +57,11 @@ export interface EntriesQueryOptions {
|
|
|
57
57
|
where?: WhereClause[];
|
|
58
58
|
/** e.g. "created_at:desc" or "title:asc,created_at:desc". */
|
|
59
59
|
sort?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Query text instead of `where` and `sort` (not both): `city = "Riyadh" AND area >= 500 ORDER BY area DESC`. Needs a
|
|
62
|
+
* VeroXM server with query text (October 2026 or later); without `q`, requests are exactly what they were.
|
|
63
|
+
*/
|
|
64
|
+
q?: string;
|
|
60
65
|
/** Omitted matches the project's default locale, same fallback semantics as the REST API -- see packages/sdk-js/src/content.ts's ListOptions.locale for the full explanation. */
|
|
61
66
|
locale?: string;
|
|
62
67
|
/** Pass "only_draft" to include unpublished entries; anything else (including omitted) returns published-only. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veroxm/react-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "React and Next.js SDK for VeroXM: content hooks, visual slots with A/B tests, the on-page editor, llms.txt and structured data.",
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"description": "React and Next.js SDK for VeroXM: content hooks, visual slots with A/B tests, the on-page editor, forms and product journeys, llms.txt and structured data.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veroxm",
|
|
7
7
|
"react",
|