@thg-agentic/hyper-personalisation-web 3.22.2 → 3.24.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 +166 -2
- package/dist/hp.min.js +3 -3
- package/dist/onsite-answers.min.js +1 -0
- package/dist/onsite-render.min.js +182 -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/ga4.js +3 -4
- package/src/hp.js +2 -0
- package/src/index.js +100 -5
- 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 +525 -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 +1507 -0
- package/src/onsite/rich-text.js +73 -0
- package/src/onsite/rules.js +250 -0
- package/src/onsite/styles.js +212 -0
- package/src/onsite/triggers.js +165 -0
- package/src/onsite/wheel-loader.js +5 -0
- package/src/onsite/wheel.js +196 -0
- package/src/onsite-facade.js +123 -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 +203 -0
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.18
|
|
5
5
|
|
|
6
6
|
/** context.source.environment. Environment the producer runs in. */
|
|
7
7
|
export type CdpSourceEnvironment = 'production' | 'staging' | 'development';
|
|
@@ -76,12 +76,28 @@ export interface DecisionMade {
|
|
|
76
76
|
latency_ms?: number | null;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/** A
|
|
79
|
+
/** A triggered journey fired for one shopper: an entry event happened, the journey's delay passed, its exit event did not happen, and the shopper passed its gates (marketing consent, suppression, frequency cap, quiet hours). */
|
|
80
|
+
export interface JourneyTriggered {
|
|
81
|
+
trigger_id: string;
|
|
82
|
+
journey: string;
|
|
83
|
+
entry_event: string;
|
|
84
|
+
entry_message_id: string;
|
|
85
|
+
entry_at: string;
|
|
86
|
+
delay_seconds: number;
|
|
87
|
+
holdout: boolean;
|
|
88
|
+
holdout_share?: number | null;
|
|
89
|
+
cart_id?: string | null;
|
|
90
|
+
currency?: string | null;
|
|
91
|
+
products?: CdpProduct[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 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. */
|
|
80
95
|
export interface SlotEngaged {
|
|
81
96
|
decision_id: string;
|
|
82
97
|
slot: string;
|
|
83
|
-
engagement: 'view' | 'click' | 'dismiss';
|
|
98
|
+
engagement: 'view' | 'click' | 'dismiss' | 'submit';
|
|
84
99
|
arm?: string | null;
|
|
100
|
+
step?: string | null;
|
|
85
101
|
position?: number | null;
|
|
86
102
|
products?: CdpProduct[] | null;
|
|
87
103
|
}
|
|
@@ -432,13 +448,18 @@ export interface SignedUp {
|
|
|
432
448
|
/** The shopper signed out. */
|
|
433
449
|
export type SignedOut = Record<string, never>;
|
|
434
450
|
|
|
435
|
-
/** The shopper opted in to marketing messages on the site or in the app, for example through a footer form,
|
|
451
|
+
/** The shopper opted in to marketing messages on the site or in the app, for example through a footer form, an onsite sign-up form, or a checkbox at checkout or in their account. */
|
|
436
452
|
export interface NewsletterSubscribed {
|
|
437
453
|
email_sha256: string;
|
|
438
454
|
requires_verification?: boolean | null;
|
|
439
455
|
placement?: string | null;
|
|
440
456
|
channel?: 'email' | 'sms' | 'post' | 'push' | null;
|
|
441
457
|
phone_sha256?: string | null;
|
|
458
|
+
slot?: string | null;
|
|
459
|
+
arm?: string | null;
|
|
460
|
+
decision_id?: string | null;
|
|
461
|
+
receipt_id?: string | null;
|
|
462
|
+
consent_text?: string | null;
|
|
442
463
|
}
|
|
443
464
|
|
|
444
465
|
/** A shopper submitted a review of a product. */
|
|
@@ -630,12 +651,47 @@ export interface ApplicationUpdated {
|
|
|
630
651
|
build: string;
|
|
631
652
|
}
|
|
632
653
|
|
|
654
|
+
/** The shopper answered a preference question, for example what they are shopping for or which categories they want to hear about. */
|
|
655
|
+
export interface PreferencesStated {
|
|
656
|
+
question: string;
|
|
657
|
+
values: string[];
|
|
658
|
+
source: 'onsite' | 'account' | 'quiz';
|
|
659
|
+
slot?: string | null;
|
|
660
|
+
arm?: string | null;
|
|
661
|
+
decision_id?: string | null;
|
|
662
|
+
step?: string | null;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/** A shopper who signed up through an onsite form claimed its offer, for example the prize of a spin-to-win or a welcome discount. */
|
|
666
|
+
export interface OfferClaimed {
|
|
667
|
+
slot: string;
|
|
668
|
+
prize: string;
|
|
669
|
+
email_sha256: string;
|
|
670
|
+
fallback: boolean;
|
|
671
|
+
arm?: string | null;
|
|
672
|
+
decision_id?: string | null;
|
|
673
|
+
pool?: string | null;
|
|
674
|
+
code_sha256?: string | null;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/** Hyper-Personalisation delivered a sign-up from an onsite form to one of the brand's systems of record, such as its account service or its email platform, or gave up trying. */
|
|
678
|
+
export interface SignUpRelayed {
|
|
679
|
+
receipt_id: string;
|
|
680
|
+
destination: string;
|
|
681
|
+
kind: 'thg' | 'listrak' | 'klaviyo' | 'webhook';
|
|
682
|
+
outcome: 'delivered' | 'duplicate' | 'verify' | 'failed';
|
|
683
|
+
attempts: number;
|
|
684
|
+
email_sha256?: string | null;
|
|
685
|
+
phone_sha256?: string | null;
|
|
686
|
+
}
|
|
687
|
+
|
|
633
688
|
/** The spec version these models implement. SDKs stamp it on context.spec.version. */
|
|
634
|
-
export const SPEC_VERSION = '1.
|
|
689
|
+
export const SPEC_VERSION = '1.18';
|
|
635
690
|
|
|
636
691
|
/** Every event name the registry accepts. Anything else is rejected at the ingest. */
|
|
637
692
|
export type CdpEventName =
|
|
638
693
|
| 'Decision Made'
|
|
694
|
+
| 'Journey Triggered'
|
|
639
695
|
| 'Slot Engaged'
|
|
640
696
|
| 'Recommendations Viewed'
|
|
641
697
|
| 'Promotion Viewed'
|
|
@@ -690,11 +746,15 @@ export type CdpEventName =
|
|
|
690
746
|
| 'Application Opened'
|
|
691
747
|
| 'Application Backgrounded'
|
|
692
748
|
| 'Application Updated'
|
|
749
|
+
| 'Preferences Stated'
|
|
750
|
+
| 'Offer Claimed'
|
|
751
|
+
| 'Sign-up Relayed'
|
|
693
752
|
;
|
|
694
753
|
|
|
695
754
|
/** Event name -> its properties, so a generic emitter stays type-safe. */
|
|
696
755
|
export interface CdpEventProperties {
|
|
697
756
|
'Decision Made': DecisionMade;
|
|
757
|
+
'Journey Triggered': JourneyTriggered;
|
|
698
758
|
'Slot Engaged': SlotEngaged;
|
|
699
759
|
'Recommendations Viewed': RecommendationsViewed;
|
|
700
760
|
'Promotion Viewed': PromotionViewed;
|
|
@@ -749,6 +809,9 @@ export interface CdpEventProperties {
|
|
|
749
809
|
'Application Opened': ApplicationOpened;
|
|
750
810
|
'Application Backgrounded': ApplicationBackgrounded;
|
|
751
811
|
'Application Updated': ApplicationUpdated;
|
|
812
|
+
'Preferences Stated': PreferencesStated;
|
|
813
|
+
'Offer Claimed': OfferClaimed;
|
|
814
|
+
'Sign-up Relayed': SignUpRelayed;
|
|
752
815
|
}
|
|
753
816
|
|
|
754
817
|
/** Which producers the registry permits for each event. Emitting from another is refused. */
|
package/types/hp.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
CallOptions,
|
|
5
5
|
RecommendationContext,
|
|
6
6
|
} from './index';
|
|
7
|
+
import type { OnsiteFacade } from './onsite';
|
|
7
8
|
|
|
8
9
|
type Methods = {
|
|
9
10
|
[K in keyof AnalyticsClient as AnalyticsClient[K] extends (
|
|
@@ -40,7 +41,7 @@ interface HpTrack {
|
|
|
40
41
|
* into the caller.
|
|
41
42
|
*/
|
|
42
43
|
export declare const hp: {
|
|
43
|
-
[K in Exclude<keyof Methods, 'track' | 'recommendationContext'>]: (
|
|
44
|
+
[K in Exclude<keyof Methods, 'track' | 'recommendationContext' | 'onsite'>]: (
|
|
44
45
|
...args: Parameters<Methods[K]>
|
|
45
46
|
) => void;
|
|
46
47
|
} & {
|
|
@@ -61,4 +62,6 @@ export declare const hp: {
|
|
|
61
62
|
* client has started, and without personalisation consent. Since 3.11.
|
|
62
63
|
*/
|
|
63
64
|
recommendationContext(): RecommendationContext;
|
|
65
|
+
/** Onsite forms: `hp.onsite.open(slot)` opens a form by hand; `debug()` says why each did or did not show. */
|
|
66
|
+
onsite: OnsiteFacade;
|
|
64
67
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ import type {
|
|
|
22
22
|
NewsletterUnsubscribed,
|
|
23
23
|
PaymentInfoEntered,
|
|
24
24
|
PersonalisationExposed,
|
|
25
|
+
PreferencesStated,
|
|
25
26
|
ProductAdded,
|
|
26
27
|
ProductAddedToWishlist,
|
|
27
28
|
ProductClicked,
|
|
@@ -335,6 +336,11 @@ export interface AnalyticsClient {
|
|
|
335
336
|
newsletterSubscribed: Emit<NewsletterSubscribed>;
|
|
336
337
|
/** An on-site opt-out. The ESP reports its own as Email Unsubscribed. */
|
|
337
338
|
newsletterUnsubscribed: Emit<NewsletterUnsubscribed>;
|
|
339
|
+
/**
|
|
340
|
+
* Answers to an approved preference question (spec 1.18). Answers sent with an onsite sign-up are
|
|
341
|
+
* the gateway's to report, so never send those.
|
|
342
|
+
*/
|
|
343
|
+
preferencesStated: Emit<PreferencesStated>;
|
|
338
344
|
/** An alert request for one product: back in stock, a price drop or a launch. */
|
|
339
345
|
backInStockSubscribed: Emit<BackInStockSubscribed>;
|
|
340
346
|
productReviewed: Emit<ProductReviewed>;
|
|
@@ -436,6 +442,10 @@ export interface ServingBody {
|
|
|
436
442
|
* computes it from the settings. `default` is no decision and is not put in force. Since 3.16.
|
|
437
443
|
*/
|
|
438
444
|
variant?: 'bandit' | 'default';
|
|
445
|
+
/** The A/B test the arm was assigned in, when the slot runs one. Since 3.23. */
|
|
446
|
+
experiment?: string;
|
|
447
|
+
/** The test's split token, sent back with the pin. Since 3.23. */
|
|
448
|
+
split?: string;
|
|
439
449
|
}>;
|
|
440
450
|
recommendation_request_id?: string;
|
|
441
451
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** A question the form's settings publish, as the preview renders it. */
|
|
2
|
+
export interface PreviewQuestion {
|
|
3
|
+
key: string;
|
|
4
|
+
type?: 'one' | 'many' | 'date' | 'number';
|
|
5
|
+
label?: string;
|
|
6
|
+
/** A choice's options. */
|
|
7
|
+
options?: Array<{ value: string; label?: string }>;
|
|
8
|
+
/** A date's or a number's format, as the settings publish it. */
|
|
9
|
+
format?: {
|
|
10
|
+
kind?: 'birthday' | 'date';
|
|
11
|
+
year?: 'none' | 'optional' | 'required';
|
|
12
|
+
min?: number;
|
|
13
|
+
max?: number;
|
|
14
|
+
decimals?: boolean;
|
|
15
|
+
unit?: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface PreviewOptions {
|
|
20
|
+
/** The step to show; the first when left out or unknown. */
|
|
21
|
+
step?: string;
|
|
22
|
+
/** The small-screen layout (`mobile`) or the large one, whatever the host's own width. */
|
|
23
|
+
device?: 'desktop' | 'mobile';
|
|
24
|
+
/** The form's consent text; a sample sentence when left out. */
|
|
25
|
+
consentText?: string;
|
|
26
|
+
/** The consent text a step taking a phone number shows; a sample sentence when left out. */
|
|
27
|
+
smsConsentText?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The form's language (the settings' `locale`, e.g. `en-GB`): a birthday's field order and month
|
|
30
|
+
* names, and a phone field's first country. The page's `<html lang>` when left out.
|
|
31
|
+
*/
|
|
32
|
+
locale?: string;
|
|
33
|
+
questions?: PreviewQuestion[];
|
|
34
|
+
prizes?: Array<{ key: string; label: string }>;
|
|
35
|
+
/** The basket a progress block is drawn against; 32 when left out. */
|
|
36
|
+
basketValue?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface OnsitePreview {
|
|
40
|
+
/** Re-render, on the step shown unless `options.step` names another. */
|
|
41
|
+
update(creative: unknown, options?: PreviewOptions): void;
|
|
42
|
+
destroy(): void;
|
|
43
|
+
/** The step on screen, or null when the creative could not be read. */
|
|
44
|
+
step(): string | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Render a creative with the shoppers' renderer inside `host`, for the console: no request, no
|
|
49
|
+
* event, no counter; its buttons only move between steps.
|
|
50
|
+
*/
|
|
51
|
+
export declare function mountPreview(
|
|
52
|
+
host: HTMLElement,
|
|
53
|
+
creative: unknown,
|
|
54
|
+
options?: PreviewOptions,
|
|
55
|
+
): OnsitePreview;
|
|
56
|
+
|
|
57
|
+
/** The countries a phone field's country code picker offers, by ISO code, with their calling codes. */
|
|
58
|
+
export declare const CALLING_CODES: Readonly<Record<string, string>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface OnsiteWheel {
|
|
2
|
+
/** Turn to the prize at `index`, the one the server drew. Instant under reduced motion. */
|
|
3
|
+
spinTo(index: number): Promise<void>;
|
|
4
|
+
remove(): void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** Draw the prize wheel into `container`. Null for fewer than two prizes. */
|
|
8
|
+
export declare function mountWheel(
|
|
9
|
+
container: Element,
|
|
10
|
+
prizes: Array<{ key: string; label: string }>,
|
|
11
|
+
): OnsiteWheel | null;
|
|
@@ -0,0 +1,203 @@
|
|
|
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
|
+
/** Other names `show()` opens this form by (`footer_signup` for the site's sign-up button). */
|
|
46
|
+
aliases?: string[];
|
|
47
|
+
pages?: { include?: string[]; exclude?: string[] };
|
|
48
|
+
/** `mobile` is a coarse pointer or a viewport under 768px. Absent: both. */
|
|
49
|
+
devices?: Array<'desktop' | 'mobile'>;
|
|
50
|
+
/** Shown only with personalisation consent, and only to members as the server decides. */
|
|
51
|
+
audiences?: string[];
|
|
52
|
+
exclude_subscribed?: boolean;
|
|
53
|
+
caps?: { per_session?: number; lifetime?: number; after_close_days?: number };
|
|
54
|
+
window?: { starts_at?: string; ends_at?: string };
|
|
55
|
+
/**
|
|
56
|
+
* The form's language, BCP 47 (`en-IE`): its phone field starts on this region's country code,
|
|
57
|
+
* and a birthday's day and month follow its order and month names. Absent: the page's `lang`.
|
|
58
|
+
*/
|
|
59
|
+
locale?: string;
|
|
60
|
+
/** The words an email step asks agreement to; absent on a form that collects only `sms`. */
|
|
61
|
+
consent_text?: { id: string; version: number; text: string };
|
|
62
|
+
/** The words an SMS step asks agreement to; present when `channels` has `sms`. */
|
|
63
|
+
sms_consent_text?: { id: string; version: number; text: string };
|
|
64
|
+
/**
|
|
65
|
+
* A choice (`one`, `many`) has `options`; a `date` or `number` question has `format`. A date is
|
|
66
|
+
* answered as `YYYY-MM-DD`, or `--MM-DD` for a birthday without its year.
|
|
67
|
+
*/
|
|
68
|
+
questions?: Array<{
|
|
69
|
+
key: string;
|
|
70
|
+
type: 'one' | 'many' | 'date' | 'number';
|
|
71
|
+
label: string;
|
|
72
|
+
options?: Array<{ value: string; label: string }>;
|
|
73
|
+
format?: OnsiteQuestionFormat;
|
|
74
|
+
}>;
|
|
75
|
+
/** The wheel's labels only: odds and codes are the server's. */
|
|
76
|
+
prizes?: Array<{ key: string; label: string }>;
|
|
77
|
+
/** A destination is handed the shopper's code, so the brand's email can carry it. */
|
|
78
|
+
code_relayed?: true;
|
|
79
|
+
channels?: Array<'email' | 'sms'>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A date question's (`kind`: a `birthday`, its `year` not asked, optional or required, or any
|
|
84
|
+
* full `date`) or a number question's (`min`, `max`, `decimals`, `unit`).
|
|
85
|
+
*/
|
|
86
|
+
export interface OnsiteQuestionFormat {
|
|
87
|
+
kind?: 'birthday' | 'date';
|
|
88
|
+
year?: 'none' | 'optional' | 'required';
|
|
89
|
+
min?: number;
|
|
90
|
+
max?: number;
|
|
91
|
+
decimals?: boolean;
|
|
92
|
+
unit?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** `hp.onsite` in the SDK settings. */
|
|
96
|
+
export interface OnsiteSettings {
|
|
97
|
+
forms: OnsiteForm[];
|
|
98
|
+
/**
|
|
99
|
+
* Minutes a session waits after a popup, sheet or full-screen form (not a bar or teaser) before another may
|
|
100
|
+
* show. Absent: no limit; 1440: once per session.
|
|
101
|
+
*/
|
|
102
|
+
overlay_gap_minutes?: number;
|
|
103
|
+
capture?: { challenge?: string } | null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface OnsiteOptions {
|
|
107
|
+
/** Development and tests: these forms instead of the settings'. */
|
|
108
|
+
settings?: OnsiteSettings;
|
|
109
|
+
/** The public API for decisions and offer claims. Default: the host the SDK was pointed at. */
|
|
110
|
+
servingHost?: string;
|
|
111
|
+
/** The ingest gateway for capture. Default: where the SDK sends events. */
|
|
112
|
+
gatewayHost?: string;
|
|
113
|
+
/** The visitor's session audiences, when the page evaluates them: a form outside them is skipped. */
|
|
114
|
+
audiences?(): string[] | null | undefined;
|
|
115
|
+
/** Whether the page knows this visitor is already subscribed (a signed-in subscriber). */
|
|
116
|
+
subscribed?(): boolean;
|
|
117
|
+
/** Log why each form did or did not show. Also on with `?hp_debug=onsite` or the SDK's debug. */
|
|
118
|
+
debug?: boolean;
|
|
119
|
+
fetch?: typeof fetch;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** One form's state on this page, and why. */
|
|
123
|
+
export interface OnsiteTrace {
|
|
124
|
+
slot: string;
|
|
125
|
+
format?: OnsiteFormat;
|
|
126
|
+
trigger?: OnsiteTriggerType;
|
|
127
|
+
priority?: number;
|
|
128
|
+
state:
|
|
129
|
+
| 'armed'
|
|
130
|
+
| 'waiting for hp.onsite.open'
|
|
131
|
+
| 'asking for a decision'
|
|
132
|
+
| 'shown'
|
|
133
|
+
| 'closed'
|
|
134
|
+
| 'held out'
|
|
135
|
+
| 'no decision'
|
|
136
|
+
| 'not eligible'
|
|
137
|
+
| 'not shown'
|
|
138
|
+
| 'invalid';
|
|
139
|
+
reasons: string[];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface OnsiteController {
|
|
143
|
+
/** Show the form on `slot` now, whatever its trigger, if its rules allow it. */
|
|
144
|
+
open(slot: string): Promise<boolean>;
|
|
145
|
+
/** Each form's state on this page, and why. */
|
|
146
|
+
debug(): OnsiteTrace[];
|
|
147
|
+
/** Stop watching every trigger. A form on screen stays until it is closed. */
|
|
148
|
+
stop(): void;
|
|
149
|
+
/** Take every form off the screen, quietly (`hp.onsite.suppress` calls it). */
|
|
150
|
+
suppress(): void;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** What every `hp.onsite.on` listener is told. */
|
|
154
|
+
export interface OnsiteEventDetail {
|
|
155
|
+
slot: string;
|
|
156
|
+
arm: string | null;
|
|
157
|
+
format: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** A code a form handed out: the claimed prize, or a reminder's unused code. */
|
|
161
|
+
export interface OnsiteCoupon {
|
|
162
|
+
code: string | null;
|
|
163
|
+
prize?: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface OnsiteEvents {
|
|
167
|
+
shown: OnsiteEventDetail;
|
|
168
|
+
/** After the sign-up; for a form that spins, once the prize is claimed. */
|
|
169
|
+
submitted: OnsiteEventDetail & { coupon: OnsiteCoupon | null };
|
|
170
|
+
/** A reminder's apply button: put the code on the basket. */
|
|
171
|
+
apply: OnsiteEventDetail & { coupon: OnsiteCoupon | null };
|
|
172
|
+
closed: OnsiteEventDetail & { reason: string };
|
|
173
|
+
/** A held-out visitor's trigger fired (not a form the site opened, whose `open` resolves false): show what the site shows without HP. */
|
|
174
|
+
held: OnsiteEventDetail;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** `hp.onsite`, callable before the runtime has loaded. */
|
|
178
|
+
export interface OnsiteFacade {
|
|
179
|
+
open(slot: string): Promise<boolean>;
|
|
180
|
+
/** The same as `open`. */
|
|
181
|
+
show(slot: string): Promise<boolean>;
|
|
182
|
+
/** Listen to the forms; returns a function that stops listening. */
|
|
183
|
+
on<K extends keyof OnsiteEvents>(
|
|
184
|
+
name: K,
|
|
185
|
+
listener: (detail: OnsiteEvents[K]) => void,
|
|
186
|
+
): () => void;
|
|
187
|
+
/** Keep the screen clear for `reason` (default `page`): a form showing goes, and none shows until lifted. */
|
|
188
|
+
suppress(reason?: string): void;
|
|
189
|
+
/** Lift `reason`, or every reason. */
|
|
190
|
+
unsuppress(reason?: string): void;
|
|
191
|
+
/** Each form's state once the page knows whether onsite forms run on it; `[]` when none will. */
|
|
192
|
+
ready(): Promise<OnsiteTrace[]>;
|
|
193
|
+
debug(): OnsiteTrace[];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Start onsite forms for the client, once per page. Null without a browser, or for a client this
|
|
198
|
+
* SDK did not make.
|
|
199
|
+
*/
|
|
200
|
+
export declare function startOnsite(
|
|
201
|
+
client: AnalyticsClient,
|
|
202
|
+
options?: OnsiteOptions,
|
|
203
|
+
): OnsiteController | null;
|