@uniformdev/context 20.35.0 → 20.35.1-alpha.188

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/index.mjs CHANGED
@@ -227,6 +227,10 @@ var ManifestInstance = class {
227
227
  }
228
228
  return (_d = (_c = __privateGet(this, _mf).pz) == null ? void 0 : _c.enr) == null ? void 0 : _d[scoreKey.substring(0, enrichmentIndex)];
229
229
  }
230
+ getAggregateDimensionByKey(scoreKey) {
231
+ var _a, _b;
232
+ return (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.agg) == null ? void 0 : _b[scoreKey];
233
+ }
230
234
  };
231
235
  _mf = new WeakMap();
232
236
  _signalInstances = new WeakMap();
@@ -941,6 +945,9 @@ var testVariations = ({
941
945
  }
942
946
  if (selectedVariant) {
943
947
  onLogMessage == null ? void 0 : onLogMessage(["info", 404, selectedVariant.id]);
948
+ if (selectedVariant.control === void 0) {
949
+ selectedVariant.control = variations.findIndex((variation) => variation.id === selectedVariantId) === 0;
950
+ }
944
951
  }
945
952
  return {
946
953
  result: selectedVariant,
@@ -1737,6 +1744,9 @@ var Context = class {
1737
1744
  __privateSet(this, _scores, state.ssv);
1738
1745
  __privateGet(this, _mitt3).emit("log", ["debug", 130, state]);
1739
1746
  }
1747
+ if (state.compositionMetadata) {
1748
+ __privateGet(this, _state).compositionMetadata = state.compositionMetadata;
1749
+ }
1740
1750
  },
1741
1751
  onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
1742
1752
  });
@@ -1889,10 +1899,16 @@ var Context = class {
1889
1899
  scores: __privateGet(this, _serverTransitionState) ? __privateMethod(this, _Context_instances, calculateScores_fn).call(this, this.storage.data) : __privateGet(this, _scores)
1890
1900
  })
1891
1901
  );
1902
+ const previousCompositionMetadata = __privateGet(this, _state).compositionMetadata;
1892
1903
  __privateSet(this, _state, {
1893
1904
  ...__privateGet(this, _state),
1894
1905
  ...newData
1895
1906
  });
1907
+ if (newData.compositionMetadata && // deep equal is not too bad, as we only have 1 level of depth in dynamic inputs
1908
+ !dequal5(previousCompositionMetadata, __privateGet(this, _state).compositionMetadata)) {
1909
+ __privateGet(this, _mitt3).emit("canvasDataUpdated", __privateGet(this, _state).compositionMetadata);
1910
+ __privateGet(this, _state).compositionMetadata = newData.compositionMetadata;
1911
+ }
1896
1912
  await this.storage.updateData(commands);
1897
1913
  if (__privateGet(this, _serverTransitionState)) {
1898
1914
  await this.processServerCommands({
@@ -1904,7 +1920,9 @@ var Context = class {
1904
1920
  __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
1905
1921
  name: testName,
1906
1922
  variantId: testVariantId,
1907
- variantAssigned: true
1923
+ variantAssigned: true,
1924
+ control: false,
1925
+ compositionMetadata: void 0
1908
1926
  });
1909
1927
  });
1910
1928
  const haveQuirksChanged = __privateGet(this, _serverTransitionState) && !dequal5(__privateGet(this, _serverTransitionState).quirks, this.storage.data.quirks);
@@ -1920,7 +1938,7 @@ var Context = class {
1920
1938
  if (!plugin.update) {
1921
1939
  continue;
1922
1940
  }
1923
- await plugin.update(newData);
1941
+ await plugin.update(newData, __privateGet(this, _scores));
1924
1942
  }
1925
1943
  }
1926
1944
  (_e = __privateGet(this, _commands)) == null ? void 0 : _e.push(...commands);
@@ -1986,7 +2004,7 @@ var Context = class {
1986
2004
  }
1987
2005
  /** 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) */
1988
2006
  test(options) {
1989
- var _a, _b, _c;
2007
+ var _a, _b, _c, _d, _e;
1990
2008
  if (options.name === CONTEXTUAL_EDITING_TEST_NAME) {
1991
2009
  const selectedVariant = (_a = options.variations.find((variant) => variant.id === CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID)) != null ? _a : options.variations.at(-1);
1992
2010
  const value2 = {
@@ -2003,7 +2021,9 @@ var Context = class {
2003
2021
  __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
2004
2022
  name: options.name,
2005
2023
  variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
2006
- variantAssigned: value.variantAssigned
2024
+ variantAssigned: value.variantAssigned,
2025
+ control: (_e = (_d = value.result) == null ? void 0 : _d.control) != null ? _e : false,
2026
+ compositionMetadata: options.compositionMetadata
2007
2027
  });
2008
2028
  return value;
2009
2029
  }
@@ -2032,7 +2052,8 @@ var Context = class {
2032
2052
  control: variation.control
2033
2053
  })),
2034
2054
  control: this.storage.data.controlGroup,
2035
- changed: true
2055
+ changed: true,
2056
+ compositionMetadata: options.compositionMetadata
2036
2057
  };
