@thg-agentic/hyper-personalisation-web 3.24.1 → 3.26.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 +100 -25
- package/dist/hp.min.js +3 -3
- package/dist/onsite-answers.min.js +1 -1
- package/dist/onsite-audiences.min.js +1 -0
- package/dist/onsite-render.min.js +2 -2
- package/dist/onsite-wheel.min.js +1 -1
- package/dist/onsite.min.js +1 -1
- package/package.json +4 -3
- package/src/bootstrap.js +114 -49
- package/src/consent-gate.js +8 -5
- package/src/context.js +2 -1
- package/src/device-storage.js +4 -4
- package/src/index.js +142 -10
- package/src/onsite/api.js +22 -5
- package/src/onsite/audiences-loader.js +6 -0
- package/src/onsite/counters.js +2 -2
- package/src/onsite/index.js +52 -1
- package/src/onsite/render.js +49 -18
- package/src/onsite/rules.js +20 -5
- package/src/onsite/visit-audiences.js +94 -0
- package/src/onsite/wheel.js +61 -13
- package/src/settings.js +30 -2
- package/src/shape.js +4 -0
- package/src/social-proof.js +5 -1
- package/src/spec-version.js +1 -1
- package/src/storage-scope.js +8 -2
- package/src/transport.js +22 -2
- package/src/version.js +1 -1
- package/src/visit-campaign.js +168 -0
- package/types/bootstrap.d.ts +10 -2
- package/types/events.d.ts +30 -2
- package/types/hp.d.ts +3 -2
- package/types/index.d.ts +10 -3
- package/types/onsite.d.ts +9 -0
package/types/bootstrap.d.ts
CHANGED
|
@@ -88,6 +88,13 @@ export interface Preset extends DataLayerPreset {
|
|
|
88
88
|
export interface Identity {
|
|
89
89
|
userId?: string | number | null;
|
|
90
90
|
emailSha256?: string | null;
|
|
91
|
+
/**
|
|
92
|
+
* The identity token your server signed for this user on this page view (ADR 0067): a JWT,
|
|
93
|
+
* ES256 with `typ: "JWT"` over `{ sub: userId, aud: "hyper-personalisation", exp }`. Without
|
|
94
|
+
* it the sign-in is recorded but never joins this device to the user's others, and a promo
|
|
95
|
+
* reminder's code is not shown. Since 3.26.
|
|
96
|
+
*/
|
|
97
|
+
token?: string | null;
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
export interface AutocaptureOptions {
|
|
@@ -165,8 +172,9 @@ export interface BootstrappedClient extends AnalyticsClient {
|
|
|
165
172
|
}
|
|
166
173
|
|
|
167
174
|
/**
|
|
168
|
-
* The client, or null when the key is not enabled
|
|
169
|
-
* visit
|
|
175
|
+
* The client, or null when the key is not enabled or the options are invalid. Settings that cannot
|
|
176
|
+
* be fetched on a first visit start it on built-in, collect-only defaults (3.25). Never rejects.
|
|
177
|
+
* Idempotent per page.
|
|
170
178
|
*/
|
|
171
179
|
export declare function bootstrap(
|
|
172
180
|
config: HpConfig,
|
package/types/events.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated from spec/registry.json by scripts/generate-sdk-models.mjs.
|
|
2
2
|
// DO NOT EDIT. Change the schema and regenerate — the schema is the contract,
|
|
3
3
|
// and a hand-edit here is an SDK that disagrees with the ingest.
|
|
4
|
-
// Spec version: 1.
|
|
4
|
+
// Spec version: 1.20
|
|
5
5
|
|
|
6
6
|
/** context.source.environment. Environment the producer runs in. */
|
|
7
7
|
export type CdpSourceEnvironment = 'production' | 'staging' | 'development';
|
|
@@ -91,6 +91,32 @@ export interface JourneyTriggered {
|
|
|
91
91
|
products?: CdpProduct[];
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/** The serving log: one ranked rail as the recommender answered it, with the features it ranked on, recorded when it was served rather than recomputed later. */
|
|
95
|
+
export interface RecommendationServed {
|
|
96
|
+
recommendation_request_id: string;
|
|
97
|
+
group: 'personalised' | 'holdout' | 'excluded';
|
|
98
|
+
personalised: boolean;
|
|
99
|
+
products: Record<string, unknown>[];
|
|
100
|
+
batch_request_id?: string | null;
|
|
101
|
+
placement?: string | null;
|
|
102
|
+
recipe_requested?: string | null;
|
|
103
|
+
recipe?: string | null;
|
|
104
|
+
strategy?: string | null;
|
|
105
|
+
algorithm_version?: string | null;
|
|
106
|
+
ranked_by?: 'ranker' | 'blend' | 'session' | 'manual' | 'other' | null;
|
|
107
|
+
fusion?: string | null;
|
|
108
|
+
fast_weight?: number | null;
|
|
109
|
+
found?: boolean | null;
|
|
110
|
+
degraded?: boolean | null;
|
|
111
|
+
person_id?: string | null;
|
|
112
|
+
decision_id?: string | null;
|
|
113
|
+
arm?: string | null;
|
|
114
|
+
propensity?: number;
|
|
115
|
+
limit?: number | null;
|
|
116
|
+
candidate_set_size?: number | null;
|
|
117
|
+
unserved?: Record<string, unknown>[] | null;
|
|
118
|
+
}
|
|
119
|
+
|
|
94
120
|
/** A visitor acted on a personalised surface: clicked it (for example opened a product from a rail), dismissed it, or submitted a step of an onsite form. */
|
|
95
121
|
export interface SlotEngaged {
|
|
96
122
|
decision_id: string;
|
|
@@ -686,12 +712,13 @@ export interface SignUpRelayed {
|
|
|
686
712
|
}
|
|
687
713
|
|
|
688
714
|
/** The spec version these models implement. SDKs stamp it on context.spec.version. */
|
|
689
|
-
export const SPEC_VERSION = '1.
|
|
715
|
+
export const SPEC_VERSION = '1.20';
|
|
690
716
|
|
|
691
717
|
/** Every event name the registry accepts. Anything else is rejected at the ingest. */
|
|
692
718
|
export type CdpEventName =
|
|
693
719
|
| 'Decision Made'
|
|
694
720
|
| 'Journey Triggered'
|
|
721
|
+
| 'Recommendation Served'
|
|
695
722
|
| 'Slot Engaged'
|
|
696
723
|
| 'Recommendations Viewed'
|
|
697
724
|
| 'Promotion Viewed'
|
|
@@ -755,6 +782,7 @@ export type CdpEventName =
|
|
|
755
782
|
export interface CdpEventProperties {
|
|
756
783
|
'Decision Made': DecisionMade;
|
|
757
784
|
'Journey Triggered': JourneyTriggered;
|
|
785
|
+
'Recommendation Served': RecommendationServed;
|
|
758
786
|
'Slot Engaged': SlotEngaged;
|
|
759
787
|
'Recommendations Viewed': RecommendationsViewed;
|
|
760
788
|
'Promotion Viewed': PromotionViewed;
|
package/types/hp.d.ts
CHANGED
|
@@ -35,8 +35,9 @@ interface HpTrack {
|
|
|
35
35
|
/**
|
|
36
36
|
* The page's client, callable from anywhere: calls made before `bootstrap` has started it wait and
|
|
37
37
|
* replay in order, keeping the messageId and time they were made with; on a page that turns out to
|
|
38
|
-
* be off they are dropped. A page that navigates first
|
|
39
|
-
*
|
|
38
|
+
* be off they are dropped. A page that navigates first carries them to the next page, which sends
|
|
39
|
+
* them under its own consent (3.9); one that cannot reach the API starts on built-in settings and
|
|
40
|
+
* sends them itself (3.25). Nothing is returned (but by
|
|
40
41
|
* `assignmentDecisionId` and `recommendationContext`), nothing is awaited, and nothing ever throws
|
|
41
42
|
* into the caller.
|
|
42
43
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -119,7 +119,8 @@ export interface AnalyticsOptions extends AnalyticsContextSources {
|
|
|
119
119
|
apiHost?: string;
|
|
120
120
|
/** Default 'web'. */
|
|
121
121
|
writeKey?: string;
|
|
122
|
-
|
|
122
|
+
/** null: none on the wire, and the ingest stamps the key's (a key scoped to one property). */
|
|
123
|
+
propertyId: string | number | null;
|
|
123
124
|
channel?: string | null;
|
|
124
125
|
market?: string | null;
|
|
125
126
|
environment?: string | null;
|
|
@@ -200,7 +201,7 @@ export interface AnalyticsOptions extends AnalyticsContextSources {
|
|
|
200
201
|
mintAnonymousId?: boolean;
|
|
201
202
|
/**
|
|
202
203
|
* Strict consent: carry events held for an unanswered CMP across a navigation, in sessionStorage
|
|
203
|
-
* per
|
|
204
|
+
* per write key (`thg_hp_held`), so a redirect before the answer (a sign-in) does not lose them.
|
|
204
205
|
* They leave only on a grant, on whichever page it comes, and are deleted on a refusal or after
|
|
205
206
|
* 30 minutes. This writes event data to the device before the visitor has answered: enable it
|
|
206
207
|
* only where your consent policy allows that. With bootstrap it also lets `hp` carry calls made
|
|
@@ -208,6 +209,12 @@ export interface AnalyticsOptions extends AnalyticsContextSources {
|
|
|
208
209
|
*/
|
|
209
210
|
holdAcrossPages?: boolean;
|
|
210
211
|
getUserId?(): string | null | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* The identity token your server signed for the user `getUserId` names (a JWT, ADR 0067), read
|
|
214
|
+
* once: sent on each identify and with each onsite decision until `reset()`, a sign-out or
|
|
215
|
+
* another user's `identify`. A later sign-in passes its own on `identify`. Since 3.26.
|
|
216
|
+
*/
|
|
217
|
+
identityToken?: string | null;
|
|
211
218
|
/** Observer for every event that will be sent. Must not throw; failures are swallowed. */
|
|
212
219
|
onEvent?(event: CdpEvent): void;
|
|
213
220
|
|
|
@@ -466,7 +473,7 @@ export interface StorageNames {
|
|
|
466
473
|
decisions?: string;
|
|
467
474
|
/** localStorage. Default 'thg_hp_settings'. */
|
|
468
475
|
settings?: string;
|
|
469
|
-
/** sessionStorage, with holdAcrossPages. Default 'thg_hp_held'. */
|
|
476
|
+
/** sessionStorage, per write key, with holdAcrossPages. Default 'thg_hp_held'. */
|
|
470
477
|
held?: string;
|
|
471
478
|
/** sessionStorage: `hp` calls carried to the next page (3.9). Default 'thg_hp_carried'. */
|
|
472
479
|
carried?: string;
|
package/types/onsite.d.ts
CHANGED
|
@@ -47,6 +47,15 @@ export interface OnsiteForm {
|
|
|
47
47
|
pages?: { include?: string[]; exclude?: string[] };
|
|
48
48
|
/** `mobile` is a coarse pointer or a viewport under 768px. Absent: both. */
|
|
49
49
|
devices?: Array<'desktop' | 'mobile'>;
|
|
50
|
+
/**
|
|
51
|
+
* Shown only to a visit that arrived from a matching campaign: the landing page's `utm_*` tags,
|
|
52
|
+
* kept for the visit. Every rule must hold; any of a rule's values meets it, in any case.
|
|
53
|
+
*/
|
|
54
|
+
arrived_from?: Array<{
|
|
55
|
+
field: 'source' | 'medium' | 'campaign' | 'content' | 'term';
|
|
56
|
+
match: 'is' | 'contains';
|
|
57
|
+
values: string[];
|
|
58
|
+
}>;
|
|
50
59
|
/** Shown only with personalisation consent, and only to members as the server decides. */
|
|
51
60
|
audiences?: string[];
|
|
52
61
|
exclude_subscribed?: boolean;
|