@thg-agentic/hyper-personalisation-web 3.17.1 → 3.18.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 +68 -33
- package/dist/hp.min.js +3 -3
- package/package.json +2 -2
- package/src/bootstrap.js +33 -5
- package/src/debug.js +45 -0
- package/src/device-storage.js +34 -22
- package/src/index.js +37 -15
- package/src/sampling.js +19 -0
- package/src/segment.js +15 -2
- package/src/session/record.js +13 -0
- package/src/session/signals.js +4 -0
- package/src/session-id.js +2 -2
- package/src/settings.js +25 -6
- package/src/shape.js +16 -7
- package/src/spec-version.js +1 -1
- package/src/storage-scope.js +6 -1
- package/src/transport.js +16 -1
- package/src/version.js +1 -1
- package/types/bootstrap.d.ts +11 -0
- package/types/events.d.ts +35 -2
- package/types/index.d.ts +11 -4
package/types/bootstrap.d.ts
CHANGED
|
@@ -56,6 +56,13 @@ export interface SettingsResponse {
|
|
|
56
56
|
queryParamAllowlist?: string[];
|
|
57
57
|
/** Host for ingest and for the API. */
|
|
58
58
|
apiHost?: string;
|
|
59
|
+
/** The share of visitors sent for, decided per anonymous id (since 3.18). Absent: 1. */
|
|
60
|
+
sampleRate?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Console logging for everyone, or for a session opened with `?hp_debug=<token>` whose SHA-256
|
|
63
|
+
* is `tokenSha256` (since 3.18). Absent: off.
|
|
64
|
+
*/
|
|
65
|
+
debug?: { enabled: boolean; tokenSha256: string | null };
|
|
59
66
|
/** Each property's personalisation holdout, keyed by property id. */
|
|
60
67
|
holdouts?: Record<
|
|
61
68
|
string,
|
|
@@ -132,6 +139,10 @@ export interface BootstrapOptions {
|
|
|
132
139
|
dataLayer?: { name?: string; ignore?: string[] };
|
|
133
140
|
/** Rename what the SDK stores. Defaults are `thg_hp_*`. */
|
|
134
141
|
storageNames?: StorageNames;
|
|
142
|
+
/**
|
|
143
|
+
* Log every event to the console. Also on when the settings turn it on (`hp.debug`), for everyone
|
|
144
|
+
* or for a session opened with `?hp_debug=<token>`, without a release of the page.
|
|
145
|
+
*/
|
|
135
146
|
debug?: boolean;
|
|
136
147
|
/** Development and tests: use this settings response and never fetch or cache one. */
|
|
137
148
|
settings?: SettingsResponse;
|
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.10
|
|
5
5
|
|
|
6
6
|
/** The product shape shared by every commerce event. */
|
|
7
7
|
export interface CdpProduct {
|
|
@@ -36,6 +36,7 @@ export interface DecisionMade {
|
|
|
36
36
|
propensity: number;
|
|
37
37
|
arm: string;
|
|
38
38
|
kind?: 'recommendation' | 'search_rank' | 'banner' | 'offer' | 'layout' | 'copy' | 'price' | 'other' | null;
|
|
39
|
+
learning_reset_at?: string | null;
|
|
39
40
|
explored?: boolean | null;
|
|
40
41
|
context_features?: Record<string, unknown> | null;
|
|
41
42
|
context_key?: string | null;
|
|
@@ -565,8 +566,32 @@ export interface EmailMarkedAsSpam {
|
|
|
565
566
|
email_id?: string | null;
|
|
566
567
|
}
|
|
567
568
|
|
|
569
|
+
/** The app was launched for the first time after being installed. */
|
|
570
|
+
export interface ApplicationInstalled {
|
|
571
|
+
version: string;
|
|
572
|
+
build: string;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/** The app was launched, or came back to the foreground. */
|
|
576
|
+
export interface ApplicationOpened {
|
|
577
|
+
from_background: boolean;
|
|
578
|
+
version: string;
|
|
579
|
+
build: string;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** The app went to the background. */
|
|
583
|
+
export type ApplicationBackgrounded = Record<string, never>;
|
|
584
|
+
|
|
585
|
+
/** The app was launched for the first time after an update to a different version or build. */
|
|
586
|
+
export interface ApplicationUpdated {
|
|
587
|
+
previous_version: string;
|
|
588
|
+
previous_build: string;
|
|
589
|
+
version: string;
|
|
590
|
+
build: string;
|
|
591
|
+
}
|
|
592
|
+
|
|
568
593
|
/** The spec version these models implement. SDKs stamp it on context.spec.version. */
|
|
569
|
-
export const SPEC_VERSION = '1.
|
|
594
|
+
export const SPEC_VERSION = '1.10';
|
|
570
595
|
|
|
571
596
|
/** Every event name the registry accepts. Anything else is rejected at the ingest. */
|
|
572
597
|
export type CdpEventName =
|
|
@@ -620,6 +645,10 @@ export type CdpEventName =
|
|
|
620
645
|
| 'Order Returned'
|
|
621
646
|
| 'Email Bounced'
|
|
622
647
|
| 'Email Marked as Spam'
|
|
648
|
+
| 'Application Installed'
|
|
649
|
+
| 'Application Opened'
|
|
650
|
+
| 'Application Backgrounded'
|
|
651
|
+
| 'Application Updated'
|
|
623
652
|
;
|
|
624
653
|
|
|
625
654
|
/** Event name -> its properties, so a generic emitter stays type-safe. */
|
|
@@ -674,6 +703,10 @@ export interface CdpEventProperties {
|
|
|
674
703
|
'Order Returned': OrderReturned;
|
|
675
704
|
'Email Bounced': EmailBounced;
|
|
676
705
|
'Email Marked as Spam': EmailMarkedAsSpam;
|
|
706
|
+
'Application Installed': ApplicationInstalled;
|
|
707
|
+
'Application Opened': ApplicationOpened;
|
|
708
|
+
'Application Backgrounded': ApplicationBackgrounded;
|
|
709
|
+
'Application Updated': ApplicationUpdated;
|
|
677
710
|
}
|
|
678
711
|
|
|
679
712
|
/** Which producers the registry permits for each event. Emitting from another is refused. */
|
package/types/index.d.ts
CHANGED
|
@@ -171,6 +171,11 @@ export interface AnalyticsOptions extends AnalyticsContextSources {
|
|
|
171
171
|
|
|
172
172
|
/** The property's personalisation holdout, from the settings (`hp.holdouts`). */
|
|
173
173
|
holdout?: Holdout | null;
|
|
174
|
+
/**
|
|
175
|
+
* The share of visitors to send for, from the settings (`hp.sampleRate`): a visitor whose
|
|
176
|
+
* anonymous id falls outside it sends nothing. Default 1. Since 3.18.
|
|
177
|
+
*/
|
|
178
|
+
sampleRate?: number;
|
|
174
179
|
|
|
175
180
|
/** Keep only these query params (anchored, case-insensitive patterns), plus campaign params. */
|
|
176
181
|
queryParamAllowlist?: string[];
|
|
@@ -184,10 +189,10 @@ export interface AnalyticsOptions extends AnalyticsContextSources {
|
|
|
184
189
|
|
|
185
190
|
/**
|
|
186
191
|
* Where device ids come from, as the source's settings serve it (`hp.anonymousId`, chosen in the
|
|
187
|
-
* console)
|
|
192
|
+
* console):
|
|
188
193
|
*
|
|
189
194
|
* - `site_cookie`: the site's own first-party cookie, the one named here or, with `cookie: null`,
|
|
190
|
-
* whatever `getAnonymousId` reads. Read only
|
|
195
|
+
* whatever `getAnonymousId` reads. Read only; a visitor without it gets the SDK's own (3.18).
|
|
191
196
|
* - `hp_cookie`: Hyper-Personalisation's own first-party cookie (`storageNames.anonymousId`,
|
|
192
197
|
* `thg_hp_anonymous_id`), which the SDK mints and keeps; `getAnonymousId` is ignored.
|
|
193
198
|
*
|
|
@@ -231,11 +236,11 @@ export interface AnalyticsOptions extends AnalyticsContextSources {
|
|
|
231
236
|
};
|
|
232
237
|
}
|
|
233
238
|
|
|
234
|
-
/** The event as queued, or null when the tracking plan disables it. */
|
|
239
|
+
/** The event as queued, or null when the tracking plan disables it or the visitor is outside the sample. */
|
|
235
240
|
type Emit<P> = (properties: P, options?: CallOptions) => CdpEvent | null;
|
|
236
241
|
|
|
237
242
|
export interface AnalyticsClient {
|
|
238
|
-
/** Null when the tracking plan disables the event. */
|
|
243
|
+
/** Null when the tracking plan disables the event or the visitor is outside the sample. */
|
|
239
244
|
track<E extends CdpEventName>(
|
|
240
245
|
event: E,
|
|
241
246
|
properties?: CdpEventProperties[E],
|
|
@@ -473,6 +478,8 @@ export interface StorageNames {
|
|
|
473
478
|
session?: string;
|
|
474
479
|
/** Session cookie: the preview token from `?hp_preview=` (3.15). Default 'thg_hp_preview'. */
|
|
475
480
|
preview?: string;
|
|
481
|
+
/** sessionStorage: the debug token from `?hp_debug=` (3.18). Default 'thg_hp_debug'. */
|
|
482
|
+
debug?: string;
|
|
476
483
|
}
|
|
477
484
|
|
|
478
485
|
/** Where a source's device ids come from: the settings' `hp.anonymousId` (since 3.6). */
|