2037
2058
  if (previousPlacement && dequal5(eventData.variantIds, previousPlacement)) {
2038
2059
  eventData.changed = false;
@@ -2046,7 +2067,10 @@ var Context = class {
2046
2067
  * @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
2047
2068
  */
2048
2069
  async forget(fromAllDevices) {
2049
- __privateSet(this, _state, {});
2070
+ const previousCompositionMetadata = __privateGet(this, _state).compositionMetadata;
2071
+ __privateSet(this, _state, {
2072
+ compositionMetadata: previousCompositionMetadata
2073
+ });
2050
2074
  if (__privateGet(this, _plugins)) {
2051
2075
  for (let i = 0; i < __privateGet(this, _plugins).length; i++) {
2052
2076
  const plugin = __privateGet(this, _plugins)[i];
@@ -2069,7 +2093,8 @@ var Context = class {
2069
2093
  ssv: __privateGet(this, _scores),
2070
2094
  tests: {},
2071
2095
  personalizeVariants: this.storage.data.personalizeVariants,
2072
- commands: __privateGet(this, _commands)
2096
+ commands: __privateGet(this, _commands),
2097
+ compositionMetadata: __privateGet(this, _state).compositionMetadata
2073
2098
  };
2074
2099
  const allTests = this.storage.data.tests;
2075
2100
  Object.entries(allTests).map(([testName, testValue]) => {
@@ -2092,6 +2117,27 @@ var Context = class {
2092
2117
  __privateGet(this, _pzCache)[event.name] = event.variantIds;
2093
2118
  __privateGet(this, _mitt3).emit("personalizationResult", event);
2094
2119
  }
2120
+ /**
2121
+ * Gets the current canvas data
2122
+ */
2123
+ getCompositionMetadata() {
2124
+ return __privateGet(this, _state).compositionMetadata;
2125
+ }
2126
+ /**
2127
+ * Updates the canvas data and emits a canvasDataUpdated event
2128
+ */
2129
+ async updateCompositionMetadata(newData) {
2130
+ const currentCanvas = __privateGet(this, _state).compositionMetadata || {};
2131
+ const updatedCanvas = { ...currentCanvas, ...newData };
2132
+ if (!dequal5(currentCanvas, updatedCanvas)) {
2133
+ __privateSet(this, _state, {
2134
+ ...__privateGet(this, _state),
2135
+ compositionMetadata: updatedCanvas
2136
+ });
2137
+ __privateGet(this, _mitt3).emit("canvasDataUpdated", updatedCanvas);
2138
+ __privateGet(this, _mitt3).emit("log", ["info", 4, "Canvas data updated"]);
2139
+ }
2140
+ }
2095
2141
  };
2096
2142
  _personalizationSelectionAlgorithms = new WeakMap();
2097
2143
  _serverTransitionState = new WeakMap();
@@ -2256,7 +2302,31 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
2256
2302
  })(ScriptType || {});
2257
2303
  var EdgeNodeTagName = "nesitag";
2258
2304
 
2259
- // src/insights/index.ts
2305
+ // src/insights/storage.ts
2306
+ var createInsightsStorage = () => {
2307
+ const STORAGE_KEY2 = "ufin";
2308
+ return {
2309
+ get: () => {
2310
+ const data = localStorage.getItem(STORAGE_KEY2);
2311
+ if (!data) {
2312
+ return;
2313
+ }
2314
+ return JSON.parse(data);
2315
+ },
2316
+ set: (data) => {
2317
+ const toSet = {
2318
+ ...data,
2319
+ updated: Date.now()
2320
+ };
2321
+ localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
2322
+ },
2323
+ clear: () => {
2324
+ localStorage.removeItem(STORAGE_KEY2);
2325
+ }
2326
+ };
2327
+ };
2328
+
2329
+ // src/insights/types.ts
2260
2330
  var getBasePayload = () => {
2261
2331
  const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
2262
2332
  const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
@@ -2269,13 +2339,34 @@ var getBasePayload = () => {
2269
2339
  href: window.location.href
2270
2340
  };
2271
2341
  };
2342
+ var generateVisitorId = () => {
2343
+ return `visitor_${generalRandomId()}`;
2344
+ };
2345
+ var generateSessionId = () => {
2346
+ return `session_${generalRandomId()}`;
2347
+ };
2348
+ var generatePageId = () => {
2349
+ return `page_${generalRandomId()}`;
2350
+ };
2351
+ var generalRandomId = () => {
2352
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
2353
+ const id = crypto.randomUUID();
2354
+ return id.replaceAll("-", "").toLowerCase();
2355
+ }
2356
+ return Math.random().toString(32).substring(2);
2357
+ };
2358
+
2359
+ // src/insights/v1.ts
2272
2360
  var createInsightsClient = ({ endpoint }) => {
2273
2361
  let endpointUrl;
2274
2362
  const apiKey = endpoint.apiKey;
2275
2363
  const projectId = endpoint.projectId;
2276
2364
  if (endpoint.type === "api") {
2277
2365
  const url = new URL(endpoint.host);
2278
- url.pathname = "/v0/events";
2366
+ url.pathname = `/v0/events`;
2367
+ if (endpoint.host.includes("tinybird.co")) {
2368
+ url.pathname = "/v0/events";
2369
+ }
2279
2370
  url.searchParams.set("name", "analytics_events");
2280
2371
  endpointUrl = url.toString();
2281
2372
  } else {
@@ -2405,38 +2496,7 @@ var createInsightsClient = ({ endpoint }) => {
2405
2496
  }
2406
2497
  };
2407
2498
  };
2408
- var createInsightsStorage = () => {
2409
- const STORAGE_KEY2 = "ufin";
2410
- return {
2411
- get: () => {
2412
- const data = localStorage.getItem(STORAGE_KEY2);
2413
- if (!data) {
2414
- return;
2415
- }
2416
- return JSON.parse(data);
2417
- },
2418
- set: (data) => {
2419
- const toSet = {
2420
- ...data,
2421
- updated: Date.now()
2422
- };
2423
- localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
2424
- },
2425
- clear: () => {
2426
- localStorage.removeItem(STORAGE_KEY2);
2427
- }
2428
- };
2429
- };
2430
- var generateVisitorId = () => {
2431
- return `visitor_${generalRandomId()}`;
2432
- };
2433
- var generateSessionId = () => {
2434
- return `session_${generalRandomId()}`;
2435
- };
2436
- var generatePageId = () => {
2437
- return `page_${generalRandomId()}`;
2438
- };
2439
- var createInsights = ({
2499
+ var createInsightsV1 = ({
2440
2500
  endpoint,
2441
2501
  sessionDurationSeconds = 30 * 60
2442
2502
  }) => {
@@ -2537,8 +2597,10 @@ var createInsights = ({
2537
2597
  }
2538
2598
  };
2539
2599
  };
2600
+
2601
+ // src/insights/index.ts
2540
2602
  var enableUniformInsights = (options) => {
2541
- const insights = createInsights({
2603
+ const insights = createInsightsV1({
2542
2604
  endpoint: options.endpoint
2543
2605
  });
2544
2606
  let previousUrl = void 0;
@@ -2584,8 +2646,8 @@ var enableUniformInsights = (options) => {
2584
2646
  };
2585
2647
  },
2586
2648
  update: (context) => {
2587
- if (context.url && context.url !== previousUrl) {
2588
- previousUrl = context.url;
2649
+ if (context.url && context.url.toString() !== previousUrl) {
2650
+ previousUrl = context.url.toString();
2589
2651
  insights.pageHit();
2590
2652
  }
2591
2653
  },
@@ -2594,13 +2656,6 @@ var enableUniformInsights = (options) => {
2594
2656
  }
2595
2657
  };
2596
2658
  };
2597
- var generalRandomId = () => {
2598
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
2599
- const id = crypto.randomUUID();
2600
- return id.replaceAll("-", "").toLowerCase();
2601
- }
2602
- return Math.random().toString(32).substring(2);
2603
- };
2604
2659
 
2605
2660
  // src/logging/enableConsoleLogDrain.ts
2606
2661
  import rfdc2 from "rfdc";
@@ -76,6 +76,17 @@ type VisitorData = {
76
76
  personalizeVariants?: PersonalizeVariants;
77
77
  };
78
78
  declare const emptyVisitorData: () => VisitorData;
79
+ /**
80
+ * Canvas-specific data that should be managed separately from regular context updates
81
+ */
82
+ type CompositionMetadata = {
83
+ /** The composition ID always required, otherwise whole metadata should not be set */
84
+ compositionId: string;
85
+ /** The matched route from router endpoint. Same as matched project map node pathname */
86
+ matchedRoute?: string;
87
+ /** Dynamic inputs for the route */
88
+ dynamicInputs?: Record<string, string>;
89
+ };
79
90
  /**
80
91
  * Expresses a 'patch' to the Uniform Context state
81
92
  */
@@ -85,6 +96,11 @@ type ContextState = {
85
96
  quirks: Quirks;
86
97
  enrichments: EnrichmentData[];
87
98
  events: EventData[];
99
+ /**
100
+ * Metadata about the composition that is being rendered right now.
101
+ * if you have multiple compositions on the page, please set this one manually.
102
+ */
103
+ compositionMetadata?: CompositionMetadata;
88
104
  };
89
105
  type ContextStateUpdate = {
90
106
  /** The new effective state of the visitor after this state update is applied */
@@ -374,6 +390,7 @@ declare class ManifestInstance {
374
390
  */
375
391
  computeAggregateDimensions(primitiveScores: ScoreVector): ScoreVector;
376
392
  getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
393
+ getAggregateDimensionByKey(scoreKey: string): AggregateDimension | undefined;
377
394
  }
378
395
 
379
396
  interface paths {
@@ -1030,6 +1047,10 @@ type TestVariant = {
1030
1047
  * If not provided, this variant will be selected in equal proportion to other variants without an explicit distribution.
1031
1048
  */
1032
1049
  testDistribution?: number;
1050
+ /** Whether this variant is a control variant.
1051
+ * Can be undefined for backward compatibility with older versions of the SDK which were not explicitly setting the control flag.
1052
+ */
1053
+ control?: boolean;
1033
1054
  };
1034
1055
  /** The result of computing an A/B test result */
1035
1056
  type TestResult<TVariant> = {
@@ -1051,6 +1072,8 @@ interface PersonalizeOptions<TVariant> {
1051
1072
  take?: number;
1052
1073
  /** Name of the personalization selection algorithm to use. Defaults to top-down criteria when not specified. */
1053
1074
  algorithm?: string;
1075
+ /** Composition metadata where the personalization is being rendered for analytics tracking */
1076
+ compositionMetadata?: CompositionMetadata;
1054
1077
  }
1055
1078
  interface PersonalizationSelectionAlgorithmOptions<TCriteria, TVariant extends PersonalizedVariant<TCriteria> = PersonalizedVariant<TCriteria>> {
1056
1079
  /** Name of placement (sent to analytics) */
@@ -1070,6 +1093,8 @@ type TestOptions<TVariant extends TestVariant> = {
1070
1093
  name: string;
1071
1094
  /** Variations that are being tested. */
1072
1095
  variations: TVariant[];
1096
+ /** Composition metadata where the personalization is being rendered for analytics tracking */
1097
+ compositionMetadata?: CompositionMetadata;
1073
1098
  };
1074
1099
  declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, onLogMessage, }: TestOptions<TVariant> & {
1075
1100
  context: Context;
@@ -1092,8 +1117,8 @@ type ContextPlugin = {
1092
1117
  init?: (context: Context) => () => void;
1093
1118
  /** Plugin-specific actions to perform when a user is forgotten */
1094
1119
  forget?: () => Promise<void> | void;
1095
- /** Plugin-specific actions to perform when the visitor context is updated */
1096
- update?: (newData: Partial<ContextState>) => Promise<void> | void;
1120
+ /** Plugin-specific actions to perform when the visitor context is updated, second parameter is the recalculated scores after the update */
1121
+ update?: (newData: Partial<ContextState>, recalculatedScores: ScoreVector) => Promise<void> | void;
1097
1122
  /**
1098
1123
  * Allows the plugin to register named personalization selection algorithms
1099
1124
  *
@@ -1140,6 +1165,12 @@ type PersonalizationEvent = {
1140
1165
  * False: the variant(s) selected were the same as a previous evaluation of this placement.
1141
1166
  */
1142
1167
  changed: boolean;
1168
+ /**
1169
+ * Contains information about the composition that contains personalization wrapper component,
1170
+ * which triggered the personalization event.
1171
+ * Only references top level root composition after pattern resolutions.
1172
+ */
1173
+ compositionMetadata?: CompositionMetadata;
1143
1174
  };
1144
1175
  /** Emitted event when an A/B test runs */
1145
1176
  type TestEvent = {
@@ -1147,12 +1178,22 @@ type TestEvent = {
1147
1178
  name: string;
1148
1179
  /** ID of the variant that was selected */
1149
1180
  variantId: string | undefined;
1181
+ /**
1182
+ * Whether the variant is part of the control group.
1183
+ */
1184
+ control: boolean;
1150
1185
  /**
1151
1186
  * Whether the test variant was newly assigned to the visitor.
1152
1187
  * True: variant was assigned to the visitor for the first time.
1153
1188
  * False: variant was already assigned to the visitor and is being reused.
1154
1189
  */
1155
1190
  variantAssigned: boolean;
1191
+ /**
1192
+ * Contains information about the composition that contains A/B test wrapper component,
1193
+ * which triggered the A/B test event.
1194
+ * Only references top level root composition after pattern resolutions.
1195
+ */
1196
+ compositionMetadata?: CompositionMetadata;
1156
1197
  };
1157
1198
  type ContextEvents = {
1158
1199
  /**
@@ -1176,6 +1217,8 @@ type ContextEvents = {
1176
1217
  testResult: TestEvent;
1177
1218
  /** Personalization variants have been selected */
1178
1219
  personalizationResult: PersonalizationEvent;
1220
+ /** Composition metadata has been set/updated, usually happens when new composition is being rendered during client-side navigation for example */
1221
+ canvasDataUpdated: CompositionMetadata;
1179
1222
  };
1180
1223
  interface ContextInstance {
1181
1224
  get scores(): Readonly<ScoreVector>;
@@ -1197,6 +1240,14 @@ interface ContextInstance {
1197
1240
  internal_processTestEvent(event: TestEvent): void;
1198
1241
  /** @deprecated */
1199
1242
  internal_processPersonalizationEvent(event: PersonalizationEvent): void;
1243
+ /**
1244
+ * Gets the current canvas data
1245
+ */
1246
+ getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
1247
+ /**
1248
+ * Updates the canvas data and emits a canvasDataUpdated event
1249
+ */
1250
+ updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
1200
1251
  }
1201
1252
  declare class Context implements ContextInstance {
1202
1253
  #private;
@@ -1266,6 +1317,14 @@ declare class Context implements ContextInstance {
1266
1317
  internal_processTestEvent(event: TestEvent): void;
1267
1318
  /** @deprecated */
1268
1319
  internal_processPersonalizationEvent(event: PersonalizationEvent): void;
1320
+ /**
1321
+ * Gets the current canvas data
1322
+ */
1323
+ getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
1324
+ /**
1325
+ * Updates the canvas data and emits a canvasDataUpdated event
1326
+ */
1327
+ updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
1269
1328
  }
1270
1329
 
1271
1330
  /**
@@ -1337,4 +1396,4 @@ declare global {
1337
1396
  }
1338
1397
  }
1339
1398
 
1340
- export { type ManifestV2 as $, type AggregateDimension as A, type DevToolsLogEvent as B, type ContextPlugin as C, type DecayFunction as D, type DevToolsDataEvent as E, type DevToolsHelloEvent as F, type DevToolsUpdateEvent as G, type DevToolsRawCommandsEvent as H, type DevToolsForgetEvent as I, type LogMessages as J, type Severity as K, type LogDrain as L, type MessageCategory as M, type MessageFunc as N, type OutputSeverity as O, type PersonalizedVariant as P, type Quirks as Q, type LogMessageSingle as R, type ScoreVector as S, TransitionDataStore as T, type LogMessageGroup as U, type VisitorData as V, ManifestInstance as W, GroupCriteriaEvaluator as X, type CriteriaEvaluatorResult as Y, type CriteriaEvaluatorParameters as Z, type SignalData as _, type StorageCommands as a, type PersonalizationManifest as a0, type Signal as a1, type SignalCriteriaGroup as a2, type SignalCriteria as a3, type EnrichmentCategory as a4, type NumberMatch as a5, type TestDefinition as a6, type AggregateDimensionInput as a7, type TestOptions as a8, testVariations as a9, type EnrichmentData as aA, type PersonalizeControlVariant as aB, type PersonalizeVariants as aC, type EventData as aD, emptyVisitorData as aE, type ContextState as aF, type ContextStateUpdate as aG, type GoalStateUpdate as aH, type paths as aI, type VariationMatchMetadata as aa, type DimensionMatch as ab, type QuirkMatch as ac, type BehaviorTag as ad, type TestVariant as ae, type TestResult as af, type StorageCommand as ag, type SetGoalCommand as ah, type ModifyScoreCommand as ai, type ModifySessionScoreCommand as aj, type SetConsentCommand as ak, type SetQuirkCommand as al, type SetTestCommand as am, type IdentifyCommand as an, type SetControlGroupCommand as ao, type SetPersonalizeVariantControlCommand as ap, areCommandsEqual as aq, type ServerToClientTransitionState as ar, SERVER_STATE_ID as as, type TransitionDataStoreEvents as at, type DecayOptions as au, type VisitorDataStoreOptions as av, type VisitorDataStoreEvents as aw, VisitorDataStore as ax, type Tests as ay, type Goals as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type PersonalizeOptions as g, Context as h, type PersonalizedResult as i, type VariationMatchDimensionCriteria as j, type PersonalizationSelectionAlgorithmOptions as k, type DevToolsEvents as l, CONTEXTUAL_EDITING_TEST_NAME as m, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as n, type PersonalizationSelectionAlgorithm as o, type PersonalizationSelectionAlgorithms as p, type ContextOptions as q, type PersonalizationEventVariantId as r, type PersonalizationEvent as s, type TestEvent as t, type ContextEvents as u, type ContextInstance as v, type DevToolsUiVersion as w, type DevToolsState as x, type DevToolsActions as y, type DevToolsEvent as z };
1399
+ export { type ManifestV2 as $, type AggregateDimension as A, type DevToolsLogEvent as B, type ContextPlugin as C, type DecayFunction as D, type DevToolsDataEvent as E, type DevToolsHelloEvent as F, type DevToolsUpdateEvent as G, type DevToolsRawCommandsEvent as H, type DevToolsForgetEvent as I, type LogMessages as J, type Severity as K, type LogDrain as L, type MessageCategory as M, type MessageFunc as N, type OutputSeverity as O, type PersonalizedVariant as P, type Quirks as Q, type LogMessageSingle as R, type ScoreVector as S, TransitionDataStore as T, type LogMessageGroup as U, type VisitorData as V, ManifestInstance as W, GroupCriteriaEvaluator as X, type CriteriaEvaluatorResult as Y, type CriteriaEvaluatorParameters as Z, type SignalData as _, type StorageCommands as a, type PersonalizationManifest as a0, type Signal as a1, type SignalCriteriaGroup as a2, type SignalCriteria as a3, type EnrichmentCategory as a4, type NumberMatch as a5, type TestDefinition as a6, type AggregateDimensionInput as a7, type TestOptions as a8, testVariations as a9, type EnrichmentData as aA, type PersonalizeControlVariant as aB, type PersonalizeVariants as aC, type EventData as aD, emptyVisitorData as aE, type CompositionMetadata as aF, type ContextState as aG, type ContextStateUpdate as aH, type GoalStateUpdate as aI, type paths as aJ, type VariationMatchMetadata as aa, type DimensionMatch as ab, type QuirkMatch as ac, type BehaviorTag as ad, type TestVariant as ae, type TestResult as af, type StorageCommand as ag, type SetGoalCommand as ah, type ModifyScoreCommand as ai, type ModifySessionScoreCommand as aj, type SetConsentCommand as ak, type SetQuirkCommand as al, type SetTestCommand as am, type IdentifyCommand as an, type SetControlGroupCommand as ao, type SetPersonalizeVariantControlCommand as ap, areCommandsEqual as aq, type ServerToClientTransitionState as ar, SERVER_STATE_ID as as, type TransitionDataStoreEvents as at, type DecayOptions as au, type VisitorDataStoreOptions as av, type VisitorDataStoreEvents as aw, VisitorDataStore as ax, type Tests as ay, type Goals as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type PersonalizeOptions as g, Context as h, type PersonalizedResult as i, type VariationMatchDimensionCriteria as j, type PersonalizationSelectionAlgorithmOptions as k, type DevToolsEvents as l, CONTEXTUAL_EDITING_TEST_NAME as m, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as n, type PersonalizationSelectionAlgorithm as o, type PersonalizationSelectionAlgorithms as p, type ContextOptions as q, type PersonalizationEventVariantId as r, type PersonalizationEvent as s, type TestEvent as t, type ContextEvents as u, type ContextInstance as v, type DevToolsUiVersion as w, type DevToolsState as x, type DevToolsActions as y, type DevToolsEvent as z };
@@ -76,6 +76,17 @@ type VisitorData = {
76
76
  personalizeVariants?: PersonalizeVariants;
77
77
  };
78
78
  declare const emptyVisitorData: () => VisitorData;
79
+ /**
80
+ * Canvas-specific data that should be managed separately from regular context updates
81
+ */
82
+ type CompositionMetadata = {
83
+ /** The composition ID always required, otherwise whole metadata should not be set */
84
+ compositionId: string;
85
+ /** The matched route from router endpoint. Same as matched project map node pathname */
86
+ matchedRoute?: string;
87
+ /** Dynamic inputs for the route */
88
+ dynamicInputs?: Record<string, string>;
89
+ };
79
90
  /**
80
91
  * Expresses a 'patch' to the Uniform Context state
81
92
  */
@@ -85,6 +96,11 @@ type ContextState = {
85
96
  quirks: Quirks;
86
97
  enrichments: EnrichmentData[];
87
98
  events: EventData[];
99
+ /**
100
+ * Metadata about the composition that is being rendered right now.
101
+ * if you have multiple compositions on the page, please set this one manually.
102
+ */
103
+ compositionMetadata?: CompositionMetadata;
88
104
  };
89
105
  type ContextStateUpdate = {
90
106
  /** The new effective state of the visitor after this state update is applied */
@@ -374,6 +390,7 @@ declare class ManifestInstance {
374
390
  */
375
391
  computeAggregateDimensions(primitiveScores: ScoreVector): ScoreVector;
376
392
  getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
393
+ getAggregateDimensionByKey(scoreKey: string): AggregateDimension | undefined;
377
394
  }
378
395
 
379
396
  interface paths {
@@ -1030,6 +1047,10 @@ type TestVariant = {
1030
1047
  * If not provided, this variant will be selected in equal proportion to other variants without an explicit distribution.
1031
1048
  */
1032
1049
  testDistribution?: number;
1050
+ /** Whether this variant is a control variant.
1051
+ * Can be undefined for backward compatibility with older versions of the SDK which were not explicitly setting the control flag.
1052
+ */
1053
+ control?: boolean;
1033
1054
  };
1034
1055
  /** The result of computing an A/B test result */
1035
1056
  type TestResult<TVariant> = {
@@ -1051,6 +1072,8 @@ interface PersonalizeOptions<TVariant> {
1051
1072
  take?: number;
1052
1073
  /** Name of the personalization selection algorithm to use. Defaults to top-down criteria when not specified. */
1053
1074
  algorithm?: string;
1075
+ /** Composition metadata where the personalization is being rendered for analytics tracking */
1076
+ compositionMetadata?: CompositionMetadata;
1054
1077
  }
1055
1078
  interface PersonalizationSelectionAlgorithmOptions<TCriteria, TVariant extends PersonalizedVariant<TCriteria> = PersonalizedVariant<TCriteria>> {
1056
1079
  /** Name of placement (sent to analytics) */
@@ -1070,6 +1093,8 @@ type TestOptions<TVariant extends TestVariant> = {
1070
1093
  name: string;
1071
1094
  /** Variations that are being tested. */
1072
1095
  variations: TVariant[];
1096
+ /** Composition metadata where the personalization is being rendered for analytics tracking */
1097
+ compositionMetadata?: CompositionMetadata;
1073
1098
  };
1074
1099
  declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, onLogMessage, }: TestOptions<TVariant> & {
1075
1100
  context: Context;
@@ -1092,8 +1117,8 @@ type ContextPlugin = {
1092
1117
  init?: (context: Context) => () => void;
1093
1118
  /** Plugin-specific actions to perform when a user is forgotten */
1094
1119
  forget?: () => Promise<void> | void;
1095
- /** Plugin-specific actions to perform when the visitor context is updated */
1096
- update?: (newData: Partial<ContextState>) => Promise<void> | void;
1120
+ /** Plugin-specific actions to perform when the visitor context is updated, second parameter is the recalculated scores after the update */
1121
+ update?: (newData: Partial<ContextState>, recalculatedScores: ScoreVector) => Promise<void> | void;
1097
1122
  /**
1098
1123
  * Allows the plugin to register named personalization selection algorithms
1099
1124
  *
@@ -1140,6 +1165,12 @@ type PersonalizationEvent = {
1140
1165
  * False: the variant(s) selected were the same as a previous evaluation of this placement.
1141
1166
  */
1142
1167
  changed: boolean;
1168
+ /**
1169
+ * Contains information about the composition that contains personalization wrapper component,
1170
+ * which triggered the personalization event.
1171
+ * Only references top level root composition after pattern resolutions.
1172
+ */
1173
+ compositionMetadata?: CompositionMetadata;
1143
1174
  };
1144
1175
  /** Emitted event when an A/B test runs */
1145
1176
  type TestEvent = {
@@ -1147,12 +1178,22 @@ type TestEvent = {
1147
1178
  name: string;
1148
1179
  /** ID of the variant that was selected */
1149
1180
  variantId: string | undefined;
1181
+ /**
1182
+ * Whether the variant is part of the control group.
1183
+ */
1184
+ control: boolean;
1150
1185
  /**
1151
1186
  * Whether the test variant was newly assigned to the visitor.
1152
1187
  * True: variant was assigned to the visitor for the first time.
1153
1188
  * False: variant was already assigned to the visitor and is being reused.
1154
1189
  */
1155
1190
  variantAssigned: boolean;
1191
+ /**
1192
+ * Contains information about the composition that contains A/B test wrapper component,
1193
+ * which triggered the A/B test event.
1194
+ * Only references top level root composition after pattern resolutions.
1195
+ */
1196
+ compositionMetadata?: CompositionMetadata;
1156
1197
  };
1157
1198
  type ContextEvents = {
1158
1199
  /**
@@ -1176,6 +1217,8 @@ type ContextEvents = {
1176
1217
  testResult: TestEvent;
1177
1218
  /** Personalization variants have been selected */
1178
1219
  personalizationResult: PersonalizationEvent;
1220
+ /** Composition metadata has been set/updated, usually happens when new composition is being rendered during client-side navigation for example */
1221
+ canvasDataUpdated: CompositionMetadata;
1179
1222
  };
1180
1223
  interface ContextInstance {
1181
1224
  get scores(): Readonly<ScoreVector>;
@@ -1197,6 +1240,14 @@ interface ContextInstance {
1197
1240
  internal_processTestEvent(event: TestEvent): void;
1198
1241
  /** @deprecated */
1199
1242
  internal_processPersonalizationEvent(event: PersonalizationEvent): void;
1243
+ /**
1244
+ * Gets the current canvas data
1245
+ */
1246
+ getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
1247
+ /**
1248
+ * Updates the canvas data and emits a canvasDataUpdated event
1249
+ */
1250
+ updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
1200
1251
  }
1201
1252
  declare class Context implements ContextInstance {
1202
1253
  #private;
@@ -1266,6 +1317,14 @@ declare class Context implements ContextInstance {
1266
1317
  internal_processTestEvent(event: TestEvent): void;
1267
1318
  /** @deprecated */
1268
1319
  internal_processPersonalizationEvent(event: PersonalizationEvent): void;
1320
+ /**
1321
+ * Gets the current canvas data
1322
+ */
1323
+ getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
1324
+ /**
1325
+ * Updates the canvas data and emits a canvasDataUpdated event
1326
+ */
1327
+ updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
1269
1328
  }
1270
1329
 
1271
1330
  /**
@@ -1337,4 +1396,4 @@ declare global {
1337
1396
  }
1338
1397
  }
1339
1398
 
1340
- export { type ManifestV2 as $, type AggregateDimension as A, type DevToolsLogEvent as B, type ContextPlugin as C, type DecayFunction as D, type DevToolsDataEvent as E, type DevToolsHelloEvent as F, type DevToolsUpdateEvent as G, type DevToolsRawCommandsEvent as H, type DevToolsForgetEvent as I, type LogMessages as J, type Severity as K, type LogDrain as L, type MessageCategory as M, type MessageFunc as N, type OutputSeverity as O, type PersonalizedVariant as P, type Quirks as Q, type LogMessageSingle as R, type ScoreVector as S, TransitionDataStore as T, type LogMessageGroup as U, type VisitorData as V, ManifestInstance as W, GroupCriteriaEvaluator as X, type CriteriaEvaluatorResult as Y, type CriteriaEvaluatorParameters as Z, type SignalData as _, type StorageCommands as a, type PersonalizationManifest as a0, type Signal as a1, type SignalCriteriaGroup as a2, type SignalCriteria as a3, type EnrichmentCategory as a4, type NumberMatch as a5, type TestDefinition as a6, type AggregateDimensionInput as a7, type TestOptions as a8, testVariations as a9, type EnrichmentData as aA, type PersonalizeControlVariant as aB, type PersonalizeVariants as aC, type EventData as aD, emptyVisitorData as aE, type ContextState as aF, type ContextStateUpdate as aG, type GoalStateUpdate as aH, type paths as aI, type VariationMatchMetadata as aa, type DimensionMatch as ab, type QuirkMatch as ac, type BehaviorTag as ad, type TestVariant as ae, type TestResult as af, type StorageCommand as ag, type SetGoalCommand as ah, type ModifyScoreCommand as ai, type ModifySessionScoreCommand as aj, type SetConsentCommand as ak, type SetQuirkCommand as al, type SetTestCommand as am, type IdentifyCommand as an, type SetControlGroupCommand as ao, type SetPersonalizeVariantControlCommand as ap, areCommandsEqual as aq, type ServerToClientTransitionState as ar, SERVER_STATE_ID as as, type TransitionDataStoreEvents as at, type DecayOptions as au, type VisitorDataStoreOptions as av, type VisitorDataStoreEvents as aw, VisitorDataStore as ax, type Tests as ay, type Goals as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type PersonalizeOptions as g, Context as h, type PersonalizedResult as i, type VariationMatchDimensionCriteria as j, type PersonalizationSelectionAlgorithmOptions as k, type DevToolsEvents as l, CONTEXTUAL_EDITING_TEST_NAME as m, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as n, type PersonalizationSelectionAlgorithm as o, type PersonalizationSelectionAlgorithms as p, type ContextOptions as q, type PersonalizationEventVariantId as r, type PersonalizationEvent as s, type TestEvent as t, type ContextEvents as u, type ContextInstance as v, type DevToolsUiVersion as w, type DevToolsState as x, type DevToolsActions as y, type DevToolsEvent as z };
1399
+ export { type ManifestV2 as $, type AggregateDimension as A, type DevToolsLogEvent as B, type ContextPlugin as C, type DecayFunction as D, type DevToolsDataEvent as E, type DevToolsHelloEvent as F, type DevToolsUpdateEvent as G, type DevToolsRawCommandsEvent as H, type DevToolsForgetEvent as I, type LogMessages as J, type Severity as K, type LogDrain as L, type MessageCategory as M, type MessageFunc as N, type OutputSeverity as O, type PersonalizedVariant as P, type Quirks as Q, type LogMessageSingle as R, type ScoreVector as S, TransitionDataStore as T, type LogMessageGroup as U, type VisitorData as V, ManifestInstance as W, GroupCriteriaEvaluator as X, type CriteriaEvaluatorResult as Y, type CriteriaEvaluatorParameters as Z, type SignalData as _, type StorageCommands as a, type PersonalizationManifest as a0, type Signal as a1, type SignalCriteriaGroup as a2, type SignalCriteria as a3, type EnrichmentCategory as a4, type NumberMatch as a5, type TestDefinition as a6, type AggregateDimensionInput as a7, type TestOptions as a8, testVariations as a9, type EnrichmentData as aA, type PersonalizeControlVariant as aB, type PersonalizeVariants as aC, type EventData as aD, emptyVisitorData as aE, type CompositionMetadata as aF, type ContextState as aG, type ContextStateUpdate as aH, type GoalStateUpdate as aI, type paths as aJ, type VariationMatchMetadata as aa, type DimensionMatch as ab, type QuirkMatch as ac, type BehaviorTag as ad, type TestVariant as ae, type TestResult as af, type StorageCommand as ag, type SetGoalCommand as ah, type ModifyScoreCommand as ai, type ModifySessionScoreCommand as aj, type SetConsentCommand as ak, type SetQuirkCommand as al, type SetTestCommand as am, type IdentifyCommand as an, type SetControlGroupCommand as ao, type SetPersonalizeVariantControlCommand as ap, areCommandsEqual as aq, type ServerToClientTransitionState as ar, SERVER_STATE_ID as as, type TransitionDataStoreEvents as at, type DecayOptions as au, type VisitorDataStoreOptions as av, type VisitorDataStoreEvents as aw, VisitorDataStore as ax, type Tests as ay, type Goals as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type PersonalizeOptions as g, Context as h, type PersonalizedResult as i, type VariationMatchDimensionCriteria as j, type PersonalizationSelectionAlgorithmOptions as k, type DevToolsEvents as l, CONTEXTUAL_EDITING_TEST_NAME as m, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as n, type PersonalizationSelectionAlgorithm as o, type PersonalizationSelectionAlgorithms as p, type ContextOptions as q, type PersonalizationEventVariantId as r, type PersonalizationEvent as s, type TestEvent as t, type ContextEvents as u, type ContextInstance as v, type DevToolsUiVersion as w, type DevToolsState as x, type DevToolsActions as y, type DevToolsEvent as z };