@uniformdev/context 20.36.1 → 20.36.2-alpha.90

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.
@@ -1,4 +1,4 @@
1
- import { aI as paths$7, $ as ManifestV2 } from '../types-CzIkFCDD.mjs';
1
+ import { aJ as paths$7, $ as ManifestV2 } from '../types-Bf1Hv1AG.mjs';
2
2
  import 'mitt';
3
3
 
4
4
  type LimitPolicy = <ReturnValue>(func: () => Promise<ReturnValue>) => Promise<ReturnValue>;
package/dist/api/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { aI as paths$7, $ as ManifestV2 } from '../types-CzIkFCDD.js';
1
+ import { aJ as paths$7, $ as ManifestV2 } from '../types-Bf1Hv1AG.js';
2
2
  import 'mitt';
3
3
 
4
4
  type LimitPolicy = <ReturnValue>(func: () => Promise<ReturnValue>) => Promise<ReturnValue>;
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, 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';
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-Bf1Hv1AG.mjs';
2
+ export { a7 as AggregateDimensionInput, ad as BehaviorTag, m as CONTEXTUAL_EDITING_TEST_NAME, n as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, aF as CompositionMetadata, u as ContextEvents, v as ContextInstance, q as ContextOptions, aG as ContextState, aH 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, aI 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-Bf1Hv1AG.mjs';
3
3
  import Cookies from 'js-cookie';
4
4
  import 'mitt';
5
5
 
@@ -229,9 +229,13 @@ type InsightsEndpoint = {
229
229
  apiKey?: string;
230
230
  projectId?: string;
231
231
  };
232
+
232
233
  type EnableUniformInsightsOptions = {
233
234
  endpoint: InsightsEndpoint;
234
235
  };
236
+ /**
237
+ * @deprecated Use `import { enableUniformInsights } from '@uniformdev/insights'` instead
238
+ */
235
239
  declare const enableUniformInsights: (options: EnableUniformInsightsOptions) => ContextPlugin;
236
240
 
237
241
  type QuickConnectConfig = {
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, 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';
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-Bf1Hv1AG.js';
2
+ export { a7 as AggregateDimensionInput, ad as BehaviorTag, m as CONTEXTUAL_EDITING_TEST_NAME, n as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, aF as CompositionMetadata, u as ContextEvents, v as ContextInstance, q as ContextOptions, aG as ContextState, aH 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, aI 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-Bf1Hv1AG.js';
3
3
  import Cookies from 'js-cookie';
4
4
  import 'mitt';
5
5
 
@@ -229,9 +229,13 @@ type InsightsEndpoint = {
229
229
  apiKey?: string;
230
230
  projectId?: string;
231
231
  };
232
+
232
233
  type EnableUniformInsightsOptions = {
233
234
  endpoint: InsightsEndpoint;
234
235
  };
236
+ /**
237
+ * @deprecated Use `import { enableUniformInsights } from '@uniformdev/insights'` instead
238
+ */
235
239
  declare const enableUniformInsights: (options: EnableUniformInsightsOptions) => ContextPlugin;
236
240
 
237
241
  type QuickConnectConfig = {
package/dist/index.esm.js CHANGED
@@ -941,6 +941,9 @@ var testVariations = ({
941
941
  }
942
942
  if (selectedVariant) {
943
943
  onLogMessage == null ? void 0 : onLogMessage(["info", 404, selectedVariant.id]);
944
+ if (selectedVariant.control === void 0) {
945
+ selectedVariant.control = variations.findIndex((variation) => variation.id === selectedVariantId) === 0;
946
+ }
944
947
  }
945
948
  return {
946
949
  result: selectedVariant,
@@ -1904,7 +1907,9 @@ var Context = class {
1904
1907
  __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
1905
1908
  name: testName,
1906
1909
  variantId: testVariantId,
1907
- variantAssigned: true
1910
+ variantAssigned: true,
1911
+ control: false,
1912
+ compositionMetadata: void 0
1908
1913
  });
1909
1914
  });
1910
1915
  const haveQuirksChanged = __privateGet(this, _serverTransitionState) && !dequal5(__privateGet(this, _serverTransitionState).quirks, this.storage.data.quirks);
@@ -1986,7 +1991,7 @@ var Context = class {
1986
1991
  }
1987
1992
  /** 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
1993
  test(options) {
1989
- var _a, _b, _c;
1994
+ var _a, _b, _c, _d, _e;
1990
1995
  if (options.name === CONTEXTUAL_EDITING_TEST_NAME) {
1991
1996
  const selectedVariant = (_a = options.variations.find((variant) => variant.id === CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID)) != null ? _a : options.variations.at(-1);
1992
1997
  const value2 = {
@@ -2003,7 +2008,9 @@ var Context = class {
2003
2008
  __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
2004
2009
  name: options.name,
2005
2010
  variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
2006
- variantAssigned: value.variantAssigned
2011
+ variantAssigned: value.variantAssigned,
2012
+ control: (_e = (_d = value.result) == null ? void 0 : _d.control) != null ? _e : false,
2013
+ compositionMetadata: options.compositionMetadata
2007
2014
  });
2008
2015
  return value;
2009
2016
  }
@@ -2032,7 +2039,8 @@ var Context = class {
2032
2039
  control: variation.control
2033
2040
  })),
2034
2041
  control: this.storage.data.controlGroup,
2035
- changed: true
2042
+ changed: true,
2043
+ compositionMetadata: options.compositionMetadata
2036
2044
  };
2037
2045
  if (previousPlacement && dequal5(eventData.variantIds, previousPlacement)) {
2038
2046
  eventData.changed = false;
@@ -2092,6 +2100,27 @@ var Context = class {
2092
2100
  __privateGet(this, _pzCache)[event.name] = event.variantIds;
2093
2101
  __privateGet(this, _mitt3).emit("personalizationResult", event);
2094
2102
  }
2103
+ /**
2104
+ * Gets the current canvas data
2105
+ */
2106
+ getCompositionMetadata() {
2107
+ return __privateGet(this, _state).compositionMetadata;
2108
+ }
2109
+ /**
2110
+ * Updates the canvas data and emits a canvasDataUpdated event
2111
+ */
2112
+ async updateCompositionMetadata(newData) {
2113
+ const currentCanvas = __privateGet(this, _state).compositionMetadata || {};
2114
+ const updatedCanvas = { ...currentCanvas, ...newData };
2115
+ if (!dequal5(currentCanvas, updatedCanvas)) {
2116
+ __privateSet(this, _state, {
2117
+ ...__privateGet(this, _state),
2118
+ compositionMetadata: updatedCanvas
2119
+ });
2120
+ __privateGet(this, _mitt3).emit("canvasDataUpdated", updatedCanvas);
2121
+ __privateGet(this, _mitt3).emit("log", ["info", 4, "Canvas data updated"]);
2122
+ }
2123
+ }
2095
2124
  };
2096
2125
  _personalizationSelectionAlgorithms = new WeakMap();
2097
2126
  _serverTransitionState = new WeakMap();
@@ -2256,7 +2285,31 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
2256
2285
  })(ScriptType || {});
