@uniformdev/context 19.96.1-alpha.13 → 19.99.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/package.json +2 -2
- package/dist/types-HD0emm2V.d.mts +0 -1140
- package/dist/types-HD0emm2V.d.ts +0 -1140
package/dist/types-HD0emm2V.d.ts
DELETED
@@ -1,1140 +0,0 @@
|
|
1
|
-
import * as mitt from 'mitt';
|
2
|
-
|
3
|
-
type Quirks = {
|
4
|
-
[key: string]: string;
|
5
|
-
};
|
6
|
-
type Tests = {
|
7
|
-
[key: string]: string;
|
8
|
-
};
|
9
|
-
type ScoreVector = {
|
10
|
-
[key: string]: number;
|
11
|
-
};
|
12
|
-
type EnrichmentData = {
|
13
|
-
/** Enrichment category name */
|
14
|
-
cat: string;
|
15
|
-
/** Enrichment key value */
|
16
|
-
key: string;
|
17
|
-
/** Strength value (amount of score added when viewing content) */
|
18
|
-
str: number;
|
19
|
-
};
|
20
|
-
/** An event that has occurred (i.e. an analytics track) which may trigger an Event signal */
|
21
|
-
type EventData = {
|
22
|
-
/** The event name that has been fired */
|
23
|
-
event: string;
|
24
|
-
};
|
25
|
-
type VisitorData = {
|
26
|
-
/**
|
27
|
-
* Quirk key-value data.
|
28
|
-
* NOTE: Context.quirks is more commonly correct if you need to read quirks data.
|
29
|
-
*/
|
30
|
-
quirks: Quirks;
|
31
|
-
/** A/B test variant selections */
|
32
|
-
tests: Tests;
|
33
|
-
/**
|
34
|
-
* Personalization score data for the current session (merge with all time for totals)
|
35
|
-
* NOTE: Context.scores is more commonly correct to read scores instead of this value.
|
36
|
-
*/
|
37
|
-
sessionScores: ScoreVector;
|
38
|
-
/**
|
39
|
-
* Personalization score data for all time (merge with session for totals)
|
40
|
-
* NOTE: Context.scores is more commonly correct to read scores instead of this value.
|
41
|
-
*/
|
42
|
-
scores: ScoreVector;
|
43
|
-
/**
|
44
|
-
* Whether consent has been given to store the visitor data
|
45
|
-
* If false or not set: visitor data is stored in memory and is lost if the browser refreshes
|
46
|
-
* If true: visitor data is stored in localStorage and any other transition storage if registered
|
47
|
-
*/
|
48
|
-
consent?: boolean;
|
49
|
-
/**
|
50
|
-
* Whether the visitor has been assigned to the personalization control group -
|
51
|
-
* visitors who are not shown personalization. If this is true, all scores will be zeroed,
|
52
|
-
* and score updates will be ignored. This has no effect on quirks or tests.
|
53
|
-
*
|
54
|
-
* If this value is not set, a random roll will be performed to determine membership,
|
55
|
-
* based on the control group size.
|
56
|
-
*/
|
57
|
-
controlGroup?: boolean;
|
58
|
-
};
|
59
|
-
declare const emptyVisitorData: () => VisitorData;
|
60
|
-
/**
|
61
|
-
* Expresses a 'patch' to the Uniform Context state
|
62
|
-
*/
|
63
|
-
type ContextState = {
|
64
|
-
cookies: Record<string, string>;
|
65
|
-
url?: URL;
|
66
|
-
quirks: Quirks;
|
67
|
-
enrichments: EnrichmentData[];
|
68
|
-
events: EventData[];
|
69
|
-
};
|
70
|
-
type ContextStateUpdate = {
|
71
|
-
state: Partial<ContextState>;
|
72
|
-
previousState: Partial<ContextState>;
|
73
|
-
visitor: VisitorData;
|
74
|
-
scores: ScoreVector;
|
75
|
-
};
|
76
|
-
|
77
|
-
type StorageCommand<TID extends string = string, TData = unknown> = {
|
78
|
-
type: TID;
|
79
|
-
data: TData;
|
80
|
-
};
|
81
|
-
/** Commands that can be issued to alter the storage of Uniform Context data */
|
82
|
-
type StorageCommands = ModifyScoreCommand | ModifySessionScoreCommand | SetConsentCommand | SetQuirkCommand | SetTestCommand | IdentifyCommand | SetControlGroupCommand;
|
83
|
-
/**
|
84
|
-
* Changes the visitor's permanent score for a given dimension
|
85
|
-
*/
|
86
|
-
type ModifyScoreCommand = StorageCommand<'modscore', {
|
87
|
-
dimension: string;
|
88
|
-
delta: number;
|
89
|
-
}>;
|
90
|
-
/**
|
91
|
-
* Changes the visitor's session (time-based) score for a given dimension
|
92
|
-
*/
|
93
|
-
type ModifySessionScoreCommand = StorageCommand<'modscoreS', {
|
94
|
-
dimension: string;
|
95
|
-
delta: number;
|
96
|
-
}>;
|
97
|
-
/**
|
98
|
-
* Changes the visitor's storage consent setting.
|
99
|
-
* Setting consent to false will trigger deletion of any stored data for the visitor.
|
100
|
-
* Scores are still collected in-memory when consent is false; just not persisted.
|
101
|
-
*/
|
102
|
-
type SetConsentCommand = StorageCommand<'consent', boolean>;
|
103
|
-
/** Sets a permanent quirk key and value for the visitor */
|
104
|
-
type SetQuirkCommand = StorageCommand<'setquirk', {
|
105
|
-
key: string;
|
106
|
-
value: string;
|
107
|
-
}>;
|
108
|
-
/** Sets a specific variant as being this visitor's variant on an A/B test */
|
109
|
-
type SetTestCommand = StorageCommand<'settest', {
|
110
|
-
test: string;
|
111
|
-
variant: string;
|
112
|
-
}>;
|
113
|
-
/**
|
114
|
-
* Identifies the visitor as being a specific unique identifier.
|
115
|
-
* NOTE: this only has an effect when using an external cross-device transition storage system.
|
116
|
-
* NOTE: you cannot read the identified visitor ID back from the storage system once it is set.
|
117
|
-
*/
|
118
|
-
type IdentifyCommand = StorageCommand<'identify', {
|
119
|
-
identity: string;
|
120
|
-
}>;
|
121
|
-
/**
|
122
|
-
* Sets whether the current visitor is in the personalization control group
|
123
|
-
* (Will not be exposed to personalization or gather classification data; WILL see A/B tests)
|
124
|
-
* In most cases this should not be sent as the membership is computed automatically for visitors;
|
125
|
-
* this command is intended mostly for diagnostics and testing purposes.
|
126
|
-
*/
|
127
|
-
type SetControlGroupCommand = StorageCommand<'setcontrol', boolean>;
|
128
|
-
|
129
|
-
type TransitionDataStoreOptions = {
|
130
|
-
initialData?: Partial<VisitorData>;
|
131
|
-
};
|
132
|
-
type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests'> & {
|
133
|
-
/**
|
134
|
-
* Server Score Vector - the resultant scores _on the server side_ after the server/edge render completes
|
135
|
-
* Note that the client side does not trust these scores; they are only used until it's done with initial
|
136
|
-
* recomputation.
|
137
|
-
*/
|
138
|
-
ssv?: ScoreVector;
|
139
|
-
};
|
140
|
-
declare const SERVER_STATE_ID = "__UNIFORM_DATA__";
|
141
|
-
type TransitionDataStoreEvents = {
|
142
|
-
/**
|
143
|
-
* Fired when the data is updated asynchronously
|
144
|
-
* (i.e. a promise resolves with new data from a backend)
|
145
|
-
*
|
146
|
-
* NOT fired for synchronous updates (e.g. calling updateData()), unless this also results in an async update of the data afterwards.
|
147
|
-
* NOT fired if an asynchronous update does not result in any change compared to the last known data.
|
148
|
-
*/
|
149
|
-
dataUpdatedAsync: Partial<VisitorData>;
|
150
|
-
};
|
151
|
-
declare abstract class TransitionDataStore {
|
152
|
-
#private;
|
153
|
-
constructor({ initialData }: TransitionDataStoreOptions);
|
154
|
-
get data(): Partial<VisitorData> | undefined;
|
155
|
-
get initialData(): Partial<VisitorData> | undefined;
|
156
|
-
/**
|
157
|
-
* Subscribe to events from the transition storage
|
158
|
-
*/
|
159
|
-
readonly events: {
|
160
|
-
on: {
|
161
|
-
<Key extends "dataUpdatedAsync">(type: Key, handler: mitt.Handler<TransitionDataStoreEvents[Key]>): void;
|
162
|
-
(type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
|
163
|
-
};
|
164
|
-
off: {
|
165
|
-
<Key_1 extends "dataUpdatedAsync">(type: Key_1, handler?: mitt.Handler<TransitionDataStoreEvents[Key_1]> | undefined): void;
|
166
|
-
(type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
|
167
|
-
};
|
168
|
-
};
|
169
|
-
/**
|
170
|
-
* Updates data in the transition storage.
|
171
|
-
* @param commands Commands to execute against existing stored value (event based stores)
|
172
|
-
* @param computedValue Pre-computed new value against existing value (object based stores)
|
173
|
-
* @returns Resolved promise when the data has been updated
|
174
|
-
*/
|
175
|
-
updateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
|
176
|
-
/**
|
177
|
-
* Deletes a visitor's stored data, forgetting them.
|
178
|
-
* @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
|
179
|
-
*/
|
180
|
-
delete(fromAllDevices?: boolean): Promise<void>;
|
181
|
-
/**
|
182
|
-
* Deletes a visitor's stored data, forgetting them.
|
183
|
-
* Important: do not emit any async score update events from this function.
|
184
|
-
* @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
|
185
|
-
*/
|
186
|
-
abstract handleDelete(fromAllDevices?: boolean): Promise<void>;
|
187
|
-
/**
|
188
|
-
* Updates visitor data in the transition store.
|
189
|
-
*
|
190
|
-
* NOTE: The updated data is optimistically stored in TransitionDataStore automatically,
|
191
|
-
* so unless the updated data is _changed_ by the backend data store, there is no need
|
192
|
-
* to emit async score changed events when the visitor data is done updating.
|
193
|
-
*/
|
194
|
-
abstract handleUpdateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
|
195
|
-
protected signalAsyncDataUpdate(newScores: Partial<VisitorData>): void;
|
196
|
-
/**
|
197
|
-
* When we load on the client side after a server side rendering has occurred (server to client transition),
|
198
|
-
* we can have a page script (ID: __UNIFORM_DATA__) that contains the computed visitor data from the SSR/edge render.
|
199
|
-
* This data is injected into the first render to allow score syncing and the server to request commands be applied
|
200
|
-
* to the client side data store.
|
201
|
-
*/
|
202
|
-
getClientTransitionState(): ServerToClientTransitionState | undefined;
|
203
|
-
}
|
204
|
-
|
205
|
-
type DecayOptions = {
|
206
|
-
now: number;
|
207
|
-
lastUpd: number | undefined;
|
208
|
-
scores: ScoreVector;
|
209
|
-
sessionScores: ScoreVector;
|
210
|
-
onLogMessage?: (message: LogMessage) => void;
|
211
|
-
};
|
212
|
-
/**
|
213
|
-
* Computes decay of visitor scores over time.
|
214
|
-
* NOTE: it is expected that this function mutates the incoming score vectors,
|
215
|
-
* if it needs to apply score decay. The data store ensures immutability already.
|
216
|
-
*
|
217
|
-
* @returns true if any decay was applied, false otherwise
|
218
|
-
*/
|
219
|
-
type DecayFunction = (options: DecayOptions) => boolean;
|
220
|
-
|
221
|
-
type VisitorDataStoreOptions = {
|
222
|
-
/** Transition storage used to transfer server or edge side execution state to the client. Unused for client side only. */
|
223
|
-
transitionStore?: TransitionDataStore;
|
224
|
-
/** Duration of a 'visit' measured by this number of milliseconds without performing any updates */
|
225
|
-
visitLifespan?: number;
|
226
|
-
/** Personalization manifest data. If set, the data store will automatically apply score caps in the manifest data. */
|
227
|
-
manifest?: ManifestInstance;
|
228
|
-
/** Allows decaying of scores over time based on time between visits. Default: no decay */
|
229
|
-
decay?: DecayFunction;
|
230
|
-
/**
|
231
|
-
* Sets the default value of storage consent for new unknown visitors.
|
232
|
-
* If storage consent is not given, only in-memory data will be stored which is lost when the browser leaves the page.
|
233
|
-
* @default false - consent is not given for new visitors until they explicitly give it with an update command
|
234
|
-
*/
|
235
|
-
defaultConsent?: boolean;
|
236
|
-
/**
|
237
|
-
* Function called when server-to-client transfer state is loaded and contains server-side computed scores.
|
238
|
-
* These scores are used as a temporary shim for the current scores on the client side, until score computation
|
239
|
-
* is completed the first time (which occurs when the current url is fed into the Context).
|
240
|
-
*
|
241
|
-
* 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),
|
242
|
-
* one render might be done with _no_ scores unless we dropped the server scores in temporarily, resulting in a flash of unpersonalized content.
|
243
|
-
*/
|
244
|
-
onServerTransitionReceived?: (state: ServerToClientTransitionState) => void;
|
245
|
-
/** Called when a log message is emitted from the data store */
|
246
|
-
onLogMessage?: (message: LogMessage) => void;
|
247
|
-
};
|
248
|
-
type VisitorDataStoreEvents = {
|
249
|
-
/**
|
250
|
-
* Fired when the stored data is updated.
|
251
|
-
* This is fired for any update, whether from integrated or transition storage.
|
252
|
-
* The event is NOT fired if an update does not result in any score changes.
|
253
|
-
*/
|
254
|
-
scoresUpdated: Pick<VisitorData, 'scores' | 'sessionScores'>;
|
255
|
-
/**
|
256
|
-
* Fired when stored quirks are updated.
|
257
|
-
* This is fired for any update, whether from integrated or transition storage.
|
258
|
-
* The event is NOT fired if an update does not result in any quirk changes.
|
259
|
-
*/
|
260
|
-
quirksUpdated: Pick<VisitorData, 'quirks'>;
|
261
|
-
/**
|
262
|
-
* Fired when test variant selection is updated.
|
263
|
-
*/
|
264
|
-
testsUpdated: Pick<VisitorData, 'tests'>;
|
265
|
-
/**
|
266
|
-
* Fired when storage consent is changed
|
267
|
-
*/
|
268
|
-
consentUpdated: Pick<VisitorData, 'consent'>;
|
269
|
-
/**
|
270
|
-
* Fired when visitor control group membership is changed
|
271
|
-
*/
|
272
|
-
controlGroupUpdated: Pick<VisitorData, 'controlGroup'>;
|
273
|
-
};
|
274
|
-
declare class VisitorDataStore {
|
275
|
-
#private;
|
276
|
-
constructor(options: VisitorDataStoreOptions);
|
277
|
-
/** Gets the current visitor data. This property is always up to date. */
|
278
|
-
get data(): VisitorData;
|
279
|
-
get decayEnabled(): boolean;
|
280
|
-
get options(): VisitorDataStoreOptions;
|
281
|
-
/**
|
282
|
-
* Subscribe to events from storage
|
283
|
-
*/
|
284
|
-
readonly events: {
|
285
|
-
on: {
|
286
|
-
<Key extends keyof VisitorDataStoreEvents>(type: Key, handler: mitt.Handler<VisitorDataStoreEvents[Key]>): void;
|
287
|
-
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
288
|
-
};
|
289
|
-
off: {
|
290
|
-
<Key_1 extends keyof VisitorDataStoreEvents>(type: Key_1, handler?: mitt.Handler<VisitorDataStoreEvents[Key_1]> | undefined): void;
|
291
|
-
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
292
|
-
};
|
293
|
-
};
|
294
|
-
/** Push data update command(s) into the visitor data */
|
295
|
-
updateData(commands: StorageCommands[]): Promise<void>;
|
296
|
-
/**
|
297
|
-
* Deletes visitor data (forgetting them)
|
298
|
-
* In most cases you should use forget() on the Context instead of this function, which also clears the Context state.
|
299
|
-
* @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
|
300
|
-
*/
|
301
|
-
delete(fromAllDevices: boolean): Promise<void>;
|
302
|
-
}
|
303
|
-
|
304
|
-
declare class ManifestInstance {
|
305
|
-
#private;
|
306
|
-
readonly data: ManifestV2;
|
307
|
-
constructor({ manifest, evaluator, onLogMessage, }: {
|
308
|
-
manifest: ManifestV2;
|
309
|
-
evaluator?: GroupCriteriaEvaluator;
|
310
|
-
onLogMessage?: (message: LogMessage) => void;
|
311
|
-
});
|
312
|
-
rollForControlGroup(): boolean;
|
313
|
-
getTest(name: string): TestDefinition | undefined;
|
314
|
-
computeSignals(update: ContextStateUpdate): StorageCommands[];
|
315
|
-
/**
|
316
|
-
* Computes aggregated scores based on other dimensions
|
317
|
-
*/
|
318
|
-
computeAggregateDimensions(primitiveScores: ScoreVector): ScoreVector;
|
319
|
-
getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
|
320
|
-
}
|
321
|
-
|
322
|
-
/**
|
323
|
-
* This file was auto-generated by openapi-typescript.
|
324
|
-
* Do not make direct changes to the file.
|
325
|
-
*/
|
326
|
-
interface paths {
|
327
|
-
"/api/v2/manifest": {
|
328
|
-
/**
|
329
|
-
* Fetches the Intent Manifest for a given project.
|
330
|
-
* 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).
|
331
|
-
*/
|
332
|
-
get: {
|
333
|
-
parameters: {
|
334
|
-
query: {
|
335
|
-
preview?: boolean;
|
336
|
-
projectId: string;
|
337
|
-
};
|
338
|
-
};
|
339
|
-
responses: {
|
340
|
-
/** OK */
|
341
|
-
200: {
|
342
|
-
content: {
|
343
|
-
"application/json": components["schemas"]["ManifestV2"];
|
344
|
-
};
|
345
|
-
};
|
346
|
-
400: external["swagger.yml"]["components"]["responses"]["BadRequestError"];
|
347
|
-
401: external["swagger.yml"]["components"]["responses"]["UnauthorizedError"];
|
348
|
-
403: external["swagger.yml"]["components"]["responses"]["ForbiddenError"];
|
349
|
-
/** No manifest has ever been published, and the API key does not have preview permissions */
|
350
|
-
404: {
|
351
|
-
content: {
|
352
|
-
"text/plain": string;
|
353
|
-
};
|
354
|
-
};
|
355
|
-
429: external["swagger.yml"]["components"]["responses"]["RateLimitError"];
|
356
|
-
500: external["swagger.yml"]["components"]["responses"]["InternalServerError"];
|
357
|
-
};
|
358
|
-
};
|
359
|
-
/** Handles preflight requests. This endpoint allows CORS. */
|
360
|
-
options: {
|
361
|
-
responses: {
|
362
|
-
/** OK */
|
363
|
-
204: never;
|
364
|
-
};
|
365
|
-
};
|
366
|
-
};
|
367
|
-
}
|
368
|
-
interface components {
|
369
|
-
schemas: {
|
370
|
-
ManifestV2: {
|
371
|
-
project: {
|
372
|
-
/**
|
373
|
-
* Format: uuid
|
374
|
-
* @description is not present unless getting a preview manifest
|
375
|
-
*/
|
376
|
-
id?: string;
|
377
|
-
/** @description is not present unless getting a preview manifest */
|
378
|
-
name?: string;
|
379
|
-
/** @description is not present unless getting a preview manifest */
|
380
|
-
ui_version?: number;
|
381
|
-
pz?: components["schemas"]["PersonalizationManifest"];
|
382
|
-
/** @description A/B test settings */
|
383
|
-
test?: {
|
384
|
-
[key: string]: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["Test"];
|
385
|
-
};
|
386
|
-
};
|
387
|
-
};
|
388
|
-
PersonalizationManifest: {
|
389
|
-
/** @description Map of all signals defined for personalization criteria */
|
390
|
-
sig?: {
|
391
|
-
[key: string]: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["Signal"];
|
392
|
-
};
|
393
|
-
/** @description Map of all enrichment categories defined for personalization criteria */
|
394
|
-
enr?: {
|
395
|
-
[key: string]: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["EnrichmentCategory"];
|
396
|
-
};
|
397
|
-
/** @description Map of all aggregate dimensions (intents or audiences) defined for personalization criteria */
|
398
|
-
agg?: {
|
399
|
-
[key: string]: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["AggregateDimension"];
|
400
|
-
};
|
401
|
-
/** @description Percentage of visitors that will be used as a personalization control group (not shown any personalization) */
|
402
|
-
control?: number;
|
403
|
-
};
|
404
|
-
};
|
405
|
-
}
|
406
|
-
interface external {
|
407
|
-
"swagger.yml": {
|
408
|
-
paths: {};
|
409
|
-
components: {
|
410
|
-
schemas: {
|
411
|
-
Error: {
|
412
|
-
/** @description Error message(s) that occurred while processing the request */
|
413
|
-
errorMessage?: string[] | string;
|
414
|
-
};
|
415
|
-
};
|
416
|
-
responses: {
|
417
|
-
/** Request input validation failed */
|
418
|
-
BadRequestError: {
|
419
|
-
content: {
|
420
|
-
"application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
|
421
|
-
};
|
422
|
-
};
|
423
|
-
/** API key or token was not valid */
|
424
|
-
UnauthorizedError: {
|
425
|
-
content: {
|
426
|
-
"application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
|
427
|
-
};
|
428
|
-
};
|
429
|
-
/** Permission was denied */
|
430
|
-
ForbiddenError: {
|
431
|
-
content: {
|
432
|
-
"application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
|
433
|
-
};
|
434
|
-
};
|
435
|
-
/** Resource not found */
|
436
|
-
NotFoundError: {
|
437
|
-
content: {
|
438
|
-
"application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
|
439
|
-
};
|
440
|
-
};
|
441
|
-
/** Too many requests in allowed time period */
|
442
|
-
RateLimitError: unknown;
|
443
|
-
/** Execution error occurred */
|
444
|
-
InternalServerError: unknown;
|
445
|
-
};
|
446
|
-
};
|
447
|
-
operations: {};
|
448
|
-
};
|
449
|
-
"uniform-context-types.swagger.yml": {
|
450
|
-
paths: {};
|
451
|
-
components: {
|
452
|
-
schemas: {
|
453
|
-
EnrichmentCategory: {
|
454
|
-
/** @description The maximum visitor score allowed for enrichment keys in this category */
|
455
|
-
cap: number;
|
456
|
-
};
|
457
|
-
PreviewSignal: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["Signal"] & {
|
458
|
-
/** @description Friendly name of the signal */
|
459
|
-
name: string;
|
460
|
-
/** @description Description of the signal */
|
461
|
-
description?: string;
|
462
|
-
};
|
463
|
-
Signal: {
|
464
|
-
/** @description The signal strength per activation (each time its criteria are true, this score is added) */
|
465
|
-
str: number;
|
466
|
-
/** @description The maximum visitor score allowed for this signal */
|
467
|
-
cap: number;
|
468
|
-
/**
|
469
|
-
* @description How long the signal's score should persist
|
470
|
-
* 's' = current session (expires after a period of inactivity)
|
471
|
-
* 'p' = permanent (expires as far in the future as possible, may be limited by browser security settings)
|
472
|
-
* 't' = transient (score tracks the current state of the criteria every time scores are updated)
|
473
|
-
*
|
474
|
-
* @enum {string}
|
475
|
-
*/
|
476
|
-
dur: "s" | "p" | "t";
|
477
|
-
crit: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["RootSignalCriteriaGroup"];
|
478
|
-
};
|
479
|
-
RootSignalCriteriaGroup: {
|
480
|
-
/**
|
481
|
-
* @description Criteria type (Group of other criteria)
|
482
|
-
* @enum {string}
|
483
|
-
*/
|
484
|
-
type: "G";
|
485
|
-
/**
|
486
|
-
* @description The logical operator to apply to the criteria groups
|
487
|
-
* & = AND
|
488
|
-
* | = OR
|
489
|
-
*
|
490
|
-
* Default is `&` if unspecified.
|
491
|
-
*
|
492
|
-
* @default &
|
493
|
-
* @enum {string}
|
494
|
-
*/
|
495
|
-
op?: "&" | "|";
|
496
|
-
/** @description The criteria clauses that make up this grouping of criteria */
|
497
|
-
clauses: (external["uniform-context-types.swagger.yml"]["components"]["schemas"]["SignalCriteriaGroup"] | external["uniform-context-types.swagger.yml"]["components"]["schemas"]["SignalCriteria"])[];
|
498
|
-
};
|
499
|
-
SignalCriteriaGroup: {
|
500
|
-
/**
|
501
|
-
* @description Criteria type (Group of other criteria)
|
502
|
-
* @enum {string}
|
503
|
-
*/
|
504
|
-
type: "G";
|
505
|
-
/**
|
506
|
-
* @description The logical operator to apply to the criteria groups
|
507
|
-
* & = AND
|
508
|
-
* | = OR
|
509
|
-
*
|
510
|
-
* Default is `&` if unspecified.
|
511
|
-
*
|
512
|
-
* @enum {string}
|
513
|
-
*/
|
514
|
-
op?: "&" | "|";
|
515
|
-
/** @description The criteria clauses that make up this grouping of criteria */
|
516
|
-
clauses: (external["uniform-context-types.swagger.yml"]["components"]["schemas"]["SignalCriteriaGroup"] | external["uniform-context-types.swagger.yml"]["components"]["schemas"]["SignalCriteria"])[];
|
517
|
-
};
|
518
|
-
SignalCriteria: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["CookieCriteria"] | external["uniform-context-types.swagger.yml"]["components"]["schemas"]["QueryStringCriteria"] | external["uniform-context-types.swagger.yml"]["components"]["schemas"]["QuirkCriteria"] | external["uniform-context-types.swagger.yml"]["components"]["schemas"]["EventCriteria"] | external["uniform-context-types.swagger.yml"]["components"]["schemas"]["CurrentPageCriteria"] | external["uniform-context-types.swagger.yml"]["components"]["schemas"]["PageViewCountCriteria"];
|
519
|
-
/** @description Matches a URL query string parameter value */
|
520
|
-
QueryStringCriteria: {
|
521
|
-
/** @enum {string} */
|
522
|
-
type: "QS";
|
523
|
-
/** @description The name of the query string parameter to match */
|
524
|
-
queryName: string;
|
525
|
-
/** @description The value to match the query string parameter against */
|
526
|
-
match: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["StringMatch"];
|
527
|
-
};
|
528
|
-
/** @description Matches a web cookie value */
|
529
|
-
CookieCriteria: {
|
530
|
-
/** @enum {string} */
|
531
|
-
type: "CK";
|
532
|
-
/** @description The name of the cookie to match */
|
533
|
-
cookieName: string;
|
534
|
-
/** @description The value to match the cookie against */
|
535
|
-
match: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["StringMatch"];
|
536
|
-
};
|
537
|
-
/** @description Matches a visitor quirk key and value */
|
538
|
-
QuirkCriteria: {
|
539
|
-
/** @enum {string} */
|
540
|
-
type: "QK";
|
541
|
-
/** @description The name of the quirk key to match */
|
542
|
-
key: string;
|
543
|
-
/** @description The quirk value to match against */
|
544
|
-
match: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["StringMatch"];
|
545
|
-
};
|
546
|
-
/** @description Matches an analytics event name being fired */
|
547
|
-
EventCriteria: {
|
548
|
-
/** @enum {string} */
|
549
|
-
type: "EVT";
|
550
|
-
/** @description How to match the event name */
|
551
|
-
event: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["StringMatch"];
|
552
|
-
};
|
553
|
-
/**
|
554
|
-
* @description Matches the current page's absolute path (i.e. /path/to/page.html)
|
555
|
-
* Does not include the query string or protocol and hostname (i.e. NOT https://foo.com/path/to/page.html?query=something)
|
556
|
-
*/
|
557
|
-
CurrentPageCriteria: {
|
558
|
-
/** @enum {string} */
|
559
|
-
type: "PV";
|
560
|
-
/** @description The page/route path to match as a page that has been visited */
|
561
|
-
path: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["StringMatch"];
|
562
|
-
};
|
563
|
-
PageViewCountCriteria: {
|
564
|
-
/** @enum {string} */
|
565
|
-
type: "PVC";
|
566
|
-
/** @description The expression to match the page view count against */
|
567
|
-
match: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["NumberMatch"];
|
568
|
-
};
|
569
|
-
/** @description Describes a match expression on a string */
|
570
|
-
StringMatch: {
|
571
|
-
/** @description The right hand side of the match expression */
|
572
|
-
rhs: string;
|
573
|
-
/**
|
574
|
-
* @description The match operator
|
575
|
-
* '=' = exact match
|
576
|
-
* '~' = contains match
|
577
|
-
* '//' = regular expression match
|
578
|
-
*
|
579
|
-
* Any of the above can be prefixed with '!' to invert the match (i.e. != for 'not an exact match')
|
580
|
-
*
|
581
|
-
* @enum {string}
|
582
|
-
*/
|
583
|
-
op: "=" | "~" | "//" | "!=" | "!~" | "!//";
|
584
|
-
/** @description The case sensitivity of the match. Defaults to false if unspecified. */
|
585
|
-
cs?: boolean;
|
586
|
-
} | {
|
587
|
-
/**
|
588
|
-
* @description The type of match to perform
|
589
|
-
* '*' = exists with any value
|
590
|
-
* '!*' = does not exist
|
591
|
-
*
|
592
|
-
* @enum {string}
|
593
|
-
*/
|
594
|
-
op: "*" | "!*";
|
595
|
-
};
|
596
|
-
/** @description Describes a match expression on a number */
|
597
|
-
NumberMatch: {
|
598
|
-
/** @description The right hand side of the match expression */
|
599
|
-
rhs: number;
|
600
|
-
/**
|
601
|
-
* @description The type of match to perform
|
602
|
-
* '=' = exact match
|
603
|
-
* '!=' = not an exact match
|
604
|
-
* '<' = less than match expression
|
605
|
-
* '>' = greater than match expression
|
606
|
-
*
|
607
|
-
* @enum {string}
|
608
|
-
*/
|
609
|
-
op: "=" | "<" | ">" | "!=";
|
610
|
-
};
|
611
|
-
/** @description Defines an aggregate dimension that is a grouping of other dimensions' scores; an intent or audience. */
|
612
|
-
AggregateDimension: {
|
613
|
-
/** @description Input dimensions to the aggregate dimension */
|
614
|
-
inputs: external["uniform-context-types.swagger.yml"]["components"]["schemas"]["AggregateDimensionInput"][];
|
615
|
-
};
|
616
|
-
/** @description Defines an input dimension to an aggregate dimension */
|
617
|
-
AggregateDimensionInput: {
|
618
|
-
/**
|
619
|
-
* @description Dimension name to reference as an input.
|
620
|
-
* For enrichment inputs, use CATEGORY_KEY as the dimension.
|
621
|
-
* Enrichments, signals, and other aggregate dimensions may be referenced.
|
622
|
-
*
|
623
|
-
* Note that creating a cycle of aggregate dimensions is allowed, however
|
624
|
-
* the final score will _ignore_ the cycled aggregate dimension in the result.
|
625
|
-
* This can be used to create mutually exclusive aggregates.
|
626
|
-
*/
|
627
|
-
dim: string;
|
628
|
-
/**
|
629
|
-
* @description The sign of the input dimension controls how it affects the aggregate dimension's final score.
|
630
|
-
*
|
631
|
-
* '+' = add to the final score
|
632
|
-
* '-' = subtract from the final score
|
633
|
-
* 'c' = clear the final score (if the input dimension has any score at all, this aggreate will have no score regardless of other inputs)
|
634
|
-
*
|
635
|
-
* Default if unspecified: '+'
|
636
|
-
*
|
637
|
-
* @default +
|
638
|
-
* @enum {string}
|
639
|
-
*/
|
640
|
-
sign?: "+" | "-" | "c";
|
641
|
-
};
|
642
|
-
Test: {
|
643
|
-
/** @description Winning variation ID - if set, the test will not run and this variation is shown to all visitors (the test is closed) */
|
644
|
-
wv?: string;
|
645
|
-
};
|
646
|
-
};
|
647
|
-
};
|
648
|
-
operations: {};
|
649
|
-
};
|
650
|
-
}
|
651
|
-
|
652
|
-
type SharedTypes = external['uniform-context-types.swagger.yml']['components']['schemas'];
|
653
|
-
type ManifestV2 = components['schemas']['ManifestV2'];
|
654
|
-
type PersonalizationManifest = components['schemas']['PersonalizationManifest'];
|
655
|
-
type Signal = SharedTypes['Signal'];
|
656
|
-
type SignalCriteriaGroup = SharedTypes['SignalCriteriaGroup'];
|
657
|
-
type SignalCriteria = SharedTypes['SignalCriteria'];
|
658
|
-
type EnrichmentCategory = SharedTypes['EnrichmentCategory'];
|
659
|
-
type StringMatch = SharedTypes['StringMatch'];
|
660
|
-
type NumberMatch = SharedTypes['NumberMatch'];
|
661
|
-
type TestDefinition = SharedTypes['Test'];
|
662
|
-
type AggregateDimension = SharedTypes['AggregateDimension'];
|
663
|
-
type AggregateDimensionInput = SharedTypes['AggregateDimensionInput'];
|
664
|
-
|
665
|
-
declare class GroupCriteriaEvaluator {
|
666
|
-
#private;
|
667
|
-
constructor(criteriaEvaluators: Record<string, CriteriaEvaluator>);
|
668
|
-
evaluate(update: ContextStateUpdate, crit: SignalCriteriaGroup, commands: StorageCommands[], signal: SignalData, onLogMessage?: (message: LogMessage) => void): CriteriaEvaluatorResult;
|
669
|
-
}
|
670
|
-
|
671
|
-
/**
|
672
|
-
* The result of evaluating a signal criteria.
|
673
|
-
*/
|
674
|
-
type CriteriaEvaluatorResult = {
|
675
|
-
/** Whether the criteria evaluated to true or not */
|
676
|
-
result: boolean;
|
677
|
-
/**
|
678
|
-
* Whether the value of the criteria changed from the previous state
|
679
|
-
* If ALL criteria on a signal have NOT changed, the signal is skipped
|
680
|
-
* and its score is left alone.
|
681
|
-
*/
|
682
|
-
changed: boolean;
|
683
|
-
};
|
684
|
-
type CriteriaEvaluatorParameters = {
|
685
|
-
/** The update being made to the Context state */
|
686
|
-
update: ContextStateUpdate;
|
687
|
-
/** Current criteria to evaluate the update against */
|
688
|
-
criteria: SignalCriteria;
|
689
|
-
/**
|
690
|
-
* The storage commands that will be executed by this update.
|
691
|
-
* If the evaluation requires custom commands, push them into this parameter.
|
692
|
-
* NOTE: needing to use this is very rare and should be avoided if possible.
|
693
|
-
*/
|
694
|
-
commands: StorageCommands[];
|
695
|
-
/** The parent signal containing the criteria we are evaluating */
|
696
|
-
signal: SignalData;
|
697
|
-
/** Function to emit log notices to the Context log */
|
698
|
-
onLogMessage?: (message: LogMessage) => void;
|
699
|
-
};
|
700
|
-
type SignalData = Signal & {
|
701
|
-
id: string;
|
702
|
-
};
|
703
|
-
/**
|
704
|
-
* A type that evaluates a signal criteria type and
|
705
|
-
* decides if it matches the current Context state or not.
|
706
|
-
*/
|
707
|
-
type CriteriaEvaluator = ((parameters: CriteriaEvaluatorParameters) => CriteriaEvaluatorResult) & {
|
708
|
-
/** If true the criteria will always execute even if a short-circuit would normally skip it */
|
709
|
-
alwaysExecute?: boolean;
|
710
|
-
};
|
711
|
-
|
712
|
-
/** Defines all error codes and their parameter(s) */
|
713
|
-
type LogMessages = {
|
714
|
-
/** Context constructed */
|
715
|
-
1: MessageFunc;
|
716
|
-
/** Context received data update */
|
717
|
-
2: MessageFunc<Partial<Omit<ContextState, 'url'> & {
|
718
|
-
url: string;
|
719
|
-
}>>;
|
720
|
-
/** Context emitted new score vector */
|
721
|
-
3: MessageFunc<ScoreVector>;
|
722
|
-
/** Context emitted updated quirks */
|
723
|
-
4: MessageFunc<Quirks>;
|
724
|
-
/** Tried to set enrichment category that did not exist */
|
725
|
-
5: MessageFunc<EnrichmentData>;
|
726
|
-
/** Storage received update commands */
|
727
|
-
101: MessageFunc<StorageCommands[]>;
|
728
|
-
/** Storage data was updated */
|
729
|
-
102: MessageFunc<VisitorData>;
|
730
|
-
/** Storage data was deleted bool: fromAllDevices */
|
731
|
-
103: MessageFunc<boolean>;
|
732
|
-
/** Visitor was assigned or removed from control group */
|
733
|
-
104: MessageFunc<boolean>;
|
734
|
-
/** Storage score was truncated to its cap */
|
735
|
-
110: MessageFunc<{
|
736
|
-
dim: string;
|
737
|
-
score: number;
|
738
|
-
cap: number;
|
739
|
-
}>;
|
740
|
-
/** Storage visitor data expired and was cleared */
|
741
|
-
120: MessageFunc;
|
742
|
-
/** Server to client transition score data was loaded */
|
743
|
-
130: MessageFunc<ServerToClientTransitionState>;
|
744
|
-
/** Server to client transition data was discarded */
|
745
|
-
131: MessageFunc;
|
746
|
-
/** Decay function executed */
|
747
|
-
140: MessageFunc<string>;
|
748
|
-
/** Signals evaluation beginning */
|
749
|
-
200: MessageFunc;
|
750
|
-
/** Evaluation of a specific signal beginning */
|
751
|
-
201: MessageFunc<SignalData>;
|
752
|
-
/** Evaluation of a group beginning */
|
753
|
-
202: MessageFunc<SignalCriteriaGroup>;
|
754
|
-
203: MessageFunc<{
|
755
|
-
criteria: SignalCriteria;
|
756
|
-
result: CriteriaEvaluatorResult;
|
757
|
-
explanation: string;
|
758
|
-
}>;
|
759
|
-
/** Result of evaluating a criteria group */
|
760
|
-
204: MessageFunc<CriteriaEvaluatorResult>;
|
761
|
-
/** Personalization placement executing */
|
762
|
-
300: MessageFunc<{
|
763
|
-
name: string;
|
764
|
-
take?: number;
|
765
|
-
}>;
|
766
|
-
/** Personalization placement testing variation */
|
767
|
-
301: MessageFunc<{
|
768
|
-
id: string;
|
769
|
-
op?: string;
|
770
|
-
}>;
|
771
|
-
/** Processed a personalization criteria */
|
772
|
-
302: MessageFunc<{
|
773
|
-
matched: boolean;
|
774
|
-
description: string;
|
775
|
-
}>;
|
776
|
-
/** Final result for a personalized variation */
|
777
|
-
303: MessageFunc<boolean>;
|
778
|
-
/** A/B test placement executing */
|
779
|
-
400: MessageFunc<string>;
|
780
|
-
/** A/B Test definition did not exist */
|
781
|
-
401: MessageFunc<string>;
|
782
|
-
/** Previously shown test variant no longer in variant data */
|
783
|
-
402: MessageFunc<{
|
784
|
-
missingVariant: string;
|
785
|
-
variants: string[];
|
786
|
-
}>;
|
787
|
-
/** Selected a new A/B test variation */
|
788
|
-
403: MessageFunc<string>;
|
789
|
-
/** Displaying A/B test variation */
|
790
|
-
404: MessageFunc<string>;
|
791
|
-
/** gtag was not present on the page to emit events to */
|
792
|
-
700: MessageFunc;
|
793
|
-
/** Enabled gtag event signal redirection */
|
794
|
-
701: MessageFunc;
|
795
|
-
};
|
796
|
-
|
797
|
-
type Severity = 'debug' | 'info' | 'warn' | 'error';
|
798
|
-
type MessageCategory = 'context' | 'storage' | 'testing' | 'personalization' | 'gtag' | 'signals';
|
799
|
-
type OutputSeverity = Severity | 'none';
|
800
|
-
type MessageFunc<TArg = void> = (arg: TArg) => [
|
801
|
-
/** Category of the message */
|
802
|
-
MessageCategory,
|
803
|
-
/** Log message text */
|
804
|
-
string,
|
805
|
-
/** Log message */
|
806
|
-
...unknown[]
|
807
|
-
];
|
808
|
-
type LogMessage = LogMessageSingle | LogMessageGroup;
|
809
|
-
type LogMessageSingle<TID extends keyof LogMessages = keyof LogMessages> = [
|
810
|
-
severity: Severity,
|
811
|
-
id: TID,
|
812
|
-
...args: Parameters<LogMessages[TID]>
|
813
|
-
];
|
814
|
-
type LogMessageGroup<TID extends keyof LogMessages = keyof LogMessages> = [severity: Severity, id: TID, group: 'GROUP', ...args: Parameters<LogMessages[TID]>] | [severity: Severity, id: TID, group: 'ENDGROUP'];
|
815
|
-
type LogDrain = (message: LogMessage) => void;
|
816
|
-
|
817
|
-
type VariantMatchCriteria = {
|
818
|
-
/**
|
819
|
-
* Operation for match criteria
|
820
|
-
*
|
821
|
-
* @defaultValue `&`
|
822
|
-
*/
|
823
|
-
op?: '&' | '|';
|
824
|
-
crit: DimensionMatch[];
|
825
|
-
/**
|
826
|
-
* Name of the variant for analytics tracking.
|
827
|
-
*/
|
828
|
-
name?: string;
|
829
|
-
};
|
830
|
-
type DimensionMatch = {
|
831
|
-
/**
|
832
|
-
* Left hand side of the match expression (name of dimension in score vector)
|
833
|
-
* NOTE: if the dimension is not present in the score vector, it will be treated as if it has a value of 0
|
834
|
-
*/
|
835
|
-
l: string;
|
836
|
-
/**
|
837
|
-
* Operator of the match expression
|
838
|
-
* Whole-vector (RHS only) operators - these do not require a `r` or `rDim` set:
|
839
|
-
* +: `l` is the strongest dimension in the score vector
|
840
|
-
* -: `l` is the weakest dimension in the score vector. This does not match if the dimension has no score at all.
|
841
|
-
*
|
842
|
-
* Comparison operators:
|
843
|
-
* >: `l` is greater than the right hand side expression
|
844
|
-
* >= : `l` is greater than or equal to the right hand side expression
|
845
|
-
* <: `l` is less than the right hand side expression
|
846
|
-
* <= : `l` is less than or equal to the right hand side expression
|
847
|
-
* =: `l` is equal to the right hand side expression
|
848
|
-
* !=: `l` is not equal to the right hand side expression
|
849
|
-
*/
|
850
|
-
op: '+' | '-' | '>' | '>=' | '<' | '<=' | '=' | '!=';
|
851
|
-
/**
|
852
|
-
* Right hand side of the match expression (not required for op = + or - which have no right side)
|
853
|
-
* This value is treated as a constant value, if it is present. If it's a string, it is parsed to an integer.
|
854
|
-
* To reference another score dimension as the RHS, use the `rDim` property instead.
|
855
|
-
* `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
|
856
|
-
*/
|
857
|
-
r?: number | string;
|
858
|
-
/**
|
859
|
-
* Right hand side of the match expression (not required for op = + or - which have no right side)
|
860
|
-
* This value is treated as a reference to another score dimension, if it is present in the score vector.
|
861
|
-
* If the referenced dimension is NOT present in the score vector, the match will always be false.
|
862
|
-
* To reference a constant value instead as the RHS, use the `r` property instead.
|
863
|
-
* `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
|
864
|
-
*/
|
865
|
-
rDim?: string;
|
866
|
-
};
|
867
|
-
|
868
|
-
/** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
|
869
|
-
type BehaviorTag = {
|
870
|
-
beh?: EnrichmentData[];
|
871
|
-
};
|
872
|
-
/** Defines the shape of a personalized content variant */
|
873
|
-
type PersonalizedVariant = {
|
874
|
-
/** A unique identifier for this variation */
|
875
|
-
id: string;
|
876
|
-
/** Match criteria for this variation */
|
877
|
-
pz?: VariantMatchCriteria;
|
878
|
-
};
|
879
|
-
/** The result of computing personalized content from variations */
|
880
|
-
type PersonalizedResult<TVariant> = {
|
881
|
-
/** Whether or not this result contains a personalized result */
|
882
|
-
personalized: boolean;
|
883
|
-
/** Matching variations */
|
884
|
-
variations: Array<TVariant>;
|
885
|
-
};
|
886
|
-
/** Defines the shape of a A/B test variant */
|
887
|
-
type TestVariant = {
|
888
|
-
/** The identifier for this variant. This value persisted to storage when a variant is selected. */
|
889
|
-
id: string;
|
890
|
-
/**
|
891
|
-
* A number between 0 and 100 representing what percentage of visitors will be selected for this variant.
|
892
|
-
* If not provided, this variant will be selected in equal proportion to other variants without an explicit distribution.
|
893
|
-
*/
|
894
|
-
testDistribution?: number;
|
895
|
-
};
|
896
|
-
/** The result of computing an A/B test result */
|
897
|
-
type TestResult<TVariant> = {
|
898
|
-
/** The selected variation */
|
899
|
-
result: TVariant | undefined;
|
900
|
-
/**
|
901
|
-
* Whether the test variant was newly assigned to the visitor.
|
902
|
-
* True: variant was assigned to the visitor for the first time.
|
903
|
-
* False: variant was already assigned to the visitor and is being reused.
|
904
|
-
*/
|
905
|
-
variantAssigned: boolean;
|
906
|
-
};
|
907
|
-
|
908
|
-
type PersonalizeOptions<TVariant> = {
|
909
|
-
/** Name of placement (sent to analytics) */
|
910
|
-
name: string;
|
911
|
-
/** Possible variants to place */
|
912
|
-
variations: Iterable<TVariant>;
|
913
|
-
/** Maximum number of variants to place (default: 1) */
|
914
|
-
take?: number;
|
915
|
-
onLogMessage?: (message: LogMessage) => void;
|
916
|
-
};
|
917
|
-
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations, take, onLogMessage, }: PersonalizeOptions<TVariant> & {
|
918
|
-
context: Context;
|
919
|
-
}): PersonalizedResult<TVariant>;
|
920
|
-
|
921
|
-
type TestOptions<TVariant extends TestVariant> = {
|
922
|
-
/** The name of the test that is being run, must be included in the manifest. */
|
923
|
-
name: string;
|
924
|
-
/** Variations that are being tested. */
|
925
|
-
variations: TVariant[];
|
926
|
-
};
|
927
|
-
declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, onLogMessage, }: TestOptions<TVariant> & {
|
928
|
-
context: Context;
|
929
|
-
onLogMessage?: ((message: LogMessage) => void) | undefined;
|
930
|
-
}) => TestResult<TVariant>;
|
931
|
-
|
932
|
-
declare const CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
933
|
-
declare const CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
934
|
-
/**
|
935
|
-
* Defines a plugin for Uniform Context.
|
936
|
-
* The plugin should attach event handlers in its creation function.
|
937
|
-
* @returns A function that detaches any event handlers when called
|
938
|
-
*/
|
939
|
-
type ContextPlugin = {
|
940
|
-
logDrain?: LogDrain;
|
941
|
-
init?: (context: Context) => () => void;
|
942
|
-
};
|
943
|
-
type ContextOptions = {
|
944
|
-
/** The Context Manifest to load (from the Context API) */
|
945
|
-
manifest: ManifestV2;
|
946
|
-
/**
|
947
|
-
* Context plugins to load at initialize time.
|
948
|
-
* Plugins that hook to the log event should be added here so that they can catch init-time log message events.
|
949
|
-
*
|
950
|
-
* Note that the Context passed to the plugin is not yet fully initialized, and is intended for event handler attachment
|
951
|
-
* only - don't call scores, update, etc on it. If you need to call these methods immediately, attach your plugin after initialisation.
|
952
|
-
*/
|
953
|
-
plugins?: Array<ContextPlugin>;
|
954
|
-
} & Omit<VisitorDataStoreOptions, 'manifest' | 'onServerTransitionScoresReceived'>;
|
955
|
-
/** Emitted when a personalization runs */
|
956
|
-
type PersonalizationEvent = {
|
957
|
-
/** Name of the personalized placement */
|
958
|
-
name: string;
|
959
|
-
/** Selected variant ID(s) */
|
960
|
-
variantIds: string[];
|
961
|
-
/** Whether the user was part of the control group (and did not receive any personalization) */
|
962
|
-
control: boolean | undefined;
|
963
|
-
/**
|
964
|
-
* Whether the personalized placement has changed since the last time the placement was evaluated.
|
965
|
-
* True: the placement was evaluated for the first time, or the variant(s) selected changed from last time (e.g. due to a score change that activated a new variant).
|
966
|
-
* False: the variant(s) selected were the same as a previous evaluation of this placement.
|
967
|
-
*/
|
968
|
-
changed: boolean;
|
969
|
-
};
|
970
|
-
/** Emitted event when an A/B test runs */
|
971
|
-
type TestEvent = {
|
972
|
-
/** Name (public ID) of the A/B test */
|
973
|
-
name: string;
|
974
|
-
/** ID of the variant that was selected */
|
975
|
-
variantId: string | undefined;
|
976
|
-
/**
|
977
|
-
* Whether the test variant was newly assigned to the visitor.
|
978
|
-
* True: variant was assigned to the visitor for the first time.
|
979
|
-
* False: variant was already assigned to the visitor and is being reused.
|
980
|
-
*/
|
981
|
-
variantAssigned: boolean;
|
982
|
-
};
|
983
|
-
type ContextEvents = {
|
984
|
-
/**
|
985
|
-
* Fired when the scores are updated.
|
986
|
-
* The event is NOT fired if an update does not result in any score changes.
|
987
|
-
* The result is merged between session and permanent data.
|
988
|
-
*/
|
989
|
-
scoresUpdated: Readonly<ScoreVector>;
|
990
|
-
/**
|
991
|
-
* Fired when quirk data changes. Not fired if no changes to quirks are made
|
992
|
-
* (e.g. setting it to the same value it already has)
|
993
|
-
*/
|
994
|
-
quirksUpdated: Quirks;
|
995
|
-
/**
|
996
|
-
* Fired when a log message is emitted from Context
|
997
|
-
* Note that event handlers attached to this event will not catch events
|
998
|
-
* logged during initialisation of the Context unless they are attached as plugins to the constructor.
|
999
|
-
*/
|
1000
|
-
log: LogMessage | LogMessageGroup;
|
1001
|
-
/** Test variant has been selected */
|
1002
|
-
testResult: TestEvent;
|
1003
|
-
/** Personalization variants have been selected */
|
1004
|
-
personalizationResult: PersonalizationEvent;
|
1005
|
-
};
|
1006
|
-
interface ContextInstance {
|
1007
|
-
get scores(): Readonly<ScoreVector>;
|
1008
|
-
get quirks(): Readonly<Quirks>;
|
1009
|
-
update(newData: Partial<ContextState>): Promise<void>;
|
1010
|
-
getTestVariantId(testName: string): string | null | undefined;
|
1011
|
-
setTestVariantId(testName: string, variantId: string): void;
|
1012
|
-
log(...message: LogMessage): void;
|
1013
|
-
test<TVariant extends TestVariant>(options: TestOptions<TVariant>): TestResult<TVariant>;
|
1014
|
-
personalize<TVariant extends PersonalizedVariant>(options: PersonalizeOptions<TVariant>): PersonalizedResult<TVariant>;
|
1015
|
-
forget(fromAllDevices: boolean): Promise<void>;
|
1016
|
-
getServerToClientTransitionState(): ServerToClientTransitionState;
|
1017
|
-
}
|
1018
|
-
declare class Context implements ContextInstance {
|
1019
|
-
#private;
|
1020
|
-
readonly manifest: ManifestInstance;
|
1021
|
-
constructor(options: ContextOptions);
|
1022
|
-
/** Gets the current visitor's dimension score vector. */
|
1023
|
-
get scores(): Readonly<ScoreVector>;
|
1024
|
-
/** Gets the current visitor's quirks values. */
|
1025
|
-
get quirks(): Readonly<Quirks>;
|
1026
|
-
/**
|
1027
|
-
* Subscribe to events
|
1028
|
-
*/
|
1029
|
-
readonly events: {
|
1030
|
-
on: {
|
1031
|
-
<Key extends keyof ContextEvents>(type: Key, handler: mitt.Handler<ContextEvents[Key]>): void;
|
1032
|
-
(type: "*", handler: mitt.WildcardHandler<ContextEvents>): void;
|
1033
|
-
};
|
1034
|
-
off: {
|
1035
|
-
<Key_1 extends keyof ContextEvents>(type: Key_1, handler?: mitt.Handler<ContextEvents[Key_1]> | undefined): void;
|
1036
|
-
(type: "*", handler: mitt.WildcardHandler<ContextEvents>): void;
|
1037
|
-
};
|
1038
|
-
};
|
1039
|
-
readonly storage: VisitorDataStore;
|
1040
|
-
/**
|
1041
|
-
* Updates the Context with new data of any sort, such as
|
1042
|
-
* new URLs, cookies, quirks, and enrichments.
|
1043
|
-
*
|
1044
|
-
* Only properties that are set in the data parameter will be updated.
|
1045
|
-
* Properties that do not result in a changed state,
|
1046
|
-
* i.e. pushing the same URL or cookies as before,
|
1047
|
-
* will NOT result in a recomputation of signal state.
|
1048
|
-
*/
|
1049
|
-
update(newData: Partial<ContextState>): Promise<void>;
|
1050
|
-
/** use test() instead */
|
1051
|
-
getTestVariantId(testName: string): string | null | undefined;
|
1052
|
-
/** use test() instead */
|
1053
|
-
setTestVariantId(testName: string, variantId: string): void;
|
1054
|
-
/**
|
1055
|
-
* Writes a message to the Context log sink.
|
1056
|
-
* Used by Uniform internal SDK; not intended for public use.
|
1057
|
-
*/
|
1058
|
-
log(...message: LogMessage): void;
|
1059
|
-
/** Executes an A/B test with a given set of variants, showing the visitor's assigned variant (or selecting one to assign, if none is set yet) */
|
1060
|
-
test<TVariant extends TestVariant>(options: TestOptions<TVariant>): TestResult<TVariant>;
|
1061
|
-
/** Executes a personalized placement with a given set of variants */
|
1062
|
-
personalize<TVariant extends PersonalizedVariant>(options: PersonalizeOptions<TVariant>): PersonalizedResult<TVariant>;
|
1063
|
-
/**
|
1064
|
-
* Forgets the visitor's data and resets the Context to its initial state.
|
1065
|
-
* @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
|
1066
|
-
*/
|
1067
|
-
forget(fromAllDevices: boolean): Promise<void>;
|
1068
|
-
/**
|
1069
|
-
* Computes server to client transition state.
|
1070
|
-
*
|
1071
|
-
* Removes state from server-to-client if it came in initial state (cookies) to avoid double tracking on the client.
|
1072
|
-
*/
|
1073
|
-
getServerToClientTransitionState(): ServerToClientTransitionState;
|
1074
|
-
}
|
1075
|
-
|
1076
|
-
/**
|
1077
|
-
* The version of the DevTools UI to load when in Chromium extension context.
|
1078
|
-
* 1: Uniform Optimize.
|
1079
|
-
* 2: Uniform Context.
|
1080
|
-
*/
|
1081
|
-
type DevToolsUiVersion = 1 | 2;
|
1082
|
-
/**
|
1083
|
-
* The data state provided to the devtools for rendering.
|
1084
|
-
*/
|
1085
|
-
type DevToolsState = {
|
1086
|
-
/** Current computed visitor scores (includes aggregates) */
|
1087
|
-
scores: Readonly<ScoreVector>;
|
1088
|
-
/** Current visitor data (includes quirks, raw scores, tests, consent, etc) */
|
1089
|
-
data: Readonly<VisitorData>;
|
1090
|
-
/** Personalization events that have fired since devtools started */
|
1091
|
-
personalizations: Array<PersonalizationEvent>;
|
1092
|
-
/** Test events that have fired since devtools started */
|
1093
|
-
tests: Array<TestEvent>;
|
1094
|
-
/** The Context manifest */
|
1095
|
-
manifest: ManifestV2;
|
1096
|
-
};
|
1097
|
-
/** Mutations the DevTools can take on the data it receives */
|
1098
|
-
type DevToolsActions = {
|
1099
|
-
/** Standard updates; maps to Context.update() */
|
1100
|
-
update: (newData: Partial<ContextState>) => Promise<void>;
|
1101
|
-
/** Raw updates to the storage subsystem. Maps to Context.storage.updateData() */
|
1102
|
-
rawUpdate: (commands: StorageCommands[]) => Promise<void>;
|
1103
|
-
/** Forget the current visitor and clear data on this device */
|
1104
|
-
forget: () => Promise<void>;
|
1105
|
-
};
|
1106
|
-
type DevToolsEvent<Type extends string = string, TEventData = unknown> = {
|
1107
|
-
/** The integration ID that is required */
|
1108
|
-
type: Type;
|
1109
|
-
} & TEventData;
|
1110
|
-
type DevToolsEvents = DevToolsLogEvent | DevToolsDataEvent | DevToolsHelloEvent | DevToolsUpdateEvent | DevToolsRawCommandsEvent | DevToolsForgetEvent;
|
1111
|
-
/** A log message emitted as an event to the browser extension */
|
1112
|
-
type DevToolsLogEvent = DevToolsEvent<'uniform:context:log', {
|
1113
|
-
message: LogMessage;
|
1114
|
-
}>;
|
1115
|
-
/** Emitted when data is updated in Context to the devtools */
|
1116
|
-
type DevToolsDataEvent = DevToolsEvent<'uniform:context:data', {
|
1117
|
-
data: DevToolsState;
|
1118
|
-
}>;
|
1119
|
-
/** A hello message emitted as an event from the browser extension to test if the page contains Context */
|
1120
|
-
type DevToolsHelloEvent = DevToolsEvent<'uniform:context:hello', {
|
1121
|
-
uiVersion: DevToolsUiVersion;
|
1122
|
-
}>;
|
1123
|
-
/** Devtools requests a normal update cycle (regular data update, re-eval signals, etc) */
|
1124
|
-
type DevToolsUpdateEvent = DevToolsEvent<'uniform-in:context:update', {
|
1125
|
-
newData: Partial<ContextState>;
|
1126
|
-
}>;
|
1127
|
-
/** Devtools requests a raw update cycle (explicitly set scores of dimensions in durations, etc) */
|
1128
|
-
type DevToolsRawCommandsEvent = DevToolsEvent<'uniform-in:context:commands', {
|
1129
|
-
commands: StorageCommands[];
|
1130
|
-
}>;
|
1131
|
-
/** A request to forget me from the DevTools */
|
1132
|
-
type DevToolsForgetEvent = DevToolsEvent<'uniform-in:context:forget', unknown>;
|
1133
|
-
declare global {
|
1134
|
-
interface Window {
|
1135
|
-
/** Window var set by enableContextDevTools() to enable embedded devtools to receive Context instance and attach events to it. */
|
1136
|
-
__UNIFORM_DEVTOOLS_CONTEXT_INSTANCE__?: Context;
|
1137
|
-
}
|
1138
|
-
}
|
1139
|
-
|
1140
|
-
export { type TestOptions as $, type AggregateDimension as A, type MessageFunc as B, type ContextPlugin as C, type DecayFunction as D, type LogMessageSingle as E, type LogMessageGroup as F, ManifestInstance as G, GroupCriteriaEvaluator as H, type CriteriaEvaluatorResult as I, type CriteriaEvaluatorParameters as J, type SignalData as K, type LogDrain as L, type MessageCategory as M, type ManifestV2 as N, type OutputSeverity as O, type PersonalizationEvent as P, type PersonalizationManifest as Q, type Signal as R, type ScoreVector as S, TransitionDataStore as T, type SignalCriteriaGroup as U, type VisitorData as V, type SignalCriteria as W, type EnrichmentCategory as X, type NumberMatch as Y, type TestDefinition as Z, type AggregateDimensionInput as _, type StorageCommands as a, testVariations as a0, type DimensionMatch as a1, type PersonalizeOptions as a2, personalizeVariations as a3, type BehaviorTag as a4, type PersonalizedVariant as a5, type PersonalizedResult as a6, type TestVariant as a7, type TestResult as a8, type StorageCommand as a9, type ModifyScoreCommand as aa, type ModifySessionScoreCommand as ab, type SetConsentCommand as ac, type SetQuirkCommand as ad, type SetTestCommand as ae, type IdentifyCommand as af, type SetControlGroupCommand as ag, type ServerToClientTransitionState as ah, SERVER_STATE_ID as ai, type TransitionDataStoreEvents as aj, type DecayOptions as ak, type VisitorDataStoreOptions as al, type VisitorDataStoreEvents as am, VisitorDataStore as an, type Quirks as ao, type Tests as ap, type EnrichmentData as aq, type EventData as ar, emptyVisitorData as as, type ContextState as at, type ContextStateUpdate as au, type paths as av, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type DevToolsEvents as g, CONTEXTUAL_EDITING_TEST_NAME as h, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as i, type ContextOptions as j, type TestEvent as k, type ContextEvents as l, type ContextInstance as m, Context as n, type DevToolsUiVersion as o, type DevToolsState as p, type DevToolsActions as q, type DevToolsEvent as r, type DevToolsLogEvent as s, type DevToolsDataEvent as t, type DevToolsHelloEvent as u, type DevToolsUpdateEvent as v, type DevToolsRawCommandsEvent as w, type DevToolsForgetEvent as x, type LogMessages as y, type Severity as z };
|