@uniformdev/context 20.7.1-alpha.14 → 20.7.1-alpha.16
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 +1 -1
- package/dist/api/api.d.ts +1 -1
- package/dist/index.d.mts +33 -4
- package/dist/index.d.ts +33 -4
- package/dist/index.esm.js +226 -41
- package/dist/index.js +231 -42
- package/dist/index.mjs +226 -41
- package/dist/{types-EJl31yuP.d.mts → types-CzIkFCDD.d.mts} +96 -24
- package/dist/{types-EJl31yuP.d.ts → types-CzIkFCDD.d.ts} +96 -24
- package/package.json +2 -2
package/dist/api/api.d.mts
CHANGED
package/dist/api/api.d.ts
CHANGED
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-
|
2
|
-
export {
|
1
|
+
import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, P as PersonalizedVariant, g as PersonalizeOptions, h as Context, i as PersonalizedResult, j as VariationMatchDimensionCriteria, k as PersonalizationSelectionAlgorithmOptions, l as DevToolsEvents } from './types-CzIkFCDD.mjs';
|
2
|
+
export { a7 as AggregateDimensionInput, ad as BehaviorTag, m as CONTEXTUAL_EDITING_TEST_NAME, n as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, u as ContextEvents, v as ContextInstance, q as ContextOptions, aF as ContextState, aG as ContextStateUpdate, Z as CriteriaEvaluatorParameters, Y as CriteriaEvaluatorResult, au as DecayOptions, y as DevToolsActions, E as DevToolsDataEvent, z as DevToolsEvent, I as DevToolsForgetEvent, F as DevToolsHelloEvent, B as DevToolsLogEvent, H as DevToolsRawCommandsEvent, x as DevToolsState, w as DevToolsUiVersion, G as DevToolsUpdateEvent, ab as DimensionMatch, a4 as EnrichmentCategory, aA as EnrichmentData, aD as EventData, aH as GoalStateUpdate, az as Goals, X as GroupCriteriaEvaluator, an as IdentifyCommand, U as LogMessageGroup, R as LogMessageSingle, J as LogMessages, W as ManifestInstance, $ as ManifestV2, M as MessageCategory, N as MessageFunc, ai as ModifyScoreCommand, aj as ModifySessionScoreCommand, a5 as NumberMatch, s as PersonalizationEvent, r as PersonalizationEventVariantId, a0 as PersonalizationManifest, o as PersonalizationSelectionAlgorithm, p as PersonalizationSelectionAlgorithms, aB as PersonalizeControlVariant, aC as PersonalizeVariants, ac as QuirkMatch, as as SERVER_STATE_ID, ar as ServerToClientTransitionState, ak as SetConsentCommand, ao as SetControlGroupCommand, ah as SetGoalCommand, ap as SetPersonalizeVariantControlCommand, al as SetQuirkCommand, am as SetTestCommand, K as Severity, a1 as Signal, a3 as SignalCriteria, a2 as SignalCriteriaGroup, _ as SignalData, ag as StorageCommand, a6 as TestDefinition, t as TestEvent, a8 as TestOptions, af as TestResult, ae as TestVariant, ay as Tests, at as TransitionDataStoreEvents, aa as VariationMatchMetadata, ax as VisitorDataStore, aw as VisitorDataStoreEvents, av as VisitorDataStoreOptions, aq as areCommandsEqual, aE as emptyVisitorData, a9 as testVariations } from './types-CzIkFCDD.mjs';
|
3
3
|
import Cookies from 'js-cookie';
|
4
4
|
import 'mitt';
|
5
5
|
|
@@ -158,7 +158,35 @@ declare function createDebugConsoleLogDrain(level: OutputSeverity, options?: Con
|
|
158
158
|
*/
|
159
159
|
declare function enableDebugConsoleLogDrain(level: OutputSeverity, options?: ConsoleDebugLogDrainOptions): ContextPlugin;
|
160
160
|
|
161
|
-
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void): boolean;
|
161
|
+
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void, quirks?: Quirks): boolean;
|
162
|
+
|
163
|
+
/**
|
164
|
+
* @deprecated Use `topDownCriteriaPersonalizationSelectionAlgorithm` instead
|
165
|
+
*/
|
166
|
+
declare function personalizeVariations<TVariant extends PersonalizedVariant<VariantMatchCriteria>>(options: PersonalizeOptions<TVariant> & {
|
167
|
+
context: Context;
|
168
|
+
}): PersonalizedResult<TVariant>;
|
169
|
+
|
170
|
+
declare const STRONGEST_SCORE_PERSONALIZATION_ALGORITHM = "ssc";
|
171
|
+
/**
|
172
|
+
* Implementation of the strongest score personalization selection algorithm.
|
173
|
+
*
|
174
|
+
* In this mode, we take all variations and break them into two groups:
|
175
|
+
* 1. Variations that have a positive score for their tagged dimension
|
176
|
+
* 2. Variations that do not have a dimension tag
|
177
|
+
*
|
178
|
+
* We then sort the first group by score, concatenate the second group, and return the top <take> variations.
|
179
|
+
*/
|
180
|
+
declare function strongestScorePersonalizationSelectionAlgorithm<TCriteria extends VariationMatchDimensionCriteria, TVariation extends PersonalizedVariant<TCriteria>>({ name, context, variations, take, onLogMessage, }: PersonalizationSelectionAlgorithmOptions<TCriteria, TVariation>): PersonalizedResult<TVariation>;
|
181
|
+
|
182
|
+
declare const TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM = "default";
|
183
|
+
/**
|
184
|
+
* Implementation of the top-down criteria personalization selection algorithm.
|
185
|
+
*
|
186
|
+
* In this mode, we evaluate variations in the order they are declared and the first <take>
|
187
|
+
* variations whose criteria evaluate to true are selected.
|
188
|
+
*/
|
189
|
+
declare function topDownCriteriaPersonalizationSelectionAlgorithm<TCriteria extends VariantMatchCriteria, TVariation extends PersonalizedVariant<TCriteria>>({ name, context, variations, take, onLogMessage, }: PersonalizationSelectionAlgorithmOptions<TCriteria, TVariation>): PersonalizedResult<TVariation>;
|
162
190
|
|
163
191
|
type ContextDevToolOptions = {
|
164
192
|
onAfterMessageReceived?: (message: DevToolsEvents) => void;
|
@@ -183,6 +211,7 @@ declare enum ScriptType {
|
|
183
211
|
type EdgePersonalizeComponentOptions = {
|
184
212
|
name: string;
|
185
213
|
count?: number;
|
214
|
+
algorithm?: string;
|
186
215
|
};
|
187
216
|
type EdgeTestComponentOptions = {
|
188
217
|
name: string;
|
@@ -213,4 +242,4 @@ type QuickConnectConfig = {
|
|
213
242
|
declare function serializeQuickConnect(config: QuickConnectConfig): string;
|
214
243
|
declare function parseQuickConnect(serialized: string): Required<QuickConnectConfig>;
|
215
244
|
|
216
|
-
export { AggregateDimension, type ConsoleDebugLogDrainOptions, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, type EnableUniformInsightsOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, QUIRK_SEP, type QuickConnectConfig, Quirks, ScoreVector, ScriptType, StorageCommands, StringMatch, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, enableUniformInsights, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks };
|
245
|
+
export { AggregateDimension, type ConsoleDebugLogDrainOptions, Context, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, type EnableUniformInsightsOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, PersonalizationSelectionAlgorithmOptions, PersonalizeOptions, PersonalizedResult, PersonalizedVariant, QUIRK_SEP, type QuickConnectConfig, Quirks, STRONGEST_SCORE_PERSONALIZATION_ALGORITHM, ScoreVector, ScriptType, StorageCommands, StringMatch, TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VariationMatchDimensionCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, enableUniformInsights, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, personalizeVariations, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks, strongestScorePersonalizationSelectionAlgorithm, topDownCriteriaPersonalizationSelectionAlgorithm };
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-
|
2
|
-
export {
|
1
|
+
import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, P as PersonalizedVariant, g as PersonalizeOptions, h as Context, i as PersonalizedResult, j as VariationMatchDimensionCriteria, k as PersonalizationSelectionAlgorithmOptions, l as DevToolsEvents } from './types-CzIkFCDD.js';
|
2
|
+
export { a7 as AggregateDimensionInput, ad as BehaviorTag, m as CONTEXTUAL_EDITING_TEST_NAME, n as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, u as ContextEvents, v as ContextInstance, q as ContextOptions, aF as ContextState, aG as ContextStateUpdate, Z as CriteriaEvaluatorParameters, Y as CriteriaEvaluatorResult, au as DecayOptions, y as DevToolsActions, E as DevToolsDataEvent, z as DevToolsEvent, I as DevToolsForgetEvent, F as DevToolsHelloEvent, B as DevToolsLogEvent, H as DevToolsRawCommandsEvent, x as DevToolsState, w as DevToolsUiVersion, G as DevToolsUpdateEvent, ab as DimensionMatch, a4 as EnrichmentCategory, aA as EnrichmentData, aD as EventData, aH as GoalStateUpdate, az as Goals, X as GroupCriteriaEvaluator, an as IdentifyCommand, U as LogMessageGroup, R as LogMessageSingle, J as LogMessages, W as ManifestInstance, $ as ManifestV2, M as MessageCategory, N as MessageFunc, ai as ModifyScoreCommand, aj as ModifySessionScoreCommand, a5 as NumberMatch, s as PersonalizationEvent, r as PersonalizationEventVariantId, a0 as PersonalizationManifest, o as PersonalizationSelectionAlgorithm, p as PersonalizationSelectionAlgorithms, aB as PersonalizeControlVariant, aC as PersonalizeVariants, ac as QuirkMatch, as as SERVER_STATE_ID, ar as ServerToClientTransitionState, ak as SetConsentCommand, ao as SetControlGroupCommand, ah as SetGoalCommand, ap as SetPersonalizeVariantControlCommand, al as SetQuirkCommand, am as SetTestCommand, K as Severity, a1 as Signal, a3 as SignalCriteria, a2 as SignalCriteriaGroup, _ as SignalData, ag as StorageCommand, a6 as TestDefinition, t as TestEvent, a8 as TestOptions, af as TestResult, ae as TestVariant, ay as Tests, at as TransitionDataStoreEvents, aa as VariationMatchMetadata, ax as VisitorDataStore, aw as VisitorDataStoreEvents, av as VisitorDataStoreOptions, aq as areCommandsEqual, aE as emptyVisitorData, a9 as testVariations } from './types-CzIkFCDD.js';
|
3
3
|
import Cookies from 'js-cookie';
|
4
4
|
import 'mitt';
|
5
5
|
|
@@ -158,7 +158,35 @@ declare function createDebugConsoleLogDrain(level: OutputSeverity, options?: Con
|
|
158
158
|
*/
|
159
159
|
declare function enableDebugConsoleLogDrain(level: OutputSeverity, options?: ConsoleDebugLogDrainOptions): ContextPlugin;
|
160
160
|
|
161
|
-
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void): boolean;
|
161
|
+
declare function evaluateVariantMatch(variantId: string, match: VariantMatchCriteria | undefined | null, vec: ScoreVector, onLogMessage?: (message: LogMessage) => void, quirks?: Quirks): boolean;
|
162
|
+
|
163
|
+
/**
|
164
|
+
* @deprecated Use `topDownCriteriaPersonalizationSelectionAlgorithm` instead
|
165
|
+
*/
|
166
|
+
declare function personalizeVariations<TVariant extends PersonalizedVariant<VariantMatchCriteria>>(options: PersonalizeOptions<TVariant> & {
|
167
|
+
context: Context;
|
168
|
+
}): PersonalizedResult<TVariant>;
|
169
|
+
|
170
|
+
declare const STRONGEST_SCORE_PERSONALIZATION_ALGORITHM = "ssc";
|
171
|
+
/**
|
172
|
+
* Implementation of the strongest score personalization selection algorithm.
|
173
|
+
*
|
174
|
+
* In this mode, we take all variations and break them into two groups:
|
175
|
+
* 1. Variations that have a positive score for their tagged dimension
|
176
|
+
* 2. Variations that do not have a dimension tag
|
177
|
+
*
|
178
|
+
* We then sort the first group by score, concatenate the second group, and return the top <take> variations.
|
179
|
+
*/
|
180
|
+
declare function strongestScorePersonalizationSelectionAlgorithm<TCriteria extends VariationMatchDimensionCriteria, TVariation extends PersonalizedVariant<TCriteria>>({ name, context, variations, take, onLogMessage, }: PersonalizationSelectionAlgorithmOptions<TCriteria, TVariation>): PersonalizedResult<TVariation>;
|
181
|
+
|
182
|
+
declare const TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM = "default";
|
183
|
+
/**
|
184
|
+
* Implementation of the top-down criteria personalization selection algorithm.
|
185
|
+
*
|
186
|
+
* In this mode, we evaluate variations in the order they are declared and the first <take>
|
187
|
+
* variations whose criteria evaluate to true are selected.
|
188
|
+
*/
|
189
|
+
declare function topDownCriteriaPersonalizationSelectionAlgorithm<TCriteria extends VariantMatchCriteria, TVariation extends PersonalizedVariant<TCriteria>>({ name, context, variations, take, onLogMessage, }: PersonalizationSelectionAlgorithmOptions<TCriteria, TVariation>): PersonalizedResult<TVariation>;
|
162
190
|
|
163
191
|
type ContextDevToolOptions = {
|
164
192
|
onAfterMessageReceived?: (message: DevToolsEvents) => void;
|
@@ -183,6 +211,7 @@ declare enum ScriptType {
|
|
183
211
|
type EdgePersonalizeComponentOptions = {
|
184
212
|
name: string;
|
185
213
|
count?: number;
|
214
|
+
algorithm?: string;
|
186
215
|
};
|
187
216
|
type EdgeTestComponentOptions = {
|
188
217
|
name: string;
|
@@ -213,4 +242,4 @@ type QuickConnectConfig = {
|
|
213
242
|
declare function serializeQuickConnect(config: QuickConnectConfig): string;
|
214
243
|
declare function parseQuickConnect(serialized: string): Required<QuickConnectConfig>;
|
215
244
|
|
216
|
-
export { AggregateDimension, type ConsoleDebugLogDrainOptions, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, type EnableUniformInsightsOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, QUIRK_SEP, type QuickConnectConfig, Quirks, ScoreVector, ScriptType, StorageCommands, StringMatch, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, enableUniformInsights, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks };
|
245
|
+
export { AggregateDimension, type ConsoleDebugLogDrainOptions, Context, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, type EnableUniformInsightsOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, PersonalizationSelectionAlgorithmOptions, PersonalizeOptions, PersonalizedResult, PersonalizedVariant, QUIRK_SEP, type QuickConnectConfig, Quirks, STRONGEST_SCORE_PERSONALIZATION_ALGORITHM, ScoreVector, ScriptType, StorageCommands, StringMatch, TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VariationMatchDimensionCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, enableUniformInsights, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, personalizeVariations, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks, strongestScorePersonalizationSelectionAlgorithm, topDownCriteriaPersonalizationSelectionAlgorithm };
|
package/dist/index.esm.js
CHANGED
@@ -516,7 +516,7 @@ var GroupCriteriaEvaluator = class {
|
|
516
516
|
_evaluators = new WeakMap();
|
517
517
|
|
518
518
|
// src/placement/criteria/evaluateVariantMatch.ts
|
519
|
-
function evaluateVariantMatch(variantId, match, vec, onLogMessage) {
|
519
|
+
function evaluateVariantMatch(variantId, match, vec, onLogMessage, quirks) {
|
520
520
|
onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variantId, op: match == null ? void 0 : match.op }]);
|
521
521
|
let result;
|
522
522
|
try {
|
@@ -524,9 +524,9 @@ function evaluateVariantMatch(variantId, match, vec, onLogMessage) {
|
|
524
524
|
onLogMessage == null ? void 0 : onLogMessage(["info", 302, { matched: true, description: "default variation" }]);
|
525
525
|
result = true;
|
526
526
|
} else if (!match.op || match.op === "&") {
|
527
|
-
result = match.crit.every((c) =>
|
527
|
+
result = match.crit.every((c) => evaluateMatch(c, vec, quirks != null ? quirks : {}, onLogMessage));
|
528
528
|
} else {
|
529
|
-
result = match.crit.some((c) =>
|
529
|
+
result = match.crit.some((c) => evaluateMatch(c, vec, quirks != null ? quirks : {}, onLogMessage));
|
530
530
|
}
|
531
531
|
onLogMessage == null ? void 0 : onLogMessage(["info", 303, result]);
|
532
532
|
} finally {
|
@@ -534,9 +534,16 @@ function evaluateVariantMatch(variantId, match, vec, onLogMessage) {
|
|
534
534
|
}
|
535
535
|
return result;
|
536
536
|
}
|
537
|
+
function evaluateMatch(crit, vec, quirks, onLogMessage) {
|
538
|
+
if ("t" in crit && crit.t === "q") {
|
539
|
+
return evaluateQuirkMatch(crit, quirks, onLogMessage);
|
540
|
+
} else {
|
541
|
+
return evaluateDimensionMatch(crit, vec, onLogMessage);
|
542
|
+
}
|
543
|
+
}
|
537
544
|
function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
538
545
|
var _a, _b;
|
539
|
-
const {
|
546
|
+
const { l: lhs, op } = crit;
|
540
547
|
const lhsScore = (_a = vec[lhs]) != null ? _a : 0;
|
541
548
|
if (op === "^") {
|
542
549
|
const [cat] = lhs.split(ENR_SEPARATOR);
|
@@ -603,33 +610,65 @@ function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
|
603
610
|
}
|
604
611
|
if (op === ">") {
|
605
612
|
const result = lhsScore > rhsScore;
|
606
|
-
|
613
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
607
614
|
return result;
|
608
615
|
} else if (op === ">=") {
|
609
616
|
const result = lhsScore >= rhsScore;
|
610
|
-
|
617
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
611
618
|
return result;
|
612
619
|
} else if (op === "<") {
|
613
620
|
const result = lhsScore < rhsScore;
|
614
|
-
|
621
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
615
622
|
return result;
|
616
623
|
} else if (op === "<=") {
|
617
624
|
const result = lhsScore <= rhsScore;
|
618
|
-
|
625
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
619
626
|
return result;
|
620
627
|
} else if (op === "=") {
|
621
628
|
const result = lhsScore === rhsScore;
|
622
|
-
|
629
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
623
630
|
return result;
|
624
631
|
} else if (op === "!=") {
|
625
632
|
const result = lhsScore !== rhsScore;
|
626
|
-
|
633
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
634
|
+
return result;
|
635
|
+
} else {
|
636
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
637
|
+
"error",
|
638
|
+
302,
|
639
|
+
{
|
640
|
+
matched: false,
|
641
|
+
description: `${crit.l} ${crit.op} ${crit.rDim ? `${crit.rDim}` : crit.r}: Unknown op ${crit.op}.`
|
642
|
+
}
|
643
|
+
]);
|
644
|
+
return false;
|
645
|
+
}
|
646
|
+
}
|
647
|
+
function evaluateQuirkMatch(crit, quirks, onLogMessage) {
|
648
|
+
var _a;
|
649
|
+
const { l: targetQuirk, op, r: targetValue } = crit;
|
650
|
+
const targetQuirkValue = (_a = quirks[targetQuirk]) != null ? _a : "";
|
651
|
+
if (op === "=") {
|
652
|
+
const result = targetQuirkValue === targetValue;
|
653
|
+
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
654
|
+
return result;
|
655
|
+
} else if (op === "!=") {
|
656
|
+
const result = targetQuirkValue !== targetValue;
|
657
|
+
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
627
658
|
return result;
|
628
659
|
} else {
|
629
|
-
|
660
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
661
|
+
"error",
|
662
|
+
302,
|
663
|
+
{
|
664
|
+
matched: false,
|
665
|
+
description: `Quirk ${crit.l} ${crit.op} ${crit.r}: Unknown quirk op ${crit.op}.`
|
666
|
+
}
|
667
|
+
]);
|
668
|
+
return false;
|
630
669
|
}
|
631
670
|
}
|
632
|
-
function
|
671
|
+
function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
633
672
|
onLogMessage == null ? void 0 : onLogMessage([
|
634
673
|
"info",
|
635
674
|
302,
|
@@ -639,9 +678,20 @@ function explain(onLogMessage, result, crit, lhsScore, rhsScore) {
|
|
639
678
|
}
|
640
679
|
]);
|
641
680
|
}
|
681
|
+
function explainQuirk(onLogMessage, result, crit, lhs) {
|
682
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
683
|
+
"info",
|
684
|
+
302,
|
685
|
+
{
|
686
|
+
matched: result,
|
687
|
+
description: `Quirk ${crit.l}[${lhs}] ${crit.op} ${crit.r}`
|
688
|
+
}
|
689
|
+
]);
|
690
|
+
}
|
642
691
|
|
643
|
-
// src/placement/
|
644
|
-
|
692
|
+
// src/placement/topDownCriteriaPersonalizationSelectionAlgorithm.ts
|
693
|
+
var TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM = "default";
|
694
|
+
function topDownCriteriaPersonalizationSelectionAlgorithm({
|
645
695
|
name,
|
646
696
|
context,
|
647
697
|
variations,
|
@@ -651,27 +701,35 @@ function personalizeVariations({
|
|
651
701
|
var _a, _b, _c;
|
652
702
|
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
653
703
|
try {
|
654
|
-
const
|
655
|
-
const
|
656
|
-
const
|
657
|
-
const
|
658
|
-
for (const
|
659
|
-
|
660
|
-
|
661
|
-
|
704
|
+
const variationMatches = [];
|
705
|
+
const defaultVariations = [];
|
706
|
+
const needsConsentToPersonalize = context.requireConsentForPersonalization;
|
707
|
+
const personalizationAllowed = !needsConsentToPersonalize || context.storage.data.consent;
|
708
|
+
for (const variation of variations) {
|
709
|
+
const isInvalidFormat = variation.pz && (typeof variation.pz !== "object" || variation.pz === null || !("crit" in variation.pz && Array.isArray(variation.pz.crit)));
|
710
|
+
let validVariation;
|
711
|
+
if (isInvalidFormat) {
|
712
|
+
const { pz, ...validParts } = variation;
|
713
|
+
validVariation = validParts;
|
714
|
+
} else {
|
715
|
+
validVariation = variation;
|
716
|
+
}
|
717
|
+
if ((_a = validVariation.pz) == null ? void 0 : _a.crit.length) {
|
718
|
+
if (personalizationAllowed && variationMatches.length !== take && evaluateVariantMatch(variation.id, validVariation.pz, context.scores, onLogMessage, context.quirks)) {
|
719
|
+
variationMatches.push(validVariation);
|
662
720
|
}
|
663
721
|
} else {
|
664
|
-
|
722
|
+
defaultVariations.push(validVariation);
|
665
723
|
}
|
666
724
|
}
|
667
725
|
const result = [];
|
668
|
-
for (let i = 0; i <
|
726
|
+
for (let i = 0; i < variationMatches.length; i++) {
|
669
727
|
let isControl = (_b = context.storage.data.controlGroup) != null ? _b : false;
|
670
|
-
const
|
671
|
-
if (!isControl && typeof ((_c =
|
728
|
+
const variation = variationMatches[i];
|
729
|
+
if (!isControl && typeof ((_c = variation.pz) == null ? void 0 : _c.control) === "number") {
|
672
730
|
isControl = context.getPersonalizeVariantControl(name, i);
|
673
731
|
if (typeof isControl === "undefined") {
|
674
|
-
isControl = rollForControlGroup(
|
732
|
+
isControl = rollForControlGroup(variation.pz.control);
|
675
733
|
context.storage.updateData([
|
676
734
|
{
|
677
735
|
type: "setpersonalizecontrol",
|
@@ -684,13 +742,13 @@ function personalizeVariations({
|
|
684
742
|
]);
|
685
743
|
}
|
686
744
|
}
|
687
|
-
let variantToAdd =
|
745
|
+
let variantToAdd = variation;
|
688
746
|
if (isControl) {
|
689
|
-
const defaultReplacement =
|
747
|
+
const defaultReplacement = defaultVariations.shift();
|
690
748
|
if (defaultReplacement) {
|
691
749
|
variantToAdd = {
|
692
750
|
...defaultReplacement,
|
693
|
-
id:
|
751
|
+
id: variation.id
|
694
752
|
};
|
695
753
|
} else {
|
696
754
|
variantToAdd = void 0;
|
@@ -700,8 +758,8 @@ function personalizeVariations({
|
|
700
758
|
result.push({ ...variantToAdd, control: isControl });
|
701
759
|
}
|
702
760
|
}
|
703
|
-
while (result.length < take &&
|
704
|
-
result.push({ ...
|
761
|
+
while (result.length < take && defaultVariations.length) {
|
762
|
+
result.push({ ...defaultVariations.shift(), control: false });
|
705
763
|
}
|
706
764
|
const personalized = result.some((v) => {
|
707
765
|
var _a2;
|
@@ -716,7 +774,94 @@ function personalizeVariations({
|
|
716
774
|
}
|
717
775
|
}
|
718
776
|
|
719
|
-
// src/placement/
|
777
|
+
// src/placement/personalizeVariations.ts
|
778
|
+
function personalizeVariations(options) {
|
779
|
+
return topDownCriteriaPersonalizationSelectionAlgorithm(options);
|
780
|
+
}
|
781
|
+
|
782
|
+
// src/placement/strongestScorePersonalizationSelectionAlgorithm.ts
|
783
|
+
var STRONGEST_SCORE_PERSONALIZATION_ALGORITHM = "ssc";
|
784
|
+
function strongestScorePersonalizationSelectionAlgorithm({
|
785
|
+
name,
|
786
|
+
context,
|
787
|
+
variations,
|
788
|
+
take = 1,
|
789
|
+
onLogMessage
|
790
|
+
}) {
|
791
|
+
var _a, _b;
|
792
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
793
|
+
try {
|
794
|
+
const variationMatches = [];
|
795
|
+
const defaultVariations = [];
|
796
|
+
const needsConsentToPersonalize = context.requireConsentForPersonalization;
|
797
|
+
const isInGlobalControlGroup = (_a = context.storage.data.controlGroup) != null ? _a : false;
|
798
|
+
const personalizationAllowed = !needsConsentToPersonalize || context.storage.data.consent;
|
799
|
+
let originalIndex = 0;
|
800
|
+
for (const variation of variations) {
|
801
|
+
const isInvalidFormat = variation.pz && typeof variation.pz !== "object";
|
802
|
+
let validVariation;
|
803
|
+
if (isInvalidFormat) {
|
804
|
+
const { pz, ...validParts } = variation;
|
805
|
+
validVariation = validParts;
|
806
|
+
} else {
|
807
|
+
validVariation = variation;
|
808
|
+
}
|
809
|
+
if ((_b = validVariation.pz) == null ? void 0 : _b.dim) {
|
810
|
+
if (!personalizationAllowed) {
|
811
|
+
continue;
|
812
|
+
}
|
813
|
+
const score = context.scores[validVariation.pz.dim];
|
814
|
+
if (score === void 0 || score <= 0) {
|
815
|
+
continue;
|
816
|
+
}
|
817
|
+
variationMatches.push({ variation: validVariation, score, originalIndex });
|
818
|
+
originalIndex++;
|
819
|
+
} else {
|
820
|
+
defaultVariations.push(validVariation);
|
821
|
+
}
|
822
|
+
}
|
823
|
+
variationMatches.sort((a, b) => {
|
824
|
+
const scoreComparison = b.score - a.score;
|
825
|
+
if (scoreComparison === 0) {
|
826
|
+
return a.originalIndex - b.originalIndex;
|
827
|
+
}
|
828
|
+
return scoreComparison;
|
829
|
+
});
|
830
|
+
const result = [];
|
831
|
+
for (let i = 0; i < variationMatches.length; i++) {
|
832
|
+
const variationMatch = variationMatches[i];
|
833
|
+
let variantToAdd = variationMatch.variation;
|
834
|
+
if (i >= take) {
|
835
|
+
continue;
|
836
|
+
}
|
837
|
+
if (isInGlobalControlGroup) {
|
838
|
+
const defaultReplacement = defaultVariations.shift();
|
839
|
+
if (defaultReplacement) {
|
840
|
+
variantToAdd = {
|
841
|
+
...defaultReplacement,
|
842
|
+
id: variationMatch.variation.id
|
843
|
+
};
|
844
|
+
} else {
|
845
|
+
variantToAdd = void 0;
|
846
|
+
}
|
847
|
+
}
|
848
|
+
if (variantToAdd) {
|
849
|
+
result.push({ ...variantToAdd, control: isInGlobalControlGroup });
|
850
|
+
}
|
851
|
+
}
|
852
|
+
while (result.length < take && defaultVariations.length) {
|
853
|
+
result.push({ ...defaultVariations.shift(), control: false });
|
854
|
+
}
|
855
|
+
return {
|
856
|
+
personalized: variationMatches.length > 0 && !isInGlobalControlGroup,
|
857
|
+
variations: result
|
858
|
+
};
|
859
|
+
} finally {
|
860
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "ENDGROUP"]);
|
861
|
+
}
|
862
|
+
}
|
863
|
+
|
864
|
+
// src/placement/normalizeVariationDistributions.ts
|
720
865
|
var normalizeVariationDistributions = (variations) => {
|
721
866
|
const { values, total, missingDistribution } = variations.reduce(
|
722
867
|
(previous, current) => {
|
@@ -735,7 +880,12 @@ var normalizeVariationDistributions = (variations) => {
|
|
735
880
|
}
|
736
881
|
);
|
737
882
|
if (total > 100) {
|
738
|
-
|
883
|
+
const autoScaleFactor = 100 / total;
|
884
|
+
values.forEach((value, index) => {
|
885
|
+
if (typeof value === "number") {
|
886
|
+
values[index] = value * autoScaleFactor;
|
887
|
+
}
|
888
|
+
});
|
739
889
|
} else if (total < 100) {
|
740
890
|
const remainder = 100 - total;
|
741
891
|
const missingSlice = remainder / missingDistribution;
|
@@ -747,6 +897,8 @@ var normalizeVariationDistributions = (variations) => {
|
|
747
897
|
}
|
748
898
|
return values;
|
749
899
|
};
|
900
|
+
|
901
|
+
// src/placement/testVariations.ts
|
750
902
|
var testVariations = ({
|
751
903
|
name,
|
752
904
|
context,
|
@@ -773,11 +925,11 @@ var testVariations = ({
|
|
773
925
|
}
|
774
926
|
if (!selectedVariant) {
|
775
927
|
const distributions = normalizeVariationDistributions(variations);
|
776
|
-
const random = Math.
|
928
|
+
const random = Math.random() * 100;
|
777
929
|
let distributionOffset = 0;
|
778
930
|
selectedVariant = variations.find((variant, index) => {
|
779
931
|
const distribution = distributions[index];
|
780
|
-
if (
|
932
|
+
if (random >= distributionOffset && random < distributionOffset + distribution) {
|
781
933
|
return variant;
|
782
934
|
}
|
783
935
|
distributionOffset += distribution;
|
@@ -1513,11 +1665,12 @@ import { dequal as dequal5 } from "dequal/lite";
|
|
1513
1665
|
import mitt3 from "mitt";
|
1514
1666
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1515
1667
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1516
|
-
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1668
|
+
var _personalizationSelectionAlgorithms, _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1517
1669
|
var Context = class {
|
1518
1670
|
constructor(options) {
|
1519
1671
|
__privateAdd(this, _Context_instances);
|
1520
1672
|
__publicField(this, "manifest");
|
1673
|
+
__privateAdd(this, _personalizationSelectionAlgorithms);
|
1521
1674
|
__privateAdd(this, _serverTransitionState);
|
1522
1675
|
__privateAdd(this, _scores, {});
|
1523
1676
|
__privateAdd(this, _state);
|
@@ -1534,7 +1687,7 @@ var Context = class {
|
|
1534
1687
|
off: __privateGet(this, _mitt3).off
|
1535
1688
|
});
|
1536
1689
|
__publicField(this, "storage");
|
1537
|
-
var _a, _b;
|
1690
|
+
var _a, _b, _c;
|
1538
1691
|
const { manifest, ...storageOptions } = options;
|
1539
1692
|
__privateSet(this, _state, {});
|
1540
1693
|
__privateSet(this, _plugins, options.plugins);
|
@@ -1542,7 +1695,20 @@ var Context = class {
|
|
1542
1695
|
if (typeof options.transitionStore !== "undefined") {
|
1543
1696
|
__privateSet(this, _commands, []);
|
1544
1697
|
}
|
1698
|
+
__privateSet(this, _personalizationSelectionAlgorithms, {
|
1699
|
+
[TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM]: topDownCriteriaPersonalizationSelectionAlgorithm,
|
1700
|
+
[STRONGEST_SCORE_PERSONALIZATION_ALGORITHM]: strongestScorePersonalizationSelectionAlgorithm
|
1701
|
+
});
|
1545
1702
|
(_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
|
1703
|
+
if (!plugin.personalizationSelectionAlgorithms) {
|
1704
|
+
return;
|
1705
|
+
}
|
1706
|
+
__privateSet(this, _personalizationSelectionAlgorithms, {
|
1707
|
+
...__privateGet(this, _personalizationSelectionAlgorithms),
|
1708
|
+
...plugin.personalizationSelectionAlgorithms
|
1709
|
+
});
|
1710
|
+
});
|
1711
|
+
(_b = __privateGet(this, _plugins)) == null ? void 0 : _b.forEach((plugin) => {
|
1546
1712
|
if (!plugin.logDrain) {
|
1547
1713
|
return;
|
1548
1714
|
}
|
@@ -1593,7 +1759,7 @@ var Context = class {
|
|
1593
1759
|
__privateGet(this, _mitt3).emit("quirksUpdated", quirks.quirks);
|
1594
1760
|
__privateGet(this, _mitt3).emit("log", ["info", 4, quirks.quirks]);
|
1595
1761
|
});
|
1596
|
-
(
|
1762
|
+
(_c = __privateGet(this, _plugins)) == null ? void 0 : _c.forEach((plugin) => {
|
1597
1763
|
if (!plugin.init) {
|
1598
1764
|
return;
|
1599
1765
|
}
|
@@ -1843,7 +2009,17 @@ var Context = class {
|
|
1843
2009
|
}
|
1844
2010
|
/** Executes a personalized placement with a given set of variants */
|
1845
2011
|
personalize(options) {
|
1846
|
-
|
2012
|
+
var _a;
|
2013
|
+
const algorithmName = (_a = options.algorithm) != null ? _a : TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM;
|
2014
|
+
const algorithm = __privateGet(this, _personalizationSelectionAlgorithms)[algorithmName];
|
2015
|
+
if (!algorithm) {
|
2016
|
+
__privateGet(this, _mitt3).emit("log", ["warn", 304, { algorithm: algorithmName }]);
|
2017
|
+
return {
|
2018
|
+
personalized: false,
|
2019
|
+
variations: []
|
2020
|
+
};
|
2021
|
+
}
|
2022
|
+
const value = algorithm({
|
1847
2023
|
...options,
|
1848
2024
|
context: this,
|
1849
2025
|
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
@@ -1917,6 +2093,7 @@ var Context = class {
|
|
1917
2093
|
__privateGet(this, _mitt3).emit("personalizationResult", event);
|
1918
2094
|
}
|
1919
2095
|
};
|
2096
|
+
_personalizationSelectionAlgorithms = new WeakMap();
|
1920
2097
|
_serverTransitionState = new WeakMap();
|
1921
2098
|
_scores = new WeakMap();
|
1922
2099
|
_state = new WeakMap();
|
@@ -2512,6 +2689,10 @@ var messageContent = {
|
|
2512
2689
|
301: ({ id, op }) => ["personalization", `testing variation ${id} (${op === "|" ? "OR" : "AND"})`],
|
2513
2690
|
302: ({ matched, description }) => ["personalization", `${description} is ${matched}`],
|
2514
2691
|
303: (selected) => ["personalization", selected ? "selected variation" : "did not select variation"],
|
2692
|
+
304: ({ algorithm }) => [
|
2693
|
+
"personalization",
|
2694
|
+
`personalization selection algorithm '${algorithm}' not found. Hiding placement.`
|
2695
|
+
],
|
2515
2696
|
// TESTING
|
2516
2697
|
400: (name) => ["testing", `executing A/B test '${name}'`],
|
2517
2698
|
401: (testName) => ["testing", `${testName} is not registered in the manifest; it will not be run.`],
|
@@ -2616,7 +2797,9 @@ export {
|
|
2616
2797
|
PAIR_SEP,
|
2617
2798
|
QUIRK_SEP,
|
2618
2799
|
SERVER_STATE_ID,
|
2800
|
+
STRONGEST_SCORE_PERSONALIZATION_ALGORITHM,
|
2619
2801
|
ScriptType,
|
2802
|
+
TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM,
|
2620
2803
|
TYPE_SEP,
|
2621
2804
|
TransitionDataStore,
|
2622
2805
|
UNIFORM_DEFAULT_COOKIE_NAME,
|
@@ -2658,5 +2841,7 @@ export {
|
|
2658
2841
|
serializePersonalizeVariants,
|
2659
2842
|
serializeQuickConnect,
|
2660
2843
|
serializeQuirks,
|
2661
|
-
|
2844
|
+
strongestScorePersonalizationSelectionAlgorithm,
|
2845
|
+
testVariations,
|
2846
|
+
topDownCriteriaPersonalizationSelectionAlgorithm
|
2662
2847
|
};
|