2257
2286
  var EdgeNodeTagName = "nesitag";
2258
2287
 
2259
- // src/insights/index.ts
2288
+ // src/insights/storage.ts
2289
+ var createInsightsStorage = () => {
2290
+ const STORAGE_KEY2 = "ufin";
2291
+ return {
2292
+ get: () => {
2293
+ const data = localStorage.getItem(STORAGE_KEY2);
2294
+ if (!data) {
2295
+ return;
2296
+ }
2297
+ return JSON.parse(data);
2298
+ },
2299
+ set: (data) => {
2300
+ const toSet = {
2301
+ ...data,
2302
+ updated: Date.now()
2303
+ };
2304
+ localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
2305
+ },
2306
+ clear: () => {
2307
+ localStorage.removeItem(STORAGE_KEY2);
2308
+ }
2309
+ };
2310
+ };
2311
+
2312
+ // src/insights/types.ts
2260
2313
  var getBasePayload = () => {
2261
2314
  const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
2262
2315
  const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
@@ -2269,13 +2322,34 @@ var getBasePayload = () => {
2269
2322
  href: window.location.href
2270
2323
  };
2271
2324
  };
2325
+ var generateVisitorId = async () => {
2326
+ return `visitor_${generalRandomId()}`;
2327
+ };
2328
+ var generateSessionId = async () => {
2329
+ return `session_${generalRandomId()}`;
2330
+ };
2331
+ var generatePageId = () => {
2332
+ return `page_${generalRandomId()}`;
2333
+ };
2334
+ var generalRandomId = () => {
2335
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
2336
+ const id = crypto.randomUUID();
2337
+ return id.replaceAll("-", "").toLowerCase();
2338
+ }
2339
+ return Math.random().toString(32).substring(2);
2340
+ };
2341
+
2342
+ // src/insights/v1.ts
2272
2343
  var createInsightsClient = ({ endpoint }) => {
2273
2344
  let endpointUrl;
2274
2345
  const apiKey = endpoint.apiKey;
2275
2346
  const projectId = endpoint.projectId;
2276
2347
  if (endpoint.type === "api") {
2277
2348
  const url = new URL(endpoint.host);
2278
- url.pathname = "/v0/events";
2349
+ url.pathname = `/v0/events`;
2350
+ if (endpoint.host.includes("tinybird.co")) {
2351
+ url.pathname = "/v0/events";
2352
+ }
2279
2353
  url.searchParams.set("name", "analytics_events");
2280
2354
  endpointUrl = url.toString();
2281
2355
  } else {
@@ -2405,38 +2479,7 @@ var createInsightsClient = ({ endpoint }) => {
2405
2479
  }
2406
2480
  };
2407
2481
  };
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 = ({
2482
+ var createInsightsV1 = ({
2440
2483
  endpoint,
2441
2484
  sessionDurationSeconds = 30 * 60
2442
2485
  }) => {
@@ -2537,8 +2580,10 @@ var createInsights = ({
2537
2580
  }
2538
2581
  };
2539
2582
  };
2583
+
2584
+ // src/insights/index.ts
2540
2585
  var enableUniformInsights = (options) => {
2541
- const insights = createInsights({
2586
+ const insights = createInsightsV1({
2542
2587
  endpoint: options.endpoint
2543
2588
  });
2544
2589
  let previousUrl = void 0;
@@ -2584,8 +2629,8 @@ var enableUniformInsights = (options) => {
2584
2629
  };
2585
2630
  },
2586
2631
  update: (context) => {
2587
- if (context.url && context.url !== previousUrl) {
2588
- previousUrl = context.url;
2632
+ if (context.url && context.url.toString() !== previousUrl) {
2633
+ previousUrl = context.url.toString();
2589
2634
  insights.pageHit();
2590
2635
  }
2591
2636
  },
@@ -2594,13 +2639,6 @@ var enableUniformInsights = (options) => {
2594
2639
  }
2595
2640
  };
2596
2641
  };
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
2642
 
2605
2643
  // src/logging/enableConsoleLogDrain.ts
2606
2644
  import rfdc2 from "rfdc";
package/dist/index.js CHANGED
@@ -1034,6 +1034,9 @@ var testVariations = ({
1034
1034
  }
1035
1035
  if (selectedVariant) {
1036
1036
  onLogMessage == null ? void 0 : onLogMessage(["info", 404, selectedVariant.id]);
1037
+ if (selectedVariant.control === void 0) {
1038
+ selectedVariant.control = variations.findIndex((variation) => variation.id === selectedVariantId) === 0;
1039
+ }
1037
1040
  }
1038
1041
  return {
1039
1042
  result: selectedVariant,
@@ -1997,7 +2000,9 @@ var Context = class {
1997
2000
  __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
1998
2001
  name: testName,
1999
2002
  variantId: testVariantId,
2000
- variantAssigned: true
2003
+ variantAssigned: true,
2004
+ control: false,
2005
+ compositionMetadata: void 0
2001
2006
  });
2002
2007
  });
2003
2008
  const haveQuirksChanged = __privateGet(this, _serverTransitionState) && !(0, import_lite5.dequal)(__privateGet(this, _serverTransitionState).quirks, this.storage.data.quirks);
@@ -2079,7 +2084,7 @@ var Context = class {
2079
2084
  }
2080
2085
  /** 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) */
2081
2086
  test(options) {
2082
- var _a, _b, _c;
2087
+ var _a, _b, _c, _d, _e;
2083
2088
  if (options.name === CONTEXTUAL_EDITING_TEST_NAME) {
2084
2089
  const selectedVariant = (_a = options.variations.find((variant) => variant.id === CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID)) != null ? _a : options.variations.at(-1);
2085
2090
  const value2 = {
@@ -2096,7 +2101,9 @@ var Context = class {
2096
2101
  __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
2097
2102
  name: options.name,
2098
2103
  variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
2099
- variantAssigned: value.variantAssigned
2104
+ variantAssigned: value.variantAssigned,
2105
+ control: (_e = (_d = value.result) == null ? void 0 : _d.control) != null ? _e : false,
2106
+ compositionMetadata: options.compositionMetadata
2100
2107
  });
2101
2108
  return value;
2102
2109
  }
@@ -2125,7 +2132,8 @@ var Context = class {
2125
2132
  control: variation.control
2126
2133
  })),
2127
2134
  control: this.storage.data.controlGroup,
2128
- changed: true
2135
+ changed: true,
2136
+ compositionMetadata: options.compositionMetadata
2129
2137
  };
