@veroxm/react-sdk 1.5.0 → 1.6.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 +6 -0
- package/dist/client-slots.js +4 -1
- package/dist/client.js +6 -2
- package/dist/form.d.ts +6 -0
- package/dist/form.js +11 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/tracking.d.ts +42 -0
- package/dist/tracking.js +26 -0
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.6.0
|
|
4
|
+
|
|
5
|
+
- Query text: `useEntries(collection, { q })`, `listEntries` and the server helpers take `q`, one readable line instead
|
|
6
|
+
of `where` and `sort`: `city = "Riyadh" AND area >= 500 ORDER BY area DESC`. `q` is only sent when given, so other
|
|
7
|
+
requests (and servers from before query text) are unchanged.
|
|
8
|
+
|
|
3
9
|
## 1.5.0
|
|
4
10
|
|
|
5
11
|
- Content in Server Components, from `@veroxm/react-sdk/next`: `getEntries`, `getEntry`, `getCollection`,
|
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
|
|
@@ -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 })] }));
|
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,8 @@ 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 { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, } from './tracking.js';
|
|
46
|
-
export type { VeroxmTrackerProviderProps, VeroxmTrackerLike, ExperienceDecision, ExperienceState, ExperienceProps, RecommendationsState, } from './tracking.js';
|
|
45
|
+
export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, useSlotImpression, VeroxmSlotImpression, } from './tracking.js';
|
|
46
|
+
export type { VeroxmTrackerProviderProps, VeroxmTrackerLike, ExperienceDecision, ExperienceState, ExperienceProps, RecommendationsState, VeroxmSlotImpressionProps, } from './tracking.js';
|
|
47
47
|
export { VeroxmSlot, useSlot, field, configureSlots, loadSlot, mergeSlotValues } from './slots.js';
|
|
48
48
|
export { defineComponent } from './slots.js';
|
|
49
49
|
export { VeroxmRegion, renderComponent, regionSlotProps } from './components.js';
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ 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
31
|
// Experience OS visitor tracking -- pair with @veroxm/sdk's createTracker().
|
|
32
|
-
export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, } from './tracking.js';
|
|
32
|
+
export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, useSlotImpression, VeroxmSlotImpression, } from './tracking.js';
|
|
33
33
|
// Visual slots (Experience Layer): named regions marketers edit from VeroXM.
|
|
34
34
|
export { VeroxmSlot, useSlot, field, configureSlots, loadSlot, mergeSlotValues } from './slots.js';
|
|
35
35
|
// Registered components: marketers choose which one shows in a region, and fill in its fields.
|
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