@thg-agentic/hyper-personalisation-web 3.22.2 → 3.23.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/README.md +143 -1
- package/dist/hp.min.js +3 -3
- package/dist/onsite-answers.min.js +1 -0
- package/dist/onsite-render.min.js +178 -0
- package/dist/onsite-wheel.min.js +1 -0
- package/dist/onsite.min.js +1 -0
- package/dist/snippet.min.js +1 -1
- package/package.json +19 -3
- package/src/bootstrap.js +33 -2
- package/src/context.js +20 -7
- package/src/hp.js +2 -0
- package/src/index.js +96 -1
- package/src/onsite/answers-loader.js +6 -0
- package/src/onsite/answers.js +177 -0
- package/src/onsite/api.js +93 -0
- package/src/onsite/counters.js +144 -0
- package/src/onsite/index.js +446 -0
- package/src/onsite/pow.js +127 -0
- package/src/onsite/preview.js +97 -0
- package/src/onsite/render-loader.js +5 -0
- package/src/onsite/render.js +1234 -0
- package/src/onsite/rich-text.js +73 -0
- package/src/onsite/rules.js +237 -0
- package/src/onsite/styles.js +208 -0
- package/src/onsite/triggers.js +165 -0
- package/src/onsite/wheel-loader.js +5 -0
- package/src/onsite/wheel.js +148 -0
- package/src/onsite-facade.js +99 -0
- package/src/onsite-loader.js +5 -0
- package/src/settings.js +18 -0
- package/src/spec-version.js +1 -1
- package/src/storage-scope.js +5 -0
- package/src/version.js +1 -1
- package/types/bootstrap.d.ts +15 -1
- package/types/events.d.ts +68 -5
- package/types/hp.d.ts +4 -1
- package/types/index.d.ts +10 -0
- package/types/onsite-preview.d.ts +58 -0
- package/types/onsite-wheel.d.ts +11 -0
- package/types/onsite.d.ts +195 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type { AnalyticsClient } from './index';
|
|
2
|
+
|
|
3
|
+
/** RichText: plain text, bold, italic and https links. No markup: anything else is dropped. */
|
|
4
|
+
export type RichText =
|
|
5
|
+
| string
|
|
6
|
+
| Array<
|
|
7
|
+
string | { b: RichText } | { i: RichText } | { a: RichText; href: string }
|
|
8
|
+
>;
|
|
9
|
+
|
|
10
|
+
export type OnsiteFormat =
|
|
11
|
+
| 'popup'
|
|
12
|
+
| 'sheet'
|
|
13
|
+
| 'bar'
|
|
14
|
+
| 'teaser'
|
|
15
|
+
| 'inline'
|
|
16
|
+
| 'fullscreen';
|
|
17
|
+
|
|
18
|
+
export type OnsiteTriggerType =
|
|
19
|
+
| 'entry'
|
|
20
|
+
| 'exit'
|
|
21
|
+
| 'scroll'
|
|
22
|
+
| 'time'
|
|
23
|
+
| 'idle'
|
|
24
|
+
| 'inline'
|
|
25
|
+
| 'manual';
|
|
26
|
+
|
|
27
|
+
/** One live form, as the settings' `hp.onsite.forms[]` index carries it (ADR 0064). */
|
|
28
|
+
export interface OnsiteForm {
|
|
29
|
+
slot: string;
|
|
30
|
+
format: OnsiteFormat;
|
|
31
|
+
/** One overlay per page view: of the forms that fire together, the highest shows. */
|
|
32
|
+
priority?: number;
|
|
33
|
+
trigger: {
|
|
34
|
+
type: OnsiteTriggerType;
|
|
35
|
+
/** entry: the delay; exit: how long until exit intent arms (5000). */
|
|
36
|
+
delay_ms?: number;
|
|
37
|
+
/** scroll: the share of the page scrolled, 0–1 (0.5). */
|
|
38
|
+
depth?: number;
|
|
39
|
+
/** time and idle: seconds (30). */
|
|
40
|
+
seconds?: number;
|
|
41
|
+
/** inline: the element the form renders into. */
|
|
42
|
+
selector?: string;
|
|
43
|
+
};
|
|
44
|
+
/** Path globs, `*` matching anything. No `include` is every page; an exclusion wins. */
|
|
45
|
+
pages?: { include?: string[]; exclude?: string[] };
|
|
46
|
+
/** `mobile` is a coarse pointer or a viewport under 768px. Absent: both. */
|
|
47
|
+
devices?: Array<'desktop' | 'mobile'>;
|
|
48
|
+
/** Shown only with personalisation consent, and only to members as the server decides. */
|
|
49
|
+
audiences?: string[];
|
|
50
|
+
exclude_subscribed?: boolean;
|
|
51
|
+
caps?: { per_session?: number; lifetime?: number; after_close_days?: number };
|
|
52
|
+
window?: { starts_at?: string; ends_at?: string };
|
|
53
|
+
/**
|
|
54
|
+
* The form's language, BCP 47 (`en-IE`): its phone field starts on this region's country code,
|
|
55
|
+
* and a birthday's day and month follow its order and month names. Absent: the page's `lang`.
|
|
56
|
+
*/
|
|
57
|
+
locale?: string;
|
|
58
|
+
/** The words an email step asks agreement to; absent on a form that collects only `sms`. */
|
|
59
|
+
consent_text?: { id: string; version: number; text: string };
|
|
60
|
+
/** The words an SMS step asks agreement to; present when `channels` has `sms`. */
|
|
61
|
+
sms_consent_text?: { id: string; version: number; text: string };
|
|
62
|
+
/**
|
|
63
|
+
* A choice (`one`, `many`) has `options`; a `date` or `number` question has `format`. A date is
|
|
64
|
+
* answered as `YYYY-MM-DD`, or `--MM-DD` for a birthday without its year.
|
|
65
|
+
*/
|
|
66
|
+
questions?: Array<{
|
|
67
|
+
key: string;
|
|
68
|
+
type: 'one' | 'many' | 'date' | 'number';
|
|
69
|
+
label: string;
|
|
70
|
+
options?: Array<{ value: string; label: string }>;
|
|
71
|
+
format?: OnsiteQuestionFormat;
|
|
72
|
+
}>;
|
|
73
|
+
/** The wheel's labels only: odds and codes are the server's. */
|
|
74
|
+
prizes?: Array<{ key: string; label: string }>;
|
|
75
|
+
channels?: Array<'email' | 'sms'>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A date question's (`kind`: a `birthday`, its `year` not asked, optional or required, or any
|
|
80
|
+
* full `date`) or a number question's (`min`, `max`, `decimals`, `unit`).
|
|
81
|
+
*/
|
|
82
|
+
export interface OnsiteQuestionFormat {
|
|
83
|
+
kind?: 'birthday' | 'date';
|
|
84
|
+
year?: 'none' | 'optional' | 'required';
|
|
85
|
+
min?: number;
|
|
86
|
+
max?: number;
|
|
87
|
+
decimals?: boolean;
|
|
88
|
+
unit?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** `hp.onsite` in the SDK settings. */
|
|
92
|
+
export interface OnsiteSettings {
|
|
93
|
+
forms: OnsiteForm[];
|
|
94
|
+
/**
|
|
95
|
+
* Minutes a session waits after a popup, sheet or full-screen form (not a bar or teaser) before another may
|
|
96
|
+
* show. Absent: no limit; 1440: once per session.
|
|
97
|
+
*/
|
|
98
|
+
overlay_gap_minutes?: number;
|
|
99
|
+
capture?: { challenge?: string } | null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface OnsiteOptions {
|
|
103
|
+
/** Development and tests: these forms instead of the settings'. */
|
|
104
|
+
settings?: OnsiteSettings;
|
|
105
|
+
/** The public API for decisions and offer claims. Default: the host the SDK was pointed at. */
|
|
106
|
+
servingHost?: string;
|
|
107
|
+
/** The ingest gateway for capture. Default: where the SDK sends events. */
|
|
108
|
+
gatewayHost?: string;
|
|
109
|
+
/** The visitor's session audiences, when the page evaluates them: a form outside them is skipped. */
|
|
110
|
+
audiences?(): string[] | null | undefined;
|
|
111
|
+
/** Whether the page knows this visitor is already subscribed (a signed-in subscriber). */
|
|
112
|
+
subscribed?(): boolean;
|
|
113
|
+
/** Log why each form did or did not show. Also on with `?hp_debug=onsite` or the SDK's debug. */
|
|
114
|
+
debug?: boolean;
|
|
115
|
+
fetch?: typeof fetch;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** One form's state on this page, and why. */
|
|
119
|
+
export interface OnsiteTrace {
|
|
120
|
+
slot: string;
|
|
121
|
+
format?: OnsiteFormat;
|
|
122
|
+
trigger?: OnsiteTriggerType;
|
|
123
|
+
priority?: number;
|
|
124
|
+
state:
|
|
125
|
+
| 'armed'
|
|
126
|
+
| 'waiting for hp.onsite.open'
|
|
127
|
+
| 'asking for a decision'
|
|
128
|
+
| 'shown'
|
|
129
|
+
| 'closed'
|
|
130
|
+
| 'held out'
|
|
131
|
+
| 'no decision'
|
|
132
|
+
| 'not eligible'
|
|
133
|
+
| 'not shown'
|
|
134
|
+
| 'invalid';
|
|
135
|
+
reasons: string[];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface OnsiteController {
|
|
139
|
+
/** Show the form on `slot` now, whatever its trigger, if its rules allow it. */
|
|
140
|
+
open(slot: string): Promise<boolean>;
|
|
141
|
+
/** Each form's state on this page, and why. */
|
|
142
|
+
debug(): OnsiteTrace[];
|
|
143
|
+
/** Stop watching every trigger. A form on screen stays until it is closed. */
|
|
144
|
+
stop(): void;
|
|
145
|
+
/** Take every form off the screen, quietly (`hp.onsite.suppress` calls it). */
|
|
146
|
+
suppress(): void;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** What every `hp.onsite.on` listener is told. */
|
|
150
|
+
export interface OnsiteEventDetail {
|
|
151
|
+
slot: string;
|
|
152
|
+
arm: string | null;
|
|
153
|
+
format: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** A code a form handed out: the claimed prize, or a reminder's unused code. */
|
|
157
|
+
export interface OnsiteCoupon {
|
|
158
|
+
code: string | null;
|
|
159
|
+
prize?: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface OnsiteEvents {
|
|
163
|
+
shown: OnsiteEventDetail;
|
|
164
|
+
/** After the sign-up; for a form that spins, once the prize is claimed. */
|
|
165
|
+
submitted: OnsiteEventDetail & { coupon: OnsiteCoupon | null };
|
|
166
|
+
/** A reminder's apply button: put the code on the basket. */
|
|
167
|
+
apply: OnsiteEventDetail & { coupon: OnsiteCoupon | null };
|
|
168
|
+
closed: OnsiteEventDetail & { reason: string };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** `hp.onsite`, callable before the runtime has loaded. */
|
|
172
|
+
export interface OnsiteFacade {
|
|
173
|
+
open(slot: string): Promise<boolean>;
|
|
174
|
+
/** The same as `open`. */
|
|
175
|
+
show(slot: string): Promise<boolean>;
|
|
176
|
+
/** Listen to the forms; returns a function that stops listening. */
|
|
177
|
+
on<K extends keyof OnsiteEvents>(
|
|
178
|
+
name: K,
|
|
179
|
+
listener: (detail: OnsiteEvents[K]) => void,
|
|
180
|
+
): () => void;
|
|
181
|
+
/** Keep the screen clear for `reason` (default `page`): a form showing goes, and none shows until lifted. */
|
|
182
|
+
suppress(reason?: string): void;
|
|
183
|
+
/** Lift `reason`, or every reason. */
|
|
184
|
+
unsuppress(reason?: string): void;
|
|
185
|
+
debug(): OnsiteTrace[];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Start onsite forms for the client, once per page. Null without a browser, or for a client this
|
|
190
|
+
* SDK did not make.
|
|
191
|
+
*/
|
|
192
|
+
export declare function startOnsite(
|
|
193
|
+
client: AnalyticsClient,
|
|
194
|
+
options?: OnsiteOptions,
|
|
195
|
+
): OnsiteController | null;
|