2130
2138
  if (previousPlacement && (0, import_lite5.dequal)(eventData.variantIds, previousPlacement)) {
2131
2139
  eventData.changed = false;
@@ -2185,6 +2193,27 @@ var Context = class {
2185
2193
  __privateGet(this, _pzCache)[event.name] = event.variantIds;
2186
2194
  __privateGet(this, _mitt3).emit("personalizationResult", event);
2187
2195
  }
2196
+ /**
2197
+ * Gets the current canvas data
2198
+ */
2199
+ getCompositionMetadata() {
2200
+ return __privateGet(this, _state).compositionMetadata;
2201
+ }
2202
+ /**
2203
+ * Updates the canvas data and emits a canvasDataUpdated event
2204
+ */
2205
+ async updateCompositionMetadata(newData) {
2206
+ const currentCanvas = __privateGet(this, _state).compositionMetadata || {};
2207
+ const updatedCanvas = { ...currentCanvas, ...newData };
2208
+ if (!(0, import_lite5.dequal)(currentCanvas, updatedCanvas)) {
2209
+ __privateSet(this, _state, {
2210
+ ...__privateGet(this, _state),
2211
+ compositionMetadata: updatedCanvas
2212
+ });
2213
+ __privateGet(this, _mitt3).emit("canvasDataUpdated", updatedCanvas);
2214
+ __privateGet(this, _mitt3).emit("log", ["info", 4, "Canvas data updated"]);
2215
+ }
2216
+ }
2188
2217
  };
