@uniformdev/context 20.70.0 → 20.70.1-alpha.10
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/dist/api/api.d.mts +19 -30
- package/dist/api/api.d.ts +19 -30
- package/dist/api/api.js +6 -6
- package/dist/api/api.mjs +6 -6
- package/dist/index.d.mts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.esm.js +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +1 -1
- package/dist/{types-BAWsX0zQ.d.mts → types-C0Mthca3.d.mts} +453 -457
- package/dist/{types-BAWsX0zQ.d.ts → types-C0Mthca3.d.ts} +453 -457
- package/package.json +6 -7
|
@@ -1,402 +1,6 @@
|
|
|
1
1
|
import * as mitt from 'mitt';
|
|
2
2
|
import { Emitter } from 'mitt';
|
|
3
3
|
|
|
4
|
-
type Quirks = {
|
|
5
|
-
[key: string]: string;
|
|
6
|
-
};
|
|
7
|
-
type Tests = {
|
|
8
|
-
[key: string]: string;
|
|
9
|
-
};
|
|
10
|
-
type ScoreVector = {
|
|
11
|
-
[key: string]: number;
|
|
12
|
-
};
|
|
13
|
-
type Goals = {
|
|
14
|
-
[key: string]: boolean;
|
|
15
|
-
};
|
|
16
|
-
type EnrichmentData = {
|
|
17
|
-
/** Enrichment category name */
|
|
18
|
-
cat: string;
|
|
19
|
-
/** Enrichment key value */
|
|
20
|
-
key: string;
|
|
21
|
-
/** Strength value (amount of score added when viewing content) */
|
|
22
|
-
str: number;
|
|
23
|
-
};
|
|
24
|
-
type PersonalizeControlVariant = {
|
|
25
|
-
index: number;
|
|
26
|
-
control: boolean;
|
|
27
|
-
};
|
|
28
|
-
type PersonalizeVariants = {
|
|
29
|
-
[key: string]: PersonalizeControlVariant[];
|
|
30
|
-
};
|
|
31
|
-
/** An event that has occurred (i.e. an analytics track) which may trigger an Event signal */
|
|
32
|
-
type EventData = {
|
|
33
|
-
/** The event name that has been fired */
|
|
34
|
-
event: string;
|
|
35
|
-
};
|
|
36
|
-
type VisitorData = {
|
|
37
|
-
/**
|
|
38
|
-
* Quirk key-value data.
|
|
39
|
-
* NOTE: Context.quirks is more commonly correct if you need to read quirks data.
|
|
40
|
-
*/
|
|
41
|
-
quirks: Quirks;
|
|
42
|
-
/** A/B test variant selections */
|
|
43
|
-
tests: Tests;
|
|
44
|
-
/**
|
|
45
|
-
* Personalization score data for the current session (merge with all time for totals)
|
|
46
|
-
* NOTE: Context.scores is more commonly correct to read scores instead of this value.
|
|
47
|
-
*/
|
|
48
|
-
sessionScores: ScoreVector;
|
|
49
|
-
/**
|
|
50
|
-
* Personalization score data for all time (merge with session for totals)
|
|
51
|
-
* NOTE: Context.scores is more commonly correct to read scores instead of this value.
|
|
52
|
-
*/
|
|
53
|
-
scores: ScoreVector;
|
|
54
|
-
/**
|
|
55
|
-
* Goals that this user has triggered.
|
|
56
|
-
*/
|
|
57
|
-
goals?: Goals;
|
|
58
|
-
/**
|
|
59
|
-
* Whether consent has been given to store the visitor data
|
|
60
|
-
* If false or not set: visitor data is stored in memory and is lost if the browser refreshes
|
|
61
|
-
* If true: visitor data is stored in localStorage and any other transition storage if registered
|
|
62
|
-
*/
|
|
63
|
-
consent?: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Whether the visitor has been assigned to the personalization control group -
|
|
66
|
-
* visitors who are not shown personalization. If this is true, all scores will be zeroed,
|
|
67
|
-
* and score updates will be ignored. This has no effect on quirks or tests.
|
|
68
|
-
*
|
|
69
|
-
* If this value is not set, a random roll will be performed to determine membership,
|
|
70
|
-
* based on the control group size.
|
|
71
|
-
*/
|
|
72
|
-
controlGroup?: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Records of personalized variants that have been shown to the visitor and their control group status
|
|
75
|
-
*/
|
|
76
|
-
personalizeVariants?: PersonalizeVariants;
|
|
77
|
-
};
|
|
78
|
-
declare const emptyVisitorData: () => VisitorData;
|
|
79
|
-
/**
|
|
80
|
-
* Canvas-specific data that should be managed separately from regular context updates
|
|
81
|
-
*/
|
|
82
|
-
type CompositionMetadata = {
|
|
83
|
-
/** The composition ID always required, otherwise whole metadata should not be set */
|
|
84
|
-
compositionId: string;
|
|
85
|
-
/** The matched route from router endpoint. Same as matched project map node pathname */
|
|
86
|
-
matchedRoute?: string;
|
|
87
|
-
/** Dynamic inputs for the route */
|
|
88
|
-
dynamicInputs?: Record<string, string>;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Expresses a 'patch' to the Uniform Context state
|
|
92
|
-
*/
|
|
93
|
-
type ContextState = {
|
|
94
|
-
cookies: Record<string, string | undefined>;
|
|
95
|
-
url?: URL;
|
|
96
|
-
quirks: Quirks;
|
|
97
|
-
enrichments: EnrichmentData[];
|
|
98
|
-
events: EventData[];
|
|
99
|
-
/**
|
|
100
|
-
* Metadata about the composition that is being rendered right now.
|
|
101
|
-
* if you have multiple compositions on the page, please set this one manually.
|
|
102
|
-
*/
|
|
103
|
-
compositionMetadata?: CompositionMetadata;
|
|
104
|
-
};
|
|
105
|
-
type ContextStateUpdate = {
|
|
106
|
-
/** The new effective state of the visitor after this state update is applied */
|
|
107
|
-
state: Partial<ContextState>;
|
|
108
|
-
/** The last state of the visitor before this state update */
|
|
109
|
-
previousState: Partial<ContextState>;
|
|
110
|
-
/** The visitor we are updating */
|
|
111
|
-
visitor: VisitorData;
|
|
112
|
-
/** The visitor's scores before this state update */
|
|
113
|
-
scores: ScoreVector;
|
|
114
|
-
};
|
|
115
|
-
type GoalStateUpdate = {
|
|
116
|
-
scores: ScoreVector | undefined;
|
|
117
|
-
quirks: Quirks | undefined;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
type StorageCommand<TID extends string = string, TData = unknown> = {
|
|
121
|
-
type: TID;
|
|
122
|
-
data: TData;
|
|
123
|
-
};
|
|
124
|
-
/** Commands that can be issued to alter the storage of Uniform Context data */
|
|
125
|
-
type StorageCommands = ModifyScoreCommand | ModifySessionScoreCommand | SetConsentCommand | SetQuirkCommand | SetTestCommand | IdentifyCommand | SetControlGroupCommand | SetPersonalizeVariantControlCommand | SetGoalCommand;
|
|
126
|
-
/**
|
|
127
|
-
* Converts the goal specified.
|
|
128
|
-
*/
|
|
129
|
-
type SetGoalCommand = StorageCommand<'setgoal', {
|
|
130
|
-
goal: string;
|
|
131
|
-
}>;
|
|
132
|
-
/**
|
|
133
|
-
* Changes the visitor's permanent score for a given dimension
|
|
134
|
-
*/
|
|
135
|
-
type ModifyScoreCommand = StorageCommand<'modscore', {
|
|
136
|
-
dimension: string;
|
|
137
|
-
delta: number;
|
|
138
|
-
}>;
|
|
139
|
-
/**
|
|
140
|
-
* Changes the visitor's session (time-based) score for a given dimension
|
|
141
|
-
*/
|
|
142
|
-
type ModifySessionScoreCommand = StorageCommand<'modscoreS', {
|
|
143
|
-
dimension: string;
|
|
144
|
-
delta: number;
|
|
145
|
-
}>;
|
|
146
|
-
/**
|
|
147
|
-
* Changes the visitor's storage consent setting.
|
|
148
|
-
* Setting consent to false will trigger deletion of any stored data for the visitor.
|
|
149
|
-
* Scores are still collected in-memory when consent is false; just not persisted.
|
|
150
|
-
*/
|
|
151
|
-
type SetConsentCommand = StorageCommand<'consent', boolean>;
|
|
152
|
-
/** Sets a permanent quirk key and value for the visitor */
|
|
153
|
-
type SetQuirkCommand = StorageCommand<'setquirk', {
|
|
154
|
-
key: string;
|
|
155
|
-
value: string;
|
|
156
|
-
}>;
|
|
157
|
-
/** Sets a specific variant as being this visitor's variant on an A/B test */
|
|
158
|
-
type SetTestCommand = StorageCommand<'settest', {
|
|
159
|
-
test: string;
|
|
160
|
-
variant: string;
|
|
161
|
-
}>;
|
|
162
|
-
/**
|
|
163
|
-
* Identifies the visitor as being a specific unique identifier.
|
|
164
|
-
* NOTE: this only has an effect when using an external cross-device transition storage system.
|
|
165
|
-
* NOTE: you cannot read the identified visitor ID back from the storage system once it is set.
|
|
166
|
-
*/
|
|
167
|
-
type IdentifyCommand = StorageCommand<'identify', {
|
|
168
|
-
identity: string;
|
|
169
|
-
}>;
|
|
170
|
-
/**
|
|
171
|
-
* Sets whether the current visitor is in the personalization control group
|
|
172
|
-
* (Will not be exposed to personalization or gather classification data; WILL see A/B tests)
|
|
173
|
-
* In most cases this should not be sent as the membership is computed automatically for visitors;
|
|
174
|
-
* this command is intended mostly for diagnostics and testing purposes.
|
|
175
|
-
*/
|
|
176
|
-
type SetControlGroupCommand = StorageCommand<'setcontrol', boolean>;
|
|
177
|
-
type SetPersonalizeVariantControlCommand = StorageCommand<'setpersonalizecontrol', {
|
|
178
|
-
personlizationName: string;
|
|
179
|
-
index: number;
|
|
180
|
-
control: boolean;
|
|
181
|
-
}>;
|
|
182
|
-
declare const areCommandsEqual: (a: StorageCommands, b: StorageCommands) => boolean;
|
|
183
|
-
|
|
184
|
-
type TransitionDataStoreOptions = {
|
|
185
|
-
initialData?: Partial<VisitorData>;
|
|
186
|
-
};
|
|
187
|
-
type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests' | 'personalizeVariants'> & {
|
|
188
|
-
/**
|
|
189
|
-
* Server Score Vector - the resultant scores _on the server side_ after the server/edge render completes
|
|
190
|
-
* Note that the client side does not trust these scores; they are only used until it's done with initial
|
|
191
|
-
* recomputation.
|
|
192
|
-
*/
|
|
193
|
-
ssv?: ScoreVector;
|
|
194
|
-
/**
|
|
195
|
-
* Storage commands that the server
|
|
196
|
-
*/
|
|
197
|
-
commands?: StorageCommands[];
|
|
198
|
-
/**
|
|
199
|
-
* Composition metadata from the server side
|
|
200
|
-
*/
|
|
201
|
-
compositionMetadata?: CompositionMetadata;
|
|
202
|
-
};
|
|
203
|
-
declare const SERVER_STATE_ID = "__UNIFORM_DATA__";
|
|
204
|
-
type TransitionDataStoreEvents = {
|
|
205
|
-
/**
|
|
206
|
-
* Fired when the data is updated asynchronously
|
|
207
|
-
* (i.e. a promise resolves with new data from a backend)
|
|
208
|
-
*
|
|
209
|
-
* NOT fired for synchronous updates (e.g. calling updateData()), unless this also results in an async update of the data afterwards.
|
|
210
|
-
* NOT fired if an asynchronous update does not result in any change compared to the last known data.
|
|
211
|
-
*/
|
|
212
|
-
dataUpdatedAsync: Partial<VisitorData>;
|
|
213
|
-
};
|
|
214
|
-
declare abstract class TransitionDataStore {
|
|
215
|
-
#private;
|
|
216
|
-
constructor({ initialData }: TransitionDataStoreOptions);
|
|
217
|
-
get data(): Partial<VisitorData> | undefined;
|
|
218
|
-
get initialData(): Partial<VisitorData> | undefined;
|
|
219
|
-
/**
|
|
220
|
-
* Subscribe to events from the transition storage
|
|
221
|
-
*/
|
|
222
|
-
readonly events: {
|
|
223
|
-
on: {
|
|
224
|
-
<Key extends "dataUpdatedAsync">(type: Key, handler: mitt.Handler<TransitionDataStoreEvents[Key]>): void;
|
|
225
|
-
(type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
|
|
226
|
-
};
|
|
227
|
-
off: {
|
|
228
|
-
<Key extends "dataUpdatedAsync">(type: Key, handler?: mitt.Handler<TransitionDataStoreEvents[Key]> | undefined): void;
|
|
229
|
-
(type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
|
|
230
|
-
};
|
|
231
|
-
};
|
|
232
|
-
/**
|
|
233
|
-
* Updates data in the transition storage.
|
|
234
|
-
* @param commands Commands to execute against existing stored value (event based stores)
|
|
235
|
-
* @param computedValue Pre-computed new value against existing value (object based stores)
|
|
236
|
-
* @returns Resolved promise when the data has been updated
|
|
237
|
-
*/
|
|
238
|
-
updateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
|
|
239
|
-
/**
|
|
240
|
-
* Deletes a visitor's stored data, forgetting them.
|
|
241
|
-
* @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
|
|
242
|
-
*/
|
|
243
|
-
delete(fromAllDevices?: boolean): Promise<void>;
|
|
244
|
-
/**
|
|
245
|
-
* Deletes a visitor's stored data, forgetting them.
|
|
246
|
-
* Important: do not emit any async score update events from this function.
|
|
247
|
-
* @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
|
|
248
|
-
*/
|
|
249
|
-
abstract handleDelete(fromAllDevices?: boolean): Promise<void>;
|
|
250
|
-
/**
|
|
251
|
-
* Updates visitor data in the transition store.
|
|
252
|
-
*
|
|
253
|
-
* NOTE: The updated data is optimistically stored in TransitionDataStore automatically,
|
|
254
|
-
* so unless the updated data is _changed_ by the backend data store, there is no need
|
|
255
|
-
* to emit async score changed events when the visitor data is done updating.
|
|
256
|
-
*/
|
|
257
|
-
abstract handleUpdateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
|
|
258
|
-
protected signalAsyncDataUpdate(newScores: Partial<VisitorData>): void;
|
|
259
|
-
/**
|
|
260
|
-
* When we load on the client side after a server side rendering has occurred (server to client transition),
|
|
261
|
-
* we can have a page script (ID: __UNIFORM_DATA__) that contains the computed visitor data from the SSR/edge render.
|
|
262
|
-
* This data is injected into the first render to allow score syncing and the server to request commands be applied
|
|
263
|
-
* to the client side data store.
|
|
264
|
-
*/
|
|
265
|
-
getClientTransitionState(): ServerToClientTransitionState | undefined;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
type DecayOptions = {
|
|
269
|
-
now: number;
|
|
270
|
-
lastUpd: number | undefined;
|
|
271
|
-
scores: ScoreVector;
|
|
272
|
-
sessionScores: ScoreVector;
|
|
273
|
-
onLogMessage?: (message: LogMessage) => void;
|
|
274
|
-
};
|
|
275
|
-
/**
|
|
276
|
-
* Computes decay of visitor scores over time.
|
|
277
|
-
* NOTE: it is expected that this function mutates the incoming score vectors,
|
|
278
|
-
* if it needs to apply score decay. The data store ensures immutability already.
|
|
279
|
-
*
|
|
280
|
-
* @returns true if any decay was applied, false otherwise
|
|
281
|
-
*/
|
|
282
|
-
type DecayFunction = (options: DecayOptions) => boolean;
|
|
283
|
-
|
|
284
|
-
type VisitorDataStoreOptions = {
|
|
285
|
-
/** Transition storage used to transfer server or edge side execution state to the client. Unused for client side only. */
|
|
286
|
-
transitionStore?: TransitionDataStore;
|
|
287
|
-
/** Duration of a 'visit' measured by this number of milliseconds without performing any updates */
|
|
288
|
-
visitLifespan?: number;
|
|
289
|
-
/** Personalization manifest data. If set, the data store will automatically apply score caps in the manifest data. */
|
|
290
|
-
manifest?: ManifestInstance;
|
|
291
|
-
/** Allows decaying of scores over time based on time between visits. Default: no decay */
|
|
292
|
-
decay?: DecayFunction;
|
|
293
|
-
/**
|
|
294
|
-
* Sets the default value of storage consent for new unknown visitors.
|
|
295
|
-
* If storage consent is not given, only in-memory data will be stored which is lost when the browser leaves the page.
|
|
296
|
-
* @default false - consent is not given for new visitors until they explicitly give it with an update command
|
|
297
|
-
*/
|
|
298
|
-
defaultConsent?: boolean;
|
|
299
|
-
/**
|
|
300
|
-
* Function called when server-to-client transfer state is loaded and contains server-side computed scores.
|
|
301
|
-
* These scores are used as a temporary shim for the current scores on the client side, until score computation
|
|
302
|
-
* is completed the first time (which occurs when the current url is fed into the Context).
|
|
303
|
-
*
|
|
304
|
-
* Because the feed of the URL may be marginally delayed (for example in React it's in an effect so it's a second render),
|
|
305
|
-
* one render might be done with _no_ scores unless we dropped the server scores in temporarily, resulting in a flash of unpersonalized content.
|
|
306
|
-
*/
|
|
307
|
-
onServerTransitionReceived?: (state: ServerToClientTransitionState) => void;
|
|
308
|
-
/** Called when a log message is emitted from the data store */
|
|
309
|
-
onLogMessage?: (message: LogMessage) => void;
|
|
310
|
-
/**
|
|
311
|
-
* Optionally specify a prefix for all storage keys.
|
|
312
|
-
* Only required if using multiple Context instances on the same domain and need to separate them.
|
|
313
|
-
*/
|
|
314
|
-
partitionKey?: string;
|
|
315
|
-
};
|
|
316
|
-
type VisitorDataStoreEvents = {
|
|
317
|
-
/**
|
|
318
|
-
* Fired when the stored data is updated.
|
|
319
|
-
* This is fired for any update, whether from integrated or transition storage.
|
|
320
|
-
* The event is NOT fired if an update does not result in any score changes.
|
|
321
|
-
*/
|
|
322
|
-
scoresUpdated: Pick<VisitorData, 'scores' | 'sessionScores'>;
|
|
323
|
-
/**
|
|
324
|
-
* Fired when stored quirks are updated.
|
|
325
|
-
* This is fired for any update, whether from integrated or transition storage.
|
|
326
|
-
* The event is NOT fired if an update does not result in any quirk changes.
|
|
327
|
-
*/
|
|
328
|
-
quirksUpdated: Pick<VisitorData, 'quirks'>;
|
|
329
|
-
/**
|
|
330
|
-
* Fired when test variant selection is updated.
|
|
331
|
-
*/
|
|
332
|
-
testsUpdated: Pick<VisitorData, 'tests'>;
|
|
333
|
-
/**
|
|
334
|
-
* Fired when storage consent is changed
|
|
335
|
-
*/
|
|
336
|
-
consentUpdated: Pick<VisitorData, 'consent'>;
|
|
337
|
-
/**
|
|
338
|
-
* Fired when visitor control group membership is changed
|
|
339
|
-
*/
|
|
340
|
-
controlGroupUpdated: Pick<VisitorData, 'controlGroup'>;
|
|
341
|
-
/**
|
|
342
|
-
* Fired when a goal is converted
|
|
343
|
-
*/
|
|
344
|
-
goalConverted: {
|
|
345
|
-
goalId: string;
|
|
346
|
-
};
|
|
347
|
-
/** Fired when storage update commands are done executing */
|
|
348
|
-
commandsExecuted: StorageCommands[];
|
|
349
|
-
};
|
|
350
|
-
declare class VisitorDataStore {
|
|
351
|
-
#private;
|
|
352
|
-
constructor(options: VisitorDataStoreOptions);
|
|
353
|
-
/** Gets the current visitor data. This property is always up to date. */
|
|
354
|
-
get data(): VisitorData;
|
|
355
|
-
get decayEnabled(): boolean;
|
|
356
|
-
get options(): VisitorDataStoreOptions;
|
|
357
|
-
/**
|
|
358
|
-
* Subscribe to events from storage
|
|
359
|
-
*/
|
|
360
|
-
readonly events: {
|
|
361
|
-
on: {
|
|
362
|
-
<Key extends keyof VisitorDataStoreEvents>(type: Key, handler: mitt.Handler<VisitorDataStoreEvents[Key]>): void;
|
|
363
|
-
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
|
364
|
-
};
|
|
365
|
-
off: {
|
|
366
|
-
<Key extends keyof VisitorDataStoreEvents>(type: Key, handler?: mitt.Handler<VisitorDataStoreEvents[Key]> | undefined): void;
|
|
367
|
-
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
|
368
|
-
};
|
|
369
|
-
};
|
|
370
|
-
/** Push data update command(s) into the visitor data */
|
|
371
|
-
updateData(commands: StorageCommands[]): Promise<void>;
|
|
372
|
-
/**
|
|
373
|
-
* Deletes visitor data (forgetting them)
|
|
374
|
-
* In most cases you should use forget() on the Context instead of this function, which also clears the Context state.
|
|
375
|
-
* @param fromAllDevices for an identified user, whether to delete all their data (for the entire account) - true, or data for this device (sign out) - false
|
|
376
|
-
*/
|
|
377
|
-
delete(fromAllDevices: boolean): Promise<void>;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
declare class ManifestInstance {
|
|
381
|
-
#private;
|
|
382
|
-
readonly data: ManifestV2;
|
|
383
|
-
constructor({ manifest, evaluator, onLogMessage, }: {
|
|
384
|
-
manifest: ManifestV2;
|
|
385
|
-
evaluator?: GroupCriteriaEvaluator;
|
|
386
|
-
onLogMessage?: (message: LogMessage) => void;
|
|
387
|
-
});
|
|
388
|
-
rollForControlGroup(): boolean;
|
|
389
|
-
getTest(name: string): TestDefinition | undefined;
|
|
390
|
-
computeSignals(update: ContextStateUpdate): StorageCommands[];
|
|
391
|
-
computeGoals(data: GoalStateUpdate): StorageCommands[];
|
|
392
|
-
/**
|
|
393
|
-
* Computes aggregated scores based on other dimensions
|
|
394
|
-
*/
|
|
395
|
-
computeAggregateDimensions(primitiveScores: ScoreVector): ScoreVector;
|
|
396
|
-
getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
|
|
397
|
-
getAggregateDimensionByKey(scoreKey: string): AggregateDimension | undefined;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
4
|
interface paths {
|
|
401
5
|
"/api/v2/manifest": {
|
|
402
6
|
parameters: {
|
|
@@ -405,9 +9,10 @@ interface paths {
|
|
|
405
9
|
path?: never;
|
|
406
10
|
cookie?: never;
|
|
407
11
|
};
|
|
408
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* @description Fetches the optimization Manifest for a given project.
|
|
409
14
|
* If no manifest has ever been published, and an API key is used that has preview manifest permissions then the current preview manifest will be returned (in delivery format).
|
|
410
|
-
|
|
15
|
+
*/
|
|
411
16
|
get: {
|
|
412
17
|
parameters: {
|
|
413
18
|
query: {
|
|
@@ -520,7 +125,6 @@ interface components {
|
|
|
520
125
|
* | = OR
|
|
521
126
|
*
|
|
522
127
|
* Default is `&` if unspecified
|
|
523
|
-
*
|
|
524
128
|
* @enum {string}
|
|
525
129
|
*/
|
|
526
130
|
op?: "&" | "|";
|
|
@@ -538,7 +142,6 @@ interface components {
|
|
|
538
142
|
* '//' = regular expression match
|
|
539
143
|
*
|
|
540
144
|
* Any of the above can be prefixed with '!' to invert the match (i.e. != for 'not an exact match')
|
|
541
|
-
*
|
|
542
145
|
* @enum {string}
|
|
543
146
|
*/
|
|
544
147
|
op: "=" | "~" | "//" | "!=" | "!~" | "!//";
|
|
@@ -549,7 +152,6 @@ interface components {
|
|
|
549
152
|
* @description The type of match to perform
|
|
550
153
|
* '*' = exists with any value
|
|
551
154
|
* '!*' = does not exist
|
|
552
|
-
*
|
|
553
155
|
* @enum {string}
|
|
554
156
|
*/
|
|
555
157
|
op: "*" | "!*";
|
|
@@ -588,9 +190,10 @@ interface components {
|
|
|
588
190
|
/** @description How to match the event name */
|
|
589
191
|
event: components["schemas"]["StringMatch"];
|
|
590
192
|
};
|
|
591
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* @description Matches the current page's absolute path (i.e. /path/to/page.html)
|
|
592
195
|
* Does not include the query string or protocol and hostname (i.e. NOT https://foo.com/path/to/page.html?query=something)
|
|
593
|
-
|
|
196
|
+
*/
|
|
594
197
|
CurrentPageCriteria: {
|
|
595
198
|
/** @enum {string} */
|
|
596
199
|
type: "PV";
|
|
@@ -607,7 +210,6 @@ interface components {
|
|
|
607
210
|
* '!=' = not an exact match
|
|
608
211
|
* '<' = less than match expression
|
|
609
212
|
* '>' = greater than match expression
|
|
610
|
-
*
|
|
611
213
|
* @enum {string}
|
|
612
214
|
*/
|
|
613
215
|
op: "=" | "<" | ">" | "!=";
|
|
@@ -631,7 +233,6 @@ interface components {
|
|
|
631
233
|
* | = OR
|
|
632
234
|
*
|
|
633
235
|
* Default is `&` if unspecified
|
|
634
|
-
*
|
|
635
236
|
* @default &
|
|
636
237
|
* @enum {string}
|
|
637
238
|
*/
|
|
@@ -656,7 +257,6 @@ interface components {
|
|
|
656
257
|
* 's' = current session (expires after a period of inactivity)
|
|
657
258
|
* 'p' = permanent (expires as far in the future as possible, may be limited by browser security settings)
|
|
658
259
|
* 't' = transient (score tracks the current state of the criteria every time scores are updated)
|
|
659
|
-
*
|
|
660
260
|
* @enum {string}
|
|
661
261
|
*/
|
|
662
262
|
dur: "s" | "p" | "t";
|
|
@@ -669,14 +269,15 @@ interface components {
|
|
|
669
269
|
};
|
|
670
270
|
/** @description Defines an input dimension to an aggregate dimension */
|
|
671
271
|
AggregateDimensionInput: {
|
|
672
|
-
/**
|
|
272
|
+
/**
|
|
273
|
+
* @description Dimension name to reference as an input.
|
|
673
274
|
* For enrichment inputs, use CATEGORY_KEY as the dimension.
|
|
674
275
|
* Enrichments, signals, and other aggregate dimensions may be referenced.
|
|
675
276
|
*
|
|
676
277
|
* Note that creating a cycle of aggregate dimensions is allowed, however
|
|
677
278
|
* the final score will _ignore_ the cycled aggregate dimension in the result.
|
|
678
279
|
* This can be used to create mutually exclusive aggregates
|
|
679
|
-
|
|
280
|
+
*/
|
|
680
281
|
dim: string;
|
|
681
282
|
/**
|
|
682
283
|
* @description The sign of the input dimension controls how it affects the aggregate dimension's final score.
|
|
@@ -686,7 +287,6 @@ interface components {
|
|
|
686
287
|
* 'c' = clear the final score (if the input dimension has any score at all, this aggregate will have no score regardless of other inputs)
|
|
687
288
|
*
|
|
688
289
|
* Default if unspecified: '+'
|
|
689
|
-
*
|
|
690
290
|
* @default +
|
|
691
291
|
* @enum {string}
|
|
692
292
|
*/
|
|
@@ -701,58 +301,454 @@ interface components {
|
|
|
701
301
|
/** @description Winning variation ID - if set, the test will not run and this variation is shown to all visitors (the test is closed) */
|
|
702
302
|
wv?: string;
|
|
703
303
|
};
|
|
704
|
-
Error: {
|
|
705
|
-
/** @description Error message(s) that occurred while processing the request */
|
|
706
|
-
errorMessage?: string[] | string;
|
|
304
|
+
Error: {
|
|
305
|
+
/** @description Error message(s) that occurred while processing the request */
|
|
306
|
+
errorMessage?: string[] | string;
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
responses: {
|
|
310
|
+
/** @description Request input validation failed */
|
|
311
|
+
BadRequestError: {
|
|
312
|
+
headers: {
|
|
313
|
+
[name: string]: unknown;
|
|
314
|
+
};
|
|
315
|
+
content: {
|
|
316
|
+
"application/json": components["schemas"]["Error"];
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
/** @description API key or token was not valid */
|
|
320
|
+
UnauthorizedError: {
|
|
321
|
+
headers: {
|
|
322
|
+
[name: string]: unknown;
|
|
323
|
+
};
|
|
324
|
+
content: {
|
|
325
|
+
"application/json": components["schemas"]["Error"];
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
/** @description Permission was denied */
|
|
329
|
+
ForbiddenError: {
|
|
330
|
+
headers: {
|
|
331
|
+
[name: string]: unknown;
|
|
332
|
+
};
|
|
333
|
+
content: {
|
|
334
|
+
"application/json": components["schemas"]["Error"];
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
/** @description Too many requests in allowed time period */
|
|
338
|
+
RateLimitError: {
|
|
339
|
+
headers: {
|
|
340
|
+
[name: string]: unknown;
|
|
341
|
+
};
|
|
342
|
+
content?: never;
|
|
343
|
+
};
|
|
344
|
+
/** @description Execution error occurred */
|
|
345
|
+
InternalServerError: {
|
|
346
|
+
headers: {
|
|
347
|
+
[name: string]: unknown;
|
|
348
|
+
};
|
|
349
|
+
content?: never;
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
parameters: never;
|
|
353
|
+
requestBodies: never;
|
|
354
|
+
headers: never;
|
|
355
|
+
pathItems: never;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
type Quirks = {
|
|
359
|
+
[key: string]: string;
|
|
360
|
+
};
|
|
361
|
+
type Tests = {
|
|
362
|
+
[key: string]: string;
|
|
363
|
+
};
|
|
364
|
+
type ScoreVector = {
|
|
365
|
+
[key: string]: number;
|
|
366
|
+
};
|
|
367
|
+
type Goals = {
|
|
368
|
+
[key: string]: boolean;
|
|
369
|
+
};
|
|
370
|
+
type EnrichmentData = {
|
|
371
|
+
/** Enrichment category name */
|
|
372
|
+
cat: string;
|
|
373
|
+
/** Enrichment key value */
|
|
374
|
+
key: string;
|
|
375
|
+
/** Strength value (amount of score added when viewing content) */
|
|
376
|
+
str: number;
|
|
377
|
+
};
|
|
378
|
+
type PersonalizeControlVariant = {
|
|
379
|
+
index: number;
|
|
380
|
+
control: boolean;
|
|
381
|
+
};
|
|
382
|
+
type PersonalizeVariants = {
|
|
383
|
+
[key: string]: PersonalizeControlVariant[];
|
|
384
|
+
};
|
|
385
|
+
/** An event that has occurred (i.e. an analytics track) which may trigger an Event signal */
|
|
386
|
+
type EventData = {
|
|
387
|
+
/** The event name that has been fired */
|
|
388
|
+
event: string;
|
|
389
|
+
};
|
|
390
|
+
type VisitorData = {
|
|
391
|
+
/**
|
|
392
|
+
* Quirk key-value data.
|
|
393
|
+
* NOTE: Context.quirks is more commonly correct if you need to read quirks data.
|
|
394
|
+
*/
|
|
395
|
+
quirks: Quirks;
|
|
396
|
+
/** A/B test variant selections */
|
|
397
|
+
tests: Tests;
|
|
398
|
+
/**
|
|
399
|
+
* Personalization score data for the current session (merge with all time for totals)
|
|
400
|
+
* NOTE: Context.scores is more commonly correct to read scores instead of this value.
|
|
401
|
+
*/
|
|
402
|
+
sessionScores: ScoreVector;
|
|
403
|
+
/**
|
|
404
|
+
* Personalization score data for all time (merge with session for totals)
|
|
405
|
+
* NOTE: Context.scores is more commonly correct to read scores instead of this value.
|
|
406
|
+
*/
|
|
407
|
+
scores: ScoreVector;
|
|
408
|
+
/**
|
|
409
|
+
* Goals that this user has triggered.
|
|
410
|
+
*/
|
|
411
|
+
goals?: Goals;
|
|
412
|
+
/**
|
|
413
|
+
* Whether consent has been given to store the visitor data
|
|
414
|
+
* If false or not set: visitor data is stored in memory and is lost if the browser refreshes
|
|
415
|
+
* If true: visitor data is stored in localStorage and any other transition storage if registered
|
|
416
|
+
*/
|
|
417
|
+
consent?: boolean;
|
|
418
|
+
/**
|
|
419
|
+
* Whether the visitor has been assigned to the personalization control group -
|
|
420
|
+
* visitors who are not shown personalization. If this is true, all scores will be zeroed,
|
|
421
|
+
* and score updates will be ignored. This has no effect on quirks or tests.
|
|
422
|
+
*
|
|
423
|
+
* If this value is not set, a random roll will be performed to determine membership,
|
|
424
|
+
* based on the control group size.
|
|
425
|
+
*/
|
|
426
|
+
controlGroup?: boolean;
|
|
427
|
+
/**
|
|
428
|
+
* Records of personalized variants that have been shown to the visitor and their control group status
|
|
429
|
+
*/
|
|
430
|
+
personalizeVariants?: PersonalizeVariants;
|
|
431
|
+
};
|
|
432
|
+
declare const emptyVisitorData: () => VisitorData;
|
|
433
|
+
/**
|
|
434
|
+
* Canvas-specific data that should be managed separately from regular context updates
|
|
435
|
+
*/
|
|
436
|
+
type CompositionMetadata = {
|
|
437
|
+
/** The composition ID always required, otherwise whole metadata should not be set */
|
|
438
|
+
compositionId: string;
|
|
439
|
+
/** The matched route from router endpoint. Same as matched project map node pathname */
|
|
440
|
+
matchedRoute?: string;
|
|
441
|
+
/** Dynamic inputs for the route */
|
|
442
|
+
dynamicInputs?: Record<string, string>;
|
|
443
|
+
};
|
|
444
|
+
/**
|
|
445
|
+
* Expresses a 'patch' to the Uniform Context state
|
|
446
|
+
*/
|
|
447
|
+
type ContextState = {
|
|
448
|
+
cookies: Record<string, string | undefined>;
|
|
449
|
+
url?: URL;
|
|
450
|
+
quirks: Quirks;
|
|
451
|
+
enrichments: EnrichmentData[];
|
|
452
|
+
events: EventData[];
|
|
453
|
+
/**
|
|
454
|
+
* Metadata about the composition that is being rendered right now.
|
|
455
|
+
* if you have multiple compositions on the page, please set this one manually.
|
|
456
|
+
*/
|
|
457
|
+
compositionMetadata?: CompositionMetadata;
|
|
458
|
+
};
|
|
459
|
+
type ContextStateUpdate = {
|
|
460
|
+
/** The new effective state of the visitor after this state update is applied */
|
|
461
|
+
state: Partial<ContextState>;
|
|
462
|
+
/** The last state of the visitor before this state update */
|
|
463
|
+
previousState: Partial<ContextState>;
|
|
464
|
+
/** The visitor we are updating */
|
|
465
|
+
visitor: VisitorData;
|
|
466
|
+
/** The visitor's scores before this state update */
|
|
467
|
+
scores: ScoreVector;
|
|
468
|
+
};
|
|
469
|
+
type GoalStateUpdate = {
|
|
470
|
+
scores: ScoreVector | undefined;
|
|
471
|
+
quirks: Quirks | undefined;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
type StorageCommand<TID extends string = string, TData = unknown> = {
|
|
475
|
+
type: TID;
|
|
476
|
+
data: TData;
|
|
477
|
+
};
|
|
478
|
+
/** Commands that can be issued to alter the storage of Uniform Context data */
|
|
479
|
+
type StorageCommands = ModifyScoreCommand | ModifySessionScoreCommand | SetConsentCommand | SetQuirkCommand | SetTestCommand | IdentifyCommand | SetControlGroupCommand | SetPersonalizeVariantControlCommand | SetGoalCommand;
|
|
480
|
+
/**
|
|
481
|
+
* Converts the goal specified.
|
|
482
|
+
*/
|
|
483
|
+
type SetGoalCommand = StorageCommand<'setgoal', {
|
|
484
|
+
goal: string;
|
|
485
|
+
}>;
|
|
486
|
+
/**
|
|
487
|
+
* Changes the visitor's permanent score for a given dimension
|
|
488
|
+
*/
|
|
489
|
+
type ModifyScoreCommand = StorageCommand<'modscore', {
|
|
490
|
+
dimension: string;
|
|
491
|
+
delta: number;
|
|
492
|
+
}>;
|
|
493
|
+
/**
|
|
494
|
+
* Changes the visitor's session (time-based) score for a given dimension
|
|
495
|
+
*/
|
|
496
|
+
type ModifySessionScoreCommand = StorageCommand<'modscoreS', {
|
|
497
|
+
dimension: string;
|
|
498
|
+
delta: number;
|
|
499
|
+
}>;
|
|
500
|
+
/**
|
|
501
|
+
* Changes the visitor's storage consent setting.
|
|
502
|
+
* Setting consent to false will trigger deletion of any stored data for the visitor.
|
|
503
|
+
* Scores are still collected in-memory when consent is false; just not persisted.
|
|
504
|
+
*/
|
|
505
|
+
type SetConsentCommand = StorageCommand<'consent', boolean>;
|
|
506
|
+
/** Sets a permanent quirk key and value for the visitor */
|
|
507
|
+
type SetQuirkCommand = StorageCommand<'setquirk', {
|
|
508
|
+
key: string;
|
|
509
|
+
value: string;
|
|
510
|
+
}>;
|
|
511
|
+
/** Sets a specific variant as being this visitor's variant on an A/B test */
|
|
512
|
+
type SetTestCommand = StorageCommand<'settest', {
|
|
513
|
+
test: string;
|
|
514
|
+
variant: string;
|
|
515
|
+
}>;
|
|
516
|
+
/**
|
|
517
|
+
* Identifies the visitor as being a specific unique identifier.
|
|
518
|
+
* NOTE: this only has an effect when using an external cross-device transition storage system.
|
|
519
|
+
* NOTE: you cannot read the identified visitor ID back from the storage system once it is set.
|
|
520
|
+
*/
|
|
521
|
+
type IdentifyCommand = StorageCommand<'identify', {
|
|
522
|
+
identity: string;
|
|
523
|
+
}>;
|
|
524
|
+
/**
|
|
525
|
+
* Sets whether the current visitor is in the personalization control group
|
|
526
|
+
* (Will not be exposed to personalization or gather classification data; WILL see A/B tests)
|
|
527
|
+
* In most cases this should not be sent as the membership is computed automatically for visitors;
|
|
528
|
+
* this command is intended mostly for diagnostics and testing purposes.
|
|
529
|
+
*/
|
|
530
|
+
type SetControlGroupCommand = StorageCommand<'setcontrol', boolean>;
|
|
531
|
+
type SetPersonalizeVariantControlCommand = StorageCommand<'setpersonalizecontrol', {
|
|
532
|
+
personlizationName: string;
|
|
533
|
+
index: number;
|
|
534
|
+
control: boolean;
|
|
535
|
+
}>;
|
|
536
|
+
declare const areCommandsEqual: (a: StorageCommands, b: StorageCommands) => boolean;
|
|
537
|
+
|
|
538
|
+
type TransitionDataStoreOptions = {
|
|
539
|
+
initialData?: Partial<VisitorData>;
|
|
540
|
+
};
|
|
541
|
+
type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests' | 'personalizeVariants'> & {
|
|
542
|
+
/**
|
|
543
|
+
* Server Score Vector - the resultant scores _on the server side_ after the server/edge render completes
|
|
544
|
+
* Note that the client side does not trust these scores; they are only used until it's done with initial
|
|
545
|
+
* recomputation.
|
|
546
|
+
*/
|
|
547
|
+
ssv?: ScoreVector;
|
|
548
|
+
/**
|
|
549
|
+
* Storage commands that the server
|
|
550
|
+
*/
|
|
551
|
+
commands?: StorageCommands[];
|
|
552
|
+
/**
|
|
553
|
+
* Composition metadata from the server side
|
|
554
|
+
*/
|
|
555
|
+
compositionMetadata?: CompositionMetadata;
|
|
556
|
+
};
|
|
557
|
+
declare const SERVER_STATE_ID = "__UNIFORM_DATA__";
|
|
558
|
+
type TransitionDataStoreEvents = {
|
|
559
|
+
/**
|
|
560
|
+
* Fired when the data is updated asynchronously
|
|
561
|
+
* (i.e. a promise resolves with new data from a backend)
|
|
562
|
+
*
|
|
563
|
+
* NOT fired for synchronous updates (e.g. calling updateData()), unless this also results in an async update of the data afterwards.
|
|
564
|
+
* NOT fired if an asynchronous update does not result in any change compared to the last known data.
|
|
565
|
+
*/
|
|
566
|
+
dataUpdatedAsync: Partial<VisitorData>;
|
|
567
|
+
};
|
|
568
|
+
declare abstract class TransitionDataStore {
|
|
569
|
+
#private;
|
|
570
|
+
constructor({ initialData }: TransitionDataStoreOptions);
|
|
571
|
+
get data(): Partial<VisitorData> | undefined;
|
|
572
|
+
get initialData(): Partial<VisitorData> | undefined;
|
|
573
|
+
/**
|
|
574
|
+
* Subscribe to events from the transition storage
|
|
575
|
+
*/
|
|
576
|
+
readonly events: {
|
|
577
|
+
on: {
|
|
578
|
+
<Key extends "dataUpdatedAsync">(type: Key, handler: mitt.Handler<TransitionDataStoreEvents[Key]>): void;
|
|
579
|
+
(type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
|
|
580
|
+
};
|
|
581
|
+
off: {
|
|
582
|
+
<Key extends "dataUpdatedAsync">(type: Key, handler?: mitt.Handler<TransitionDataStoreEvents[Key]> | undefined): void;
|
|
583
|
+
(type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
|
|
707
584
|
};
|
|
708
585
|
};
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
586
|
+
/**
|
|
587
|
+
* Updates data in the transition storage.
|
|
588
|
+
* @param commands Commands to execute against existing stored value (event based stores)
|
|
589
|
+
* @param computedValue Pre-computed new value against existing value (object based stores)
|
|
590
|
+
* @returns Resolved promise when the data has been updated
|
|
591
|
+
*/
|
|
592
|
+
updateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
|
|
593
|
+
/**
|
|
594
|
+
* Deletes a visitor's stored data, forgetting them.
|
|
595
|
+
* @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
|
|
596
|
+
*/
|
|
597
|
+
delete(fromAllDevices?: boolean): Promise<void>;
|
|
598
|
+
/**
|
|
599
|
+
* Deletes a visitor's stored data, forgetting them.
|
|
600
|
+
* Important: do not emit any async score update events from this function.
|
|
601
|
+
* @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
|
|
602
|
+
*/
|
|
603
|
+
abstract handleDelete(fromAllDevices?: boolean): Promise<void>;
|
|
604
|
+
/**
|
|
605
|
+
* Updates visitor data in the transition store.
|
|
606
|
+
*
|
|
607
|
+
* NOTE: The updated data is optimistically stored in TransitionDataStore automatically,
|
|
608
|
+
* so unless the updated data is _changed_ by the backend data store, there is no need
|
|
609
|
+
* to emit async score changed events when the visitor data is done updating.
|
|
610
|
+
*/
|
|
611
|
+
abstract handleUpdateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
|
|
612
|
+
protected signalAsyncDataUpdate(newScores: Partial<VisitorData>): void;
|
|
613
|
+
/**
|
|
614
|
+
* When we load on the client side after a server side rendering has occurred (server to client transition),
|
|
615
|
+
* we can have a page script (ID: __UNIFORM_DATA__) that contains the computed visitor data from the SSR/edge render.
|
|
616
|
+
* This data is injected into the first render to allow score syncing and the server to request commands be applied
|
|
617
|
+
* to the client side data store.
|
|
618
|
+
*/
|
|
619
|
+
getClientTransitionState(): ServerToClientTransitionState | undefined;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
type DecayOptions = {
|
|
623
|
+
now: number;
|
|
624
|
+
lastUpd: number | undefined;
|
|
625
|
+
scores: ScoreVector;
|
|
626
|
+
sessionScores: ScoreVector;
|
|
627
|
+
onLogMessage?: (message: LogMessage) => void;
|
|
628
|
+
};
|
|
629
|
+
/**
|
|
630
|
+
* Computes decay of visitor scores over time.
|
|
631
|
+
* NOTE: it is expected that this function mutates the incoming score vectors,
|
|
632
|
+
* if it needs to apply score decay. The data store ensures immutability already.
|
|
633
|
+
*
|
|
634
|
+
* @returns true if any decay was applied, false otherwise
|
|
635
|
+
*/
|
|
636
|
+
type DecayFunction = (options: DecayOptions) => boolean;
|
|
637
|
+
|
|
638
|
+
type VisitorDataStoreOptions = {
|
|
639
|
+
/** Transition storage used to transfer server or edge side execution state to the client. Unused for client side only. */
|
|
640
|
+
transitionStore?: TransitionDataStore;
|
|
641
|
+
/** Duration of a 'visit' measured by this number of milliseconds without performing any updates */
|
|
642
|
+
visitLifespan?: number;
|
|
643
|
+
/** Personalization manifest data. If set, the data store will automatically apply score caps in the manifest data. */
|
|
644
|
+
manifest?: ManifestInstance;
|
|
645
|
+
/** Allows decaying of scores over time based on time between visits. Default: no decay */
|
|
646
|
+
decay?: DecayFunction;
|
|
647
|
+
/**
|
|
648
|
+
* Sets the default value of storage consent for new unknown visitors.
|
|
649
|
+
* If storage consent is not given, only in-memory data will be stored which is lost when the browser leaves the page.
|
|
650
|
+
* @default false - consent is not given for new visitors until they explicitly give it with an update command
|
|
651
|
+
*/
|
|
652
|
+
defaultConsent?: boolean;
|
|
653
|
+
/**
|
|
654
|
+
* Function called when server-to-client transfer state is loaded and contains server-side computed scores.
|
|
655
|
+
* These scores are used as a temporary shim for the current scores on the client side, until score computation
|
|
656
|
+
* is completed the first time (which occurs when the current url is fed into the Context).
|
|
657
|
+
*
|
|
658
|
+
* Because the feed of the URL may be marginally delayed (for example in React it's in an effect so it's a second render),
|
|
659
|
+
* one render might be done with _no_ scores unless we dropped the server scores in temporarily, resulting in a flash of unpersonalized content.
|
|
660
|
+
*/
|
|
661
|
+
onServerTransitionReceived?: (state: ServerToClientTransitionState) => void;
|
|
662
|
+
/** Called when a log message is emitted from the data store */
|
|
663
|
+
onLogMessage?: (message: LogMessage) => void;
|
|
664
|
+
/**
|
|
665
|
+
* Optionally specify a prefix for all storage keys.
|
|
666
|
+
* Only required if using multiple Context instances on the same domain and need to separate them.
|
|
667
|
+
*/
|
|
668
|
+
partitionKey?: string;
|
|
669
|
+
};
|
|
670
|
+
type VisitorDataStoreEvents = {
|
|
671
|
+
/**
|
|
672
|
+
* Fired when the stored data is updated.
|
|
673
|
+
* This is fired for any update, whether from integrated or transition storage.
|
|
674
|
+
* The event is NOT fired if an update does not result in any score changes.
|
|
675
|
+
*/
|
|
676
|
+
scoresUpdated: Pick<VisitorData, 'scores' | 'sessionScores'>;
|
|
677
|
+
/**
|
|
678
|
+
* Fired when stored quirks are updated.
|
|
679
|
+
* This is fired for any update, whether from integrated or transition storage.
|
|
680
|
+
* The event is NOT fired if an update does not result in any quirk changes.
|
|
681
|
+
*/
|
|
682
|
+
quirksUpdated: Pick<VisitorData, 'quirks'>;
|
|
683
|
+
/**
|
|
684
|
+
* Fired when test variant selection is updated.
|
|
685
|
+
*/
|
|
686
|
+
testsUpdated: Pick<VisitorData, 'tests'>;
|
|
687
|
+
/**
|
|
688
|
+
* Fired when storage consent is changed
|
|
689
|
+
*/
|
|
690
|
+
consentUpdated: Pick<VisitorData, 'consent'>;
|
|
691
|
+
/**
|
|
692
|
+
* Fired when visitor control group membership is changed
|
|
693
|
+
*/
|
|
694
|
+
controlGroupUpdated: Pick<VisitorData, 'controlGroup'>;
|
|
695
|
+
/**
|
|
696
|
+
* Fired when a goal is converted
|
|
697
|
+
*/
|
|
698
|
+
goalConverted: {
|
|
699
|
+
goalId: string;
|
|
700
|
+
};
|
|
701
|
+
/** Fired when storage update commands are done executing */
|
|
702
|
+
commandsExecuted: StorageCommands[];
|
|
703
|
+
};
|
|
704
|
+
declare class VisitorDataStore {
|
|
705
|
+
#private;
|
|
706
|
+
constructor(options: VisitorDataStoreOptions);
|
|
707
|
+
/** Gets the current visitor data. This property is always up to date. */
|
|
708
|
+
get data(): VisitorData;
|
|
709
|
+
get decayEnabled(): boolean;
|
|
710
|
+
get options(): VisitorDataStoreOptions;
|
|
711
|
+
/**
|
|
712
|
+
* Subscribe to events from storage
|
|
713
|
+
*/
|
|
714
|
+
readonly events: {
|
|
715
|
+
on: {
|
|
716
|
+
<Key extends keyof VisitorDataStoreEvents>(type: Key, handler: mitt.Handler<VisitorDataStoreEvents[Key]>): void;
|
|
717
|
+
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
|
743
718
|
};
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
[name: string]: unknown;
|
|
748
|
-
};
|
|
749
|
-
content?: never;
|
|
719
|
+
off: {
|
|
720
|
+
<Key extends keyof VisitorDataStoreEvents>(type: Key, handler?: mitt.Handler<VisitorDataStoreEvents[Key]> | undefined): void;
|
|
721
|
+
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
|
750
722
|
};
|
|
751
723
|
};
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
724
|
+
/** Push data update command(s) into the visitor data */
|
|
725
|
+
updateData(commands: StorageCommands[]): Promise<void>;
|
|
726
|
+
/**
|
|
727
|
+
* Deletes visitor data (forgetting them)
|
|
728
|
+
* In most cases you should use forget() on the Context instead of this function, which also clears the Context state.
|
|
729
|
+
* @param fromAllDevices for an identified user, whether to delete all their data (for the entire account) - true, or data for this device (sign out) - false
|
|
730
|
+
*/
|
|
731
|
+
delete(fromAllDevices: boolean): Promise<void>;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
declare class ManifestInstance {
|
|
735
|
+
#private;
|
|
736
|
+
readonly data: ManifestV2;
|
|
737
|
+
constructor({ manifest, evaluator, onLogMessage, }: {
|
|
738
|
+
manifest: ManifestV2;
|
|
739
|
+
evaluator?: GroupCriteriaEvaluator;
|
|
740
|
+
onLogMessage?: (message: LogMessage) => void;
|
|
741
|
+
});
|
|
742
|
+
rollForControlGroup(): boolean;
|
|
743
|
+
getTest(name: string): TestDefinition | undefined;
|
|
744
|
+
computeSignals(update: ContextStateUpdate): StorageCommands[];
|
|
745
|
+
computeGoals(data: GoalStateUpdate): StorageCommands[];
|
|
746
|
+
/**
|
|
747
|
+
* Computes aggregated scores based on other dimensions
|
|
748
|
+
*/
|
|
749
|
+
computeAggregateDimensions(primitiveScores: ScoreVector): ScoreVector;
|
|
750
|
+
getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
|
|
751
|
+
getAggregateDimensionByKey(scoreKey: string): AggregateDimension | undefined;
|
|
756
752
|
}
|
|
757
753
|
|
|
758
754
|
type ManifestV2 = components['schemas']['ManifestV2'];
|
|
@@ -1400,4 +1396,4 @@ declare global {
|
|
|
1400
1396
|
}
|
|
1401
1397
|
}
|
|
1402
1398
|
|
|
1403
|
-
export {
|
|
1399
|
+
export { GroupCriteriaEvaluator as $, type AggregateDimension as A, type BehaviorTag as B, type ContextPlugin as C, type DecayFunction as D, type DevToolsDataEvent as E, type DevToolsEvent as F, type DevToolsForgetEvent as G, type DevToolsHelloEvent as H, type DevToolsLogEvent as I, type DevToolsRawCommandsEvent as J, type DevToolsState as K, type LogDrain as L, type ManifestV2 as M, type DevToolsUiVersion as N, type OutputSeverity as O, type PersonalizedVariant as P, type Quirks as Q, type DevToolsUpdateEvent as R, type ScoreVector as S, TransitionDataStore as T, type DimensionMatch as U, type VisitorData as V, type EnrichmentCategory as W, type EnrichmentData as X, type EventData as Y, type GoalStateUpdate as Z, type Goals as _, type StorageCommands as a, type IdentifyCommand as a0, type LogMessageGroup as a1, type LogMessageSingle as a2, type LogMessages as a3, ManifestInstance as a4, type MessageCategory as a5, type MessageFunc as a6, type ModifyScoreCommand as a7, type ModifySessionScoreCommand as a8, type NumberMatch as a9, type TestVariant as aA, type Tests as aB, type TransitionDataStoreEvents as aC, type VariationMatchMetadata as aD, VisitorDataStore as aE, type VisitorDataStoreEvents as aF, type VisitorDataStoreOptions as aG, areCommandsEqual as aH, emptyVisitorData as aI, testVariations as aJ, type PersonalizationEvent as aa, type PersonalizationEventVariantId as ab, type PersonalizationManifest as ac, type PersonalizationSelectionAlgorithm as ad, type PersonalizationSelectionAlgorithms as ae, type PersonalizeControlVariant as af, type PersonalizeVariants as ag, type QuirkMatch as ah, SERVER_STATE_ID as ai, type ServerToClientTransitionState as aj, type SetConsentCommand as ak, type SetControlGroupCommand as al, type SetGoalCommand as am, type SetPersonalizeVariantControlCommand as an, type SetQuirkCommand as ao, type SetTestCommand as ap, type Severity as aq, type Signal as ar, type SignalCriteria as as, type SignalCriteriaGroup as at, type SignalData as au, type StorageCommand as av, type TestDefinition as aw, type TestEvent as ax, type TestOptions as ay, type TestResult as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type PersonalizeOptions as g, Context as h, type PersonalizedResult as i, type VariationMatchDimensionCriteria as j, type PersonalizationSelectionAlgorithmOptions as k, type DevToolsEvents as l, type AggregateDimensionInput as m, CONTEXTUAL_EDITING_TEST_NAME as n, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as o, type paths as p, type CompositionMetadata as q, type ContextEvents as r, type ContextInstance as s, type ContextOptions as t, type ContextState as u, type ContextStateUpdate as v, type CriteriaEvaluatorParameters as w, type CriteriaEvaluatorResult as x, type DecayOptions as y, type DevToolsActions as z };
|