2189
2218
  _personalizationSelectionAlgorithms = new WeakMap();
2190
2219
  _serverTransitionState = new WeakMap();
@@ -2349,7 +2378,31 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
2349
2378
  })(ScriptType || {});
2350
2379
  var EdgeNodeTagName = "nesitag";
2351
2380
 
2352
- // src/insights/index.ts
2381
+ // src/insights/storage.ts
2382
+ var createInsightsStorage = () => {
2383
+ const STORAGE_KEY2 = "ufin";
2384
+ return {
2385
+ get: () => {
2386
+ const data = localStorage.getItem(STORAGE_KEY2);
2387
+ if (!data) {
2388
+ return;
2389
+ }
2390
+ return JSON.parse(data);
2391
+ },
2392
+ set: (data) => {
2393
+ const toSet = {
2394
+ ...data,
2395
+ updated: Date.now()
2396
+ };
2397
+ localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
2398
+ },
2399
+ clear: () => {
2400
+ localStorage.removeItem(STORAGE_KEY2);
2401
+ }
2402
+ };
2403
+ };
2404
+
2405
+ // src/insights/types.ts
2353
2406
  var getBasePayload = () => {
2354
2407
  const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
2355
2408
  const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
@@ -2362,13 +2415,34 @@ var getBasePayload = () => {
2362
2415
  href: window.location.href
2363
2416
  };
2364
2417
  };
2418
+ var generateVisitorId = async () => {
2419
+ return `visitor_${generalRandomId()}`;
2420
+ };
2421
+ var generateSessionId = async () => {
2422
+ return `session_${generalRandomId()}`;
2423
+ };
2424
+ var generatePageId = () => {
2425
+ return `page_${generalRandomId()}`;
2426
+ };
2427
+ var generalRandomId = () => {
2428
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
2429
+ const id = crypto.randomUUID();
2430
+ return id.replaceAll("-", "").toLowerCase();
2431
+ }
2432
+ return Math.random().toString(32).substring(2);
2433
+ };
2434
+
2435
+ // src/insights/v1.ts
2365
2436
  var createInsightsClient = ({ endpoint }) => {
2366
2437
  let endpointUrl;
2367
2438
  const apiKey = endpoint.apiKey;
2368
2439
  const projectId = endpoint.projectId;
2369
2440
  if (endpoint.type === "api") {
2370
2441
  const url = new URL(endpoint.host);
2371
- url.pathname = "/v0/events";
2442
+ url.pathname = `/v0/events`;
2443
+ if (endpoint.host.includes("tinybird.co")) {
2444
+ url.pathname = "/v0/events";
2445
+ }
2372
2446
  url.searchParams.set("name", "analytics_events");
2373
2447
  endpointUrl = url.toString();
2374
2448
  } else {
@@ -2498,38 +2572,7 @@ var createInsightsClient = ({ endpoint }) => {
2498
2572
  }
2499
2573
  };
2500
2574
  };
2501
- var createInsightsStorage = () => {
2502
- const STORAGE_KEY2 = "ufin";
2503
- return {
2504
- get: () => {
2505
- const data = localStorage.getItem(STORAGE_KEY2);
2506
- if (!data) {
2507
- return;
2508
- }
2509
- return JSON.parse(data);
2510
- },
2511
- set: (data) => {
2512
- const toSet = {
2513
- ...data,
2514
- updated: Date.now()
2515
- };
2516
- localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
2517
- },
2518
- clear: () => {
2519
- localStorage.removeItem(STORAGE_KEY2);
2520
- }
2521
- };
2522
- };
2523
- var generateVisitorId = () => {
2524
- return `visitor_${generalRandomId()}`;
2525
- };
2526
- var generateSessionId = () => {
2527
- return `session_${generalRandomId()}`;
2528
- };
2529
- var generatePageId = () => {
2530
- return `page_${generalRandomId()}`;
2531
- };
2532
- var createInsights = ({
2575
+ var createInsightsV1 = ({
2533
2576
  endpoint,
2534
2577
  sessionDurationSeconds = 30 * 60
2535
2578
  }) => {
@@ -2630,8 +2673,10 @@ var createInsights = ({
2630
2673
  }
2631
2674
  };
2632
2675
  };
2676
+
2677
+ // src/insights/index.ts
2633
2678
  var enableUniformInsights = (options) => {
2634
- const insights = createInsights({
2679
+ const insights = createInsightsV1({
2635
2680
  endpoint: options.endpoint
2636
2681
  });
2637
2682
  let previousUrl = void 0;
@@ -2677,8 +2722,8 @@ var enableUniformInsights = (options) => {
2677
2722
  };
2678
2723
  },
2679
2724
  update: (context) => {
2680
- if (context.url && context.url !== previousUrl) {
2681
- previousUrl = context.url;
2725
+ if (context.url && context.url.toString() !== previousUrl) {
2726
+ previousUrl = context.url.toString();
2682
2727
  insights.pageHit();
2683
2728
  }
2684
2729
  },
@@ -2687,13 +2732,6 @@ var enableUniformInsights = (options) => {
2687
2732
  }
2688
2733
  };
2689
2734
  };
2690
- var generalRandomId = () => {
2691
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
2692
- const id = crypto.randomUUID();
2693
- return id.replaceAll("-", "").toLowerCase();
2694
- }
2695
- return Math.random().toString(32).substring(2);
2696
- };
2697
2735
 
2698
2736
  // src/logging/enableConsoleLogDrain.ts
2699
2737
  var import_rfdc2 = __toESM(require("rfdc"));
package/dist/index.mjs CHANGED
@@ -941,6 +941,9 @@ var testVariations = ({
941
941
  }
942
942
  if (selectedVariant) {
943
943
  onLogMessage == null ? void 0 : onLogMessage(["info", 404, selectedVariant.id]);
944
+ if (selectedVariant.control === void 0) {
945
+ selectedVariant.control = variations.findIndex((variation) => variation.id === selectedVariantId) === 0;
946
+ }
944
947
  }
945
948
  return {
946
949
  result: selectedVariant,
@@ -1904,7 +1907,9 @@ var Context = class {
1904
1907
  __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
1905
1908
  name: testName,
1906
1909
  variantId: testVariantId,
1907
- variantAssigned: true
1910
+ variantAssigned: true,
1911
+ control: false,
1912
+ compositionMetadata: void 0
1908
1913
  });
1909
1914
  });
1910
1915
  const haveQuirksChanged = __privateGet(this, _serverTransitionState) && !dequal5(__privateGet(this, _serverTransitionState).quirks, this.storage.data.quirks);
@@ -1986,7 +1991,7 @@ var Context = class {
1986
1991
  }
1987
1992
  /** 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
1993
  test(options) {
1989
- var _a, _b, _c;
1994
+ var _a, _b, _c, _d, _e;
1990
1995
  if (options.name === CONTEXTUAL_EDITING_TEST_NAME) {
1991
1996
  const selectedVariant = (_a = options.variations.find((variant) => variant.id === CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID)) != null ? _a : options.variations.at(-1);
1992
1997
  const value2 = {
@@ -2003,7 +2008,9 @@ var Context = class {
2003
2008
  __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
2004
2009
  name: options.name,
2005
2010
  variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
2006
- variantAssigned: value.variantAssigned
2011
+ variantAssigned: value.variantAssigned,
2012
+ control: (_e = (_d = value.result) == null ? void 0 : _d.control) != null ? _e : false,
2013
+ compositionMetadata: options.compositionMetadata
2007
2014
  });
2008
2015
  return value;
2009
2016
  }
@@ -2032,7 +2039,8 @@ var Context = class {
2032
2039
  control: variation.control
2033
2040
  })),
2034
2041
  control: this.storage.data.controlGroup,
2035
- changed: true
2042
+ changed: true,
2043
+ compositionMetadata: options.compositionMetadata
2036
2044
  };
2037
2045
  if (previousPlacement && dequal5(eventData.variantIds, previousPlacement)) {
2038
2046
  eventData.changed = false;
@@ -2092,6 +2100,27 @@ var Context = class {
2092
2100
  __privateGet(this, _pzCache)[event.name] = event.variantIds;
2093
2101
  __privateGet(this, _mitt3).emit("personalizationResult", event);
2094
2102
  }
2103
+ /**
2104
+ * Gets the current canvas data
2105
+ */
2106
+ getCompositionMetadata() {
2107
+ return __privateGet(this, _state).compositionMetadata;
2108
+ }
2109
+ /**
2110
+ * Updates the canvas data and emits a canvasDataUpdated event
2111
+ */
2112
+ async updateCompositionMetadata(newData) {
2113
+ const currentCanvas = __privateGet(this, _state).compositionMetadata || {};
2114
+ const updatedCanvas = { ...currentCanvas, ...newData };
2115
+ if (!dequal5(currentCanvas, updatedCanvas)) {
2116
+ __privateSet(this, _state, {
2117
+ ...__privateGet(this, _state),
2118
+ compositionMetadata: updatedCanvas
2119
+ });
2120
+ __privateGet(this, _mitt3).emit("canvasDataUpdated", updatedCanvas);
2121
+ __privateGet(this, _mitt3).emit("log", ["info", 4, "Canvas data updated"]);
2122
+ }
2123
+ }
2095
2124
  };
2096
2125
  _personalizationSelectionAlgorithms = new WeakMap();
2097
2126
  _serverTransitionState = new WeakMap();
@@ -2256,7 +2285,31 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
2256
2285
  })(ScriptType || {});
2257
2286
  var EdgeNodeTagName = "nesitag";
2258
2287
 
2259
- // src/insights/index.ts
2288
+ // src/insights/storage.ts
2289
+ var createInsightsStorage = () => {
2290
+ const STORAGE_KEY2 = "ufin";
2291
+ return {
2292
+ get: () => {
2293
+ const data = localStorage.getItem(STORAGE_KEY2);
2294
+ if (!data) {
2295
+ return;
2296
+ }
2297
+ return JSON.parse(data);
2298
+ },
2299
+ set: (data) => {
2300
+ const toSet = {
2301
+ ...data,
2302
+ updated: Date.now()
2303
+ };
2304
+ localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
2305
+ },
2306
+ clear: () => {
2307
+ localStorage.removeItem(STORAGE_KEY2);
2308
+ }
2309
+ };
2310
+ };
2311
+
2312
+ // src/insights/types.ts
2260
2313
  var getBasePayload = () => {
2261
2314
  const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
2262
2315
  const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
@@ -2269,13 +2322,34 @@ var getBasePayload = () => {
2269
2322
  href: window.location.href
2270
2323
  };
2271
2324
  };
2325
+ var generateVisitorId = async () => {
2326
+ return `visitor_${generalRandomId()}`;
2327
+ };
2328
+ var generateSessionId = async () => {
2329
+ return `session_${generalRandomId()}`;
2330
+ };
2331
+ var generatePageId = () => {
2332
+ return `page_${generalRandomId()}`;
2333
+ };
2334
+ var generalRandomId = () => {
2335
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
2336
+ const id = crypto.randomUUID();
2337
+ return id.replaceAll("-", "").toLowerCase();
2338
+ }
2339
+ return Math.random().toString(32).substring(2);
2340
+ };
2341
+
2342
+ // src/insights/v1.ts
2272
2343
  var createInsightsClient = ({ endpoint }) => {
2273
2344
  let endpointUrl;
2274
2345
  const apiKey = endpoint.apiKey;
2275
2346
  const projectId = endpoint.projectId;
2276
2347
  if (endpoint.type === "api") {
2277
2348
  const url = new URL(endpoint.host);
2278
- url.pathname = "/v0/events";
2349
+ url.pathname = `/v0/events`;
2350
+ if (endpoint.host.includes("tinybird.co")) {
2351
+ url.pathname = "/v0/events";
2352
+ }
2279
2353
  url.searchParams.set("name", "analytics_events");
2280
2354
  endpointUrl = url.toString();
2281
2355
  } else {
@@ -2405,38 +2479,7 @@ var createInsightsClient = ({ endpoint }) => {
2405
2479
  }
2406
2480
  };
2407
2481
  };
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 = ({
2482
+ var createInsightsV1 = ({
2440
2483
  endpoint,
2441
2484
  sessionDurationSeconds = 30 * 60
2442
2485
  }) => {
@@ -2537,8 +2580,10 @@ var createInsights = ({
2537
2580
  }
2538
2581
  };
2539
2582
  };
2583
+
2584
+ // src/insights/index.ts
2540
2585
  var enableUniformInsights = (options) => {
2541
- const insights = createInsights({
2586
+ const insights = createInsightsV1({
2542
2587
  endpoint: options.endpoint
2543
2588
  });
2544
2589
  let previousUrl = void 0;
@@ -2584,8 +2629,8 @@ var enableUniformInsights = (options) => {
2584
2629
  };
2585
2630
  },
2586
2631
  update: (context) => {
2587
- if (context.url && context.url !== previousUrl) {
2588
- previousUrl = context.url;
2632
+ if (context.url && context.url.toString() !== previousUrl) {
2633
+ previousUrl = context.url.toString();
2589
2634
  insights.pageHit();
2590
2635
  }
2591
2636
  },
@@ -2594,13 +2639,6 @@ var enableUniformInsights = (options) => {
2594
2639
  }
2595
2640
  };
2596
2641
  };
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
2642
 
2605
2643
  // src/logging/enableConsoleLogDrain.ts
2606
2644
  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 */
@@ -1030,6 +1046,10 @@ type TestVariant = {
1030
1046
  * If not provided, this variant will be selected in equal proportion to other variants without an explicit distribution.
1031
1047
  */
1032
1048
  testDistribution?: number;
1049
+ /** Whether this variant is a control variant.
1050
+ * Can be undefined for backward compatibility with older versions of the SDK which were not explicitly setting the control flag.
1051
+ */
1052
+ control?: boolean;
1033
1053
  };
1034
1054
  /** The result of computing an A/B test result */
1035
1055
  type TestResult<TVariant> = {
@@ -1051,6 +1071,8 @@ interface PersonalizeOptions<TVariant> {
1051
1071
  take?: number;
1052
1072
  /** Name of the personalization selection algorithm to use. Defaults to top-down criteria when not specified. */
1053
1073
  algorithm?: string;
1074
+ /** Composition metadata where the personalization is being rendered for analytics tracking */
1075
+ compositionMetadata?: CompositionMetadata;
1054
1076
  }
1055
1077
  interface PersonalizationSelectionAlgorithmOptions<TCriteria, TVariant extends PersonalizedVariant<TCriteria> = PersonalizedVariant<TCriteria>> {
1056
1078
  /** Name of placement (sent to analytics) */
@@ -1070,6 +1092,8 @@ type TestOptions<TVariant extends TestVariant> = {
1070
1092
  name: string;
1071
1093
  /** Variations that are being tested. */
1072
1094
  variations: TVariant[];
1095
+ /** Composition metadata where the personalization is being rendered for analytics tracking */
1096
+ compositionMetadata?: CompositionMetadata;
1073
1097
  };
1074
1098
  declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, onLogMessage, }: TestOptions<TVariant> & {
1075
1099
  context: Context;
@@ -1140,6 +1164,12 @@ type PersonalizationEvent = {
1140
1164
  * False: the variant(s) selected were the same as a previous evaluation of this placement.
1141
1165
  */
1142
1166
  changed: boolean;
1167
+ /**
1168
+ * Contains information about the composition that contains personalization wrapper component,
1169
+ * which triggered the personalization event.
1170
+ * Only references top level root composition after pattern resolutions.
1171
+ */
1172
+ compositionMetadata?: CompositionMetadata;
1143
1173
  };
1144
1174
  /** Emitted event when an A/B test runs */
1145
1175
  type TestEvent = {
@@ -1147,12 +1177,22 @@ type TestEvent = {
1147
1177
  name: string;
1148
1178
  /** ID of the variant that was selected */
1149
1179
  variantId: string | undefined;
1180
+ /**
1181
+ * Whether the variant is part of the control group.
1182
+ */
1183
+ control: boolean;
1150
1184
  /**
1151
1185
  * Whether the test variant was newly assigned to the visitor.
1152
1186
  * True: variant was assigned to the visitor for the first time.
1153
1187
  * False: variant was already assigned to the visitor and is being reused.
1154
1188
  */
1155
1189
  variantAssigned: boolean;
1190
+ /**
1191
+ * Contains information about the composition that contains A/B test wrapper component,
1192
+ * which triggered the A/B test event.
1193
+ * Only references top level root composition after pattern resolutions.
1194
+ */
1195
+ compositionMetadata?: CompositionMetadata;
1156
1196
  };
1157
1197
  type ContextEvents = {
1158
1198
  /**
@@ -1176,6 +1216,8 @@ type ContextEvents = {
1176
1216
  testResult: TestEvent;
1177
1217
  /** Personalization variants have been selected */
1178
1218
  personalizationResult: PersonalizationEvent;
1219
+ /** Composition metadata has been set/updated, usually happens when new composition is being rendered during client-side navigation for example */
1220
+ canvasDataUpdated: CompositionMetadata;
1179
1221
  };
1180
1222
  interface ContextInstance {
1181
1223
  get scores(): Readonly<ScoreVector>;
@@ -1197,6 +1239,14 @@ interface ContextInstance {
1197
1239
  internal_processTestEvent(event: TestEvent): void;
1198
1240
  /** @deprecated */
1199
1241
  internal_processPersonalizationEvent(event: PersonalizationEvent): void;
1242
+ /**
1243
+ * Gets the current canvas data
1244
+ */
1245
+ getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
1246
+ /**
1247
+ * Updates the canvas data and emits a canvasDataUpdated event
1248
+ */
1249
+ updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
1200
1250
  }
1201
1251
  declare class Context implements ContextInstance {
1202
1252
  #private;
@@ -1266,6 +1316,14 @@ declare class Context implements ContextInstance {
1266
1316
  internal_processTestEvent(event: TestEvent): void;
1267
1317
  /** @deprecated */
1268
1318
  internal_processPersonalizationEvent(event: PersonalizationEvent): void;
1319
+ /**
1320
+ * Gets the current canvas data
1321
+ */
1322
+ getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
1323
+ /**
1324
+ * Updates the canvas data and emits a canvasDataUpdated event
1325
+ */
1326
+ updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
1269
1327
  }
1270
1328
 
1271
1329
  /**
@@ -1337,4 +1395,4 @@ declare global {
1337
1395
  }
1338
1396
  }
1339
1397
 
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 };
1398
+ 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 */
@@ -1030,6 +1046,10 @@ type TestVariant = {
1030
1046
  * If not provided, this variant will be selected in equal proportion to other variants without an explicit distribution.
1031
1047
  */
1032
1048
  testDistribution?: number;
1049
+ /** Whether this variant is a control variant.
1050
+ * Can be undefined for backward compatibility with older versions of the SDK which were not explicitly setting the control flag.
1051
+ */
1052
+ control?: boolean;
1033
1053
  };
1034
1054
  /** The result of computing an A/B test result */
1035
1055
  type TestResult<TVariant> = {
@@ -1051,6 +1071,8 @@ interface PersonalizeOptions<TVariant> {
1051
1071
  take?: number;
1052
1072
  /** Name of the personalization selection algorithm to use. Defaults to top-down criteria when not specified. */
1053
1073
  algorithm?: string;
1074
+ /** Composition metadata where the personalization is being rendered for analytics tracking */
1075
+ compositionMetadata?: CompositionMetadata;
1054
1076
  }
1055
1077
  interface PersonalizationSelectionAlgorithmOptions<TCriteria, TVariant extends PersonalizedVariant<TCriteria> = PersonalizedVariant<TCriteria>> {
1056
1078
  /** Name of placement (sent to analytics) */
@@ -1070,6 +1092,8 @@ type TestOptions<TVariant extends TestVariant> = {
1070
1092
  name: string;
1071
1093
  /** Variations that are being tested. */
1072
1094
  variations: TVariant[];
1095
+ /** Composition metadata where the personalization is being rendered for analytics tracking */
1096
+ compositionMetadata?: CompositionMetadata;
1073
1097
  };
1074
1098
  declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, onLogMessage, }: TestOptions<TVariant> & {
1075
1099
  context: Context;
@@ -1140,6 +1164,12 @@ type PersonalizationEvent = {
1140
1164
  * False: the variant(s) selected were the same as a previous evaluation of this placement.
1141
1165
  */
1142
1166
  changed: boolean;
1167
+ /**
1168
+ * Contains information about the composition that contains personalization wrapper component,
1169
+ * which triggered the personalization event.
1170
+ * Only references top level root composition after pattern resolutions.
1171
+ */
1172
+ compositionMetadata?: CompositionMetadata;
1143
1173
  };
1144
1174
  /** Emitted event when an A/B test runs */
1145
1175
  type TestEvent = {
@@ -1147,12 +1177,22 @@ type TestEvent = {
1147
1177
  name: string;
1148
1178
  /** ID of the variant that was selected */
1149
1179
  variantId: string | undefined;
1180
+ /**
1181
+ * Whether the variant is part of the control group.
1182
+ */
1183
+ control: boolean;
1150
1184
  /**
1151
1185
  * Whether the test variant was newly assigned to the visitor.
1152
1186
  * True: variant was assigned to the visitor for the first time.
1153
1187
  * False: variant was already assigned to the visitor and is being reused.
1154
1188
  */
1155
1189
  variantAssigned: boolean;
1190
+ /**
1191
+ * Contains information about the composition that contains A/B test wrapper component,
1192
+ * which triggered the A/B test event.
1193
+ * Only references top level root composition after pattern resolutions.
1194
+ */
1195
+ compositionMetadata?: CompositionMetadata;
1156
1196
  };
1157
1197
  type ContextEvents = {
1158
1198
  /**
@@ -1176,6 +1216,8 @@ type ContextEvents = {
1176
1216
  testResult: TestEvent;
1177
1217
  /** Personalization variants have been selected */
1178
1218
  personalizationResult: PersonalizationEvent;
1219
+ /** Composition metadata has been set/updated, usually happens when new composition is being rendered during client-side navigation for example */
1220
+ canvasDataUpdated: CompositionMetadata;
1179
1221
  };
1180
1222
  interface ContextInstance {
1181
1223
  get scores(): Readonly<ScoreVector>;
@@ -1197,6 +1239,14 @@ interface ContextInstance {
1197
1239
  internal_processTestEvent(event: TestEvent): void;
1198
1240
  /** @deprecated */
1199
1241
  internal_processPersonalizationEvent(event: PersonalizationEvent): void;
1242
+ /**
1243
+ * Gets the current canvas data
1244
+ */
1245
+ getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
1246
+ /**
1247
+ * Updates the canvas data and emits a canvasDataUpdated event
1248
+ */
1249
+ updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
1200
1250
  }
1201
1251
  declare class Context implements ContextInstance {
1202
1252
  #private;
@@ -1266,6 +1316,14 @@ declare class Context implements ContextInstance {
1266
1316
  internal_processTestEvent(event: TestEvent): void;
1267
1317
  /** @deprecated */
1268
1318
  internal_processPersonalizationEvent(event: PersonalizationEvent): void;
1319
+ /**
1320
+ * Gets the current canvas data
1321
+ */
1322
+ getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
1323
+ /**
1324
+ * Updates the canvas data and emits a canvasDataUpdated event
1325
+ */
1326
+ updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
1269
1327
  }
1270
1328
 
1271
1329
  /**
@@ -1337,4 +1395,4 @@ declare global {
1337
1395
  }
1338
1396
  }
1339
1397
 
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 };
1398
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/context",
3
- "version": "20.36.1",
3
+ "version": "20.36.2-alpha.90+94c3a288ac",
4
4
  "description": "Uniform Context core package",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -72,5 +72,5 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "cced31b4edaff96f2eec23f2336ee0873663066a"
75
+ "gitHead": "94c3a288acbde88c1229222ae50bd289b7c5749e"
76
76
  }