@uniformdev/context 20.35.0 → 20.35.1-alpha.210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/api.d.mts +1 -1
- package/dist/api/api.d.ts +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.esm.js +106 -51
- package/dist/index.js +106 -51
- package/dist/index.mjs +106 -51
- package/dist/{types-CzIkFCDD.d.mts → types-HcKr1VVF.d.mts} +66 -3
- package/dist/{types-CzIkFCDD.d.ts → types-HcKr1VVF.d.ts} +66 -3
- package/package.json +3 -5
package/dist/api/api.d.mts
CHANGED
package/dist/api/api.d.ts
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, P as PersonalizedVariant, g as PersonalizeOptions, h as Context, i as PersonalizedResult, j as VariationMatchDimensionCriteria, k as PersonalizationSelectionAlgorithmOptions, l as DevToolsEvents } from './types-
|
|
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,
|
|
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-HcKr1VVF.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-HcKr1VVF.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-
|
|
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,
|
|
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-HcKr1VVF.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-HcKr1VVF.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
|
@@ -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
|
-
|
|
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/
|
|
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 =
|
|
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
|
|
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 =
|
|
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";
|
package/dist/index.js
CHANGED
|
@@ -320,6 +320,10 @@ var ManifestInstance = class {
|
|
|
320
320
|
}
|
|
321
321
|
return (_d = (_c = __privateGet(this, _mf).pz) == null ? void 0 : _c.enr) == null ? void 0 : _d[scoreKey.substring(0, enrichmentIndex)];
|
|
322
322
|
}
|
|
323
|
+
getAggregateDimensionByKey(scoreKey) {
|
|
324
|
+
var _a, _b;
|
|
325
|
+
return (_b = (_a = __privateGet(this, _mf).pz) == null ? void 0 : _a.agg) == null ? void 0 : _b[scoreKey];
|
|
326
|
+
}
|
|
323
327
|
};
|
|
324
328
|
_mf = new WeakMap();
|
|
325
329
|
_signalInstances = new WeakMap();
|
|
@@ -1034,6 +1038,9 @@ var testVariations = ({
|
|
|
1034
1038
|
}
|
|
1035
1039
|
if (selectedVariant) {
|
|
1036
1040
|
onLogMessage == null ? void 0 : onLogMessage(["info", 404, selectedVariant.id]);
|
|
1041
|
+
if (selectedVariant.control === void 0) {
|
|
1042
|
+
selectedVariant.control = variations.findIndex((variation) => variation.id === selectedVariantId) === 0;
|
|
1043
|
+
}
|
|
1037
1044
|
}
|
|
1038
1045
|
return {
|
|
1039
1046
|
result: selectedVariant,
|
|
@@ -1830,6 +1837,9 @@ var Context = class {
|
|
|
1830
1837
|
__privateSet(this, _scores, state.ssv);
|
|
1831
1838
|
__privateGet(this, _mitt3).emit("log", ["debug", 130, state]);
|
|
1832
1839
|
}
|
|
1840
|
+
if (state.compositionMetadata) {
|
|
1841
|
+
__privateGet(this, _state).compositionMetadata = state.compositionMetadata;
|
|
1842
|
+
}
|
|
1833
1843
|
},
|
|
1834
1844
|
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
|
1835
1845
|
});
|
|
@@ -1982,10 +1992,16 @@ var Context = class {
|
|
|
1982
1992
|
scores: __privateGet(this, _serverTransitionState) ? __privateMethod(this, _Context_instances, calculateScores_fn).call(this, this.storage.data) : __privateGet(this, _scores)
|
|
1983
1993
|
})
|
|
1984
1994
|
);
|
|
1995
|
+
const previousCompositionMetadata = __privateGet(this, _state).compositionMetadata;
|
|
1985
1996
|
__privateSet(this, _state, {
|
|
1986
1997
|
...__privateGet(this, _state),
|
|
1987
1998
|
...newData
|
|
1988
1999
|
});
|
|
2000
|
+
if (newData.compositionMetadata && // deep equal is not too bad, as we only have 1 level of depth in dynamic inputs
|
|
2001
|
+
!(0, import_lite5.dequal)(previousCompositionMetadata, __privateGet(this, _state).compositionMetadata)) {
|
|
2002
|
+
__privateGet(this, _mitt3).emit("canvasDataUpdated", __privateGet(this, _state).compositionMetadata);
|
|
2003
|
+
__privateGet(this, _state).compositionMetadata = newData.compositionMetadata;
|
|
2004
|
+
}
|
|
1989
2005
|
await this.storage.updateData(commands);
|
|
1990
2006
|
if (__privateGet(this, _serverTransitionState)) {
|
|
1991
2007
|
await this.processServerCommands({
|
|
@@ -1997,7 +2013,9 @@ var Context = class {
|
|
|
1997
2013
|
__privateMethod(this, _Context_instances, emitTest_fn).call(this, {
|
|
1998
2014
|
name: testName,
|
|
1999
2015
|
variantId: testVariantId,
|
|
2000
|
-
variantAssigned: true
|
|
2016
|
+
variantAssigned: true,
|
|
2017
|
+
control: false,
|
|
2018
|
+
compositionMetadata: void 0
|
|
2001
2019
|
});
|
|
2002
2020
|
});
|
|
2003
2021
|
const haveQuirksChanged = __privateGet(this, _serverTransitionState) && !(0, import_lite5.dequal)(__privateGet(this, _serverTransitionState).quirks, this.storage.data.quirks);
|
|
@@ -2013,7 +2031,7 @@ var Context = class {
|
|
|
2013
2031
|
if (!plugin.update) {
|
|
2014
2032
|
continue;
|
|
2015
2033
|
}
|
|
2016
|
-
await plugin.update(newData);
|
|
2034
|
+
await plugin.update(newData, __privateGet(this, _scores));
|
|
2017
2035
|
}
|
|
2018
2036
|
}
|
|
2019
2037
|
(_e = __privateGet(this, _commands)) == null ? void 0 : _e.push(...commands);
|
|
@@ -2079,7 +2097,7 @@ var Context = class {
|
|
|
2079
2097
|
}
|
|
2080
2098
|
/** 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
2099
|
test(options) {
|
|
2082
|
-
var _a, _b, _c;
|
|
2100
|
+
var _a, _b, _c, _d, _e;
|
|
2083
2101
|
if (options.name === CONTEXTUAL_EDITING_TEST_NAME) {
|
|
2084
2102
|
const selectedVariant = (_a = options.variations.find((variant) => variant.id === CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID)) != null ? _a : options.variations.at(-1);
|
|
2085
2103
|
const value2 = {
|
|
@@ -2096,7 +2114,9 @@ var Context = class {
|
|
|
2096
2114
|
__privateMethod(this, _Context_instances, emitTest_fn).call(this, {
|
|
2097
2115
|
name: options.name,
|
|
2098
2116
|
variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
|
|
2099
|
-
variantAssigned: value.variantAssigned
|
|
2117
|
+
variantAssigned: value.variantAssigned,
|
|
2118
|
+
control: (_e = (_d = value.result) == null ? void 0 : _d.control) != null ? _e : false,
|
|
2119
|
+
compositionMetadata: options.compositionMetadata
|
|
2100
2120
|
});
|
|
2101
2121
|
return value;
|
|
2102
2122
|
}
|
|
@@ -2125,7 +2145,8 @@ var Context = class {
|
|
|
2125
2145
|
control: variation.control
|
|
2126
2146
|
})),
|
|
2127
2147
|
control: this.storage.data.controlGroup,
|
|
2128
|
-
changed: true
|
|
2148
|
+
changed: true,
|
|
2149
|
+
compositionMetadata: options.compositionMetadata
|
|
2129
2150
|
};
|
|
2130
2151
|
if (previousPlacement && (0, import_lite5.dequal)(eventData.variantIds, previousPlacement)) {
|
|
2131
2152
|
eventData.changed = false;
|
|
@@ -2139,7 +2160,10 @@ var Context = class {
|
|
|
2139
2160
|
* @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
|
|
2140
2161
|
*/
|
|
2141
2162
|
async forget(fromAllDevices) {
|
|
2142
|
-
|
|
2163
|
+
const previousCompositionMetadata = __privateGet(this, _state).compositionMetadata;
|
|
2164
|
+
__privateSet(this, _state, {
|
|
2165
|
+
compositionMetadata: previousCompositionMetadata
|
|
2166
|
+
});
|
|
2143
2167
|
if (__privateGet(this, _plugins)) {
|
|
2144
2168
|
for (let i = 0; i < __privateGet(this, _plugins).length; i++) {
|
|
2145
2169
|
const plugin = __privateGet(this, _plugins)[i];
|
|
@@ -2162,7 +2186,8 @@ var Context = class {
|
|
|
2162
2186
|
ssv: __privateGet(this, _scores),
|
|
2163
2187
|
tests: {},
|
|
2164
2188
|
personalizeVariants: this.storage.data.personalizeVariants,
|
|
2165
|
-
commands: __privateGet(this, _commands)
|
|
2189
|
+
commands: __privateGet(this, _commands),
|
|
2190
|
+
compositionMetadata: __privateGet(this, _state).compositionMetadata
|
|
2166
2191
|
};
|
|
2167
2192
|
const allTests = this.storage.data.tests;
|
|
2168
2193
|
Object.entries(allTests).map(([testName, testValue]) => {
|
|
@@ -2185,6 +2210,27 @@ var Context = class {
|
|
|
2185
2210
|
__privateGet(this, _pzCache)[event.name] = event.variantIds;
|
|
2186
2211
|
__privateGet(this, _mitt3).emit("personalizationResult", event);
|
|
2187
2212
|
}
|
|
2213
|
+
/**
|
|
2214
|
+
* Gets the current canvas data
|
|
2215
|
+
*/
|
|
2216
|
+
getCompositionMetadata() {
|
|
2217
|
+
return __privateGet(this, _state).compositionMetadata;
|
|
2218
|
+
}
|
|
2219
|
+
/**
|
|
2220
|
+
* Updates the canvas data and emits a canvasDataUpdated event
|
|
2221
|
+
*/
|
|
2222
|
+
async updateCompositionMetadata(newData) {
|
|
2223
|
+
const currentCanvas = __privateGet(this, _state).compositionMetadata || {};
|
|
2224
|
+
const updatedCanvas = { ...currentCanvas, ...newData };
|
|
2225
|
+
if (!(0, import_lite5.dequal)(currentCanvas, updatedCanvas)) {
|
|
2226
|
+
__privateSet(this, _state, {
|
|
2227
|
+
...__privateGet(this, _state),
|
|
2228
|
+
compositionMetadata: updatedCanvas
|
|
2229
|
+
});
|
|
2230
|
+
__privateGet(this, _mitt3).emit("canvasDataUpdated", updatedCanvas);
|
|
2231
|
+
__privateGet(this, _mitt3).emit("log", ["info", 4, "Canvas data updated"]);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2188
2234
|
};
|
|
2189
2235
|
_personalizationSelectionAlgorithms = new WeakMap();
|
|
2190
2236
|
_serverTransitionState = new WeakMap();
|
|
@@ -2349,7 +2395,31 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
|
|
|
2349
2395
|
})(ScriptType || {});
|
|
2350
2396
|
var EdgeNodeTagName = "nesitag";
|
|
2351
2397
|
|
|
2352
|
-
// src/insights/
|
|
2398
|
+
// src/insights/storage.ts
|
|
2399
|
+
var createInsightsStorage = () => {
|
|
2400
|
+
const STORAGE_KEY2 = "ufin";
|
|
2401
|
+
return {
|
|
2402
|
+
get: () => {
|
|
2403
|
+
const data = localStorage.getItem(STORAGE_KEY2);
|
|
2404
|
+
if (!data) {
|
|
2405
|
+
return;
|
|
2406
|
+
}
|
|
2407
|
+
return JSON.parse(data);
|
|
2408
|
+
},
|
|
2409
|
+
set: (data) => {
|
|
2410
|
+
const toSet = {
|
|
2411
|
+
...data,
|
|
2412
|
+
updated: Date.now()
|
|
2413
|
+
};
|
|
2414
|
+
localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
|
|
2415
|
+
},
|
|
2416
|
+
clear: () => {
|
|
2417
|
+
localStorage.removeItem(STORAGE_KEY2);
|
|
2418
|
+
}
|
|
2419
|
+
};
|
|
2420
|
+
};
|
|
2421
|
+
|
|
2422
|
+
// src/insights/types.ts
|
|
2353
2423
|
var getBasePayload = () => {
|
|
2354
2424
|
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2355
2425
|
const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
|
|
@@ -2362,13 +2432,34 @@ var getBasePayload = () => {
|
|
|
2362
2432
|
href: window.location.href
|
|
2363
2433
|
};
|
|
2364
2434
|
};
|
|
2435
|
+
var generateVisitorId = () => {
|
|
2436
|
+
return `visitor_${generalRandomId()}`;
|
|
2437
|
+
};
|
|
2438
|
+
var generateSessionId = () => {
|
|
2439
|
+
return `session_${generalRandomId()}`;
|
|
2440
|
+
};
|
|
2441
|
+
var generatePageId = () => {
|
|
2442
|
+
return `page_${generalRandomId()}`;
|
|
2443
|
+
};
|
|
2444
|
+
var generalRandomId = () => {
|
|
2445
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
2446
|
+
const id = crypto.randomUUID();
|
|
2447
|
+
return id.replaceAll("-", "").toLowerCase();
|
|
2448
|
+
}
|
|
2449
|
+
return Math.random().toString(32).substring(2);
|
|
2450
|
+
};
|
|
2451
|
+
|
|
2452
|
+
// src/insights/v1.ts
|
|
2365
2453
|
var createInsightsClient = ({ endpoint }) => {
|
|
2366
2454
|
let endpointUrl;
|
|
2367
2455
|
const apiKey = endpoint.apiKey;
|
|
2368
2456
|
const projectId = endpoint.projectId;
|
|
2369
2457
|
if (endpoint.type === "api") {
|
|
2370
2458
|
const url = new URL(endpoint.host);
|
|
2371
|
-
url.pathname =
|
|
2459
|
+
url.pathname = `/v0/events`;
|
|
2460
|
+
if (endpoint.host.includes("tinybird.co")) {
|
|
2461
|
+
url.pathname = "/v0/events";
|
|
2462
|
+
}
|
|
2372
2463
|
url.searchParams.set("name", "analytics_events");
|
|
2373
2464
|
endpointUrl = url.toString();
|
|
2374
2465
|
} else {
|
|
@@ -2498,38 +2589,7 @@ var createInsightsClient = ({ endpoint }) => {
|
|
|
2498
2589
|
}
|
|
2499
2590
|
};
|
|
2500
2591
|
};
|
|
2501
|
-
var
|
|
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 = ({
|
|
2592
|
+
var createInsightsV1 = ({
|
|
2533
2593
|
endpoint,
|
|
2534
2594
|
sessionDurationSeconds = 30 * 60
|
|
2535
2595
|
}) => {
|
|
@@ -2630,8 +2690,10 @@ var createInsights = ({
|
|
|
2630
2690
|
}
|
|
2631
2691
|
};
|
|
2632
2692
|
};
|
|
2693
|
+
|
|
2694
|
+
// src/insights/index.ts
|
|
2633
2695
|
var enableUniformInsights = (options) => {
|
|
2634
|
-
const insights =
|
|
2696
|
+
const insights = createInsightsV1({
|
|
2635
2697
|
endpoint: options.endpoint
|
|
2636
2698
|
});
|
|
2637
2699
|
let previousUrl = void 0;
|
|
@@ -2677,8 +2739,8 @@ var enableUniformInsights = (options) => {
|
|
|
2677
2739
|
};
|
|
2678
2740
|
},
|
|
2679
2741
|
update: (context) => {
|
|
2680
|
-
if (context.url && context.url !== previousUrl) {
|
|
2681
|
-
previousUrl = context.url;
|
|
2742
|
+
if (context.url && context.url.toString() !== previousUrl) {
|
|
2743
|
+
previousUrl = context.url.toString();
|
|
2682
2744
|
insights.pageHit();
|
|
2683
2745
|
}
|
|
2684
2746
|
},
|
|
@@ -2687,13 +2749,6 @@ var enableUniformInsights = (options) => {
|
|
|
2687
2749
|
}
|
|
2688
2750
|
};
|
|
2689
2751
|
};
|
|
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
2752
|
|
|
2698
2753
|
// src/logging/enableConsoleLogDrain.ts
|
|
2699
2754
|
var import_rfdc2 = __toESM(require("rfdc"));
|
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
|
-
|
|
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/
|
|
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 =
|
|
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
|
|
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 =
|
|
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 */
|
|
@@ -179,6 +195,10 @@ type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'test
|
|
|
179
195
|
* Storage commands that the server
|
|
180
196
|
*/
|
|
181
197
|
commands?: StorageCommands[];
|
|
198
|
+
/**
|
|
199
|
+
* Composition metadata from the server side
|
|
200
|
+
*/
|
|
201
|
+
compositionMetadata?: CompositionMetadata;
|
|
182
202
|
};
|
|
183
203
|
declare const SERVER_STATE_ID = "__UNIFORM_DATA__";
|
|
184
204
|
type TransitionDataStoreEvents = {
|
|
@@ -374,6 +394,7 @@ declare class ManifestInstance {
|
|
|
374
394
|
*/
|
|
375
395
|
computeAggregateDimensions(primitiveScores: ScoreVector): ScoreVector;
|
|
376
396
|
getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
|
|
397
|
+
getAggregateDimensionByKey(scoreKey: string): AggregateDimension | undefined;
|
|
377
398
|
}
|
|
378
399
|
|
|
379
400
|
interface paths {
|
|
@@ -1030,6 +1051,10 @@ type TestVariant = {
|
|
|
1030
1051
|
* If not provided, this variant will be selected in equal proportion to other variants without an explicit distribution.
|
|
1031
1052
|
*/
|
|
1032
1053
|
testDistribution?: number;
|
|
1054
|
+
/** Whether this variant is a control variant.
|
|
1055
|
+
* Can be undefined for backward compatibility with older versions of the SDK which were not explicitly setting the control flag.
|
|
1056
|
+
*/
|
|
1057
|
+
control?: boolean;
|
|
1033
1058
|
};
|
|
1034
1059
|
/** The result of computing an A/B test result */
|
|
1035
1060
|
type TestResult<TVariant> = {
|
|
@@ -1051,6 +1076,8 @@ interface PersonalizeOptions<TVariant> {
|
|
|
1051
1076
|
take?: number;
|
|
1052
1077
|
/** Name of the personalization selection algorithm to use. Defaults to top-down criteria when not specified. */
|
|
1053
1078
|
algorithm?: string;
|
|
1079
|
+
/** Composition metadata where the personalization is being rendered for analytics tracking */
|
|
1080
|
+
compositionMetadata?: CompositionMetadata;
|
|
1054
1081
|
}
|
|
1055
1082
|
interface PersonalizationSelectionAlgorithmOptions<TCriteria, TVariant extends PersonalizedVariant<TCriteria> = PersonalizedVariant<TCriteria>> {
|
|
1056
1083
|
/** Name of placement (sent to analytics) */
|
|
@@ -1070,6 +1097,8 @@ type TestOptions<TVariant extends TestVariant> = {
|
|
|
1070
1097
|
name: string;
|
|
1071
1098
|
/** Variations that are being tested. */
|
|
1072
1099
|
variations: TVariant[];
|
|
1100
|
+
/** Composition metadata where the personalization is being rendered for analytics tracking */
|
|
1101
|
+
compositionMetadata?: CompositionMetadata;
|
|
1073
1102
|
};
|
|
1074
1103
|
declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, onLogMessage, }: TestOptions<TVariant> & {
|
|
1075
1104
|
context: Context;
|
|
@@ -1092,8 +1121,8 @@ type ContextPlugin = {
|
|
|
1092
1121
|
init?: (context: Context) => () => void;
|
|
1093
1122
|
/** Plugin-specific actions to perform when a user is forgotten */
|
|
1094
1123
|
forget?: () => Promise<void> | void;
|
|
1095
|
-
/** Plugin-specific actions to perform when the visitor context is updated */
|
|
1096
|
-
update?: (newData: Partial<ContextState
|
|
1124
|
+
/** Plugin-specific actions to perform when the visitor context is updated, second parameter is the recalculated scores after the update */
|
|
1125
|
+
update?: (newData: Partial<ContextState>, recalculatedScores: ScoreVector) => Promise<void> | void;
|
|
1097
1126
|
/**
|
|
1098
1127
|
* Allows the plugin to register named personalization selection algorithms
|
|
1099
1128
|
*
|
|
@@ -1140,6 +1169,12 @@ type PersonalizationEvent = {
|
|
|
1140
1169
|
* False: the variant(s) selected were the same as a previous evaluation of this placement.
|
|
1141
1170
|
*/
|
|
1142
1171
|
changed: boolean;
|
|
1172
|
+
/**
|
|
1173
|
+
* Contains information about the composition that contains personalization wrapper component,
|
|
1174
|
+
* which triggered the personalization event.
|
|
1175
|
+
* Only references top level root composition after pattern resolutions.
|
|
1176
|
+
*/
|
|
1177
|
+
compositionMetadata?: CompositionMetadata;
|
|
1143
1178
|
};
|
|
1144
1179
|
/** Emitted event when an A/B test runs */
|
|
1145
1180
|
type TestEvent = {
|
|
@@ -1147,12 +1182,22 @@ type TestEvent = {
|
|
|
1147
1182
|
name: string;
|
|
1148
1183
|
/** ID of the variant that was selected */
|
|
1149
1184
|
variantId: string | undefined;
|
|
1185
|
+
/**
|
|
1186
|
+
* Whether the variant is part of the control group.
|
|
1187
|
+
*/
|
|
1188
|
+
control: boolean;
|
|
1150
1189
|
/**
|
|
1151
1190
|
* Whether the test variant was newly assigned to the visitor.
|
|
1152
1191
|
* True: variant was assigned to the visitor for the first time.
|
|
1153
1192
|
* False: variant was already assigned to the visitor and is being reused.
|
|
1154
1193
|
*/
|
|
1155
1194
|
variantAssigned: boolean;
|
|
1195
|
+
/**
|
|
1196
|
+
* Contains information about the composition that contains A/B test wrapper component,
|
|
1197
|
+
* which triggered the A/B test event.
|
|
1198
|
+
* Only references top level root composition after pattern resolutions.
|
|
1199
|
+
*/
|
|
1200
|
+
compositionMetadata?: CompositionMetadata;
|
|
1156
1201
|
};
|
|
1157
1202
|
type ContextEvents = {
|
|
1158
1203
|
/**
|
|
@@ -1176,6 +1221,8 @@ type ContextEvents = {
|
|
|
1176
1221
|
testResult: TestEvent;
|
|
1177
1222
|
/** Personalization variants have been selected */
|
|
1178
1223
|
personalizationResult: PersonalizationEvent;
|
|
1224
|
+
/** Composition metadata has been set/updated, usually happens when new composition is being rendered during client-side navigation for example */
|
|
1225
|
+
canvasDataUpdated: CompositionMetadata;
|
|
1179
1226
|
};
|
|
1180
1227
|
interface ContextInstance {
|
|
1181
1228
|
get scores(): Readonly<ScoreVector>;
|
|
@@ -1197,6 +1244,14 @@ interface ContextInstance {
|
|
|
1197
1244
|
internal_processTestEvent(event: TestEvent): void;
|
|
1198
1245
|
/** @deprecated */
|
|
1199
1246
|
internal_processPersonalizationEvent(event: PersonalizationEvent): void;
|
|
1247
|
+
/**
|
|
1248
|
+
* Gets the current canvas data
|
|
1249
|
+
*/
|
|
1250
|
+
getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
|
|
1251
|
+
/**
|
|
1252
|
+
* Updates the canvas data and emits a canvasDataUpdated event
|
|
1253
|
+
*/
|
|
1254
|
+
updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
|
|
1200
1255
|
}
|
|
1201
1256
|
declare class Context implements ContextInstance {
|
|
1202
1257
|
#private;
|
|
@@ -1266,6 +1321,14 @@ declare class Context implements ContextInstance {
|
|
|
1266
1321
|
internal_processTestEvent(event: TestEvent): void;
|
|
1267
1322
|
/** @deprecated */
|
|
1268
1323
|
internal_processPersonalizationEvent(event: PersonalizationEvent): void;
|
|
1324
|
+
/**
|
|
1325
|
+
* Gets the current canvas data
|
|
1326
|
+
*/
|
|
1327
|
+
getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
|
|
1328
|
+
/**
|
|
1329
|
+
* Updates the canvas data and emits a canvasDataUpdated event
|
|
1330
|
+
*/
|
|
1331
|
+
updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
|
|
1269
1332
|
}
|
|
1270
1333
|
|
|
1271
1334
|
/**
|
|
@@ -1337,4 +1400,4 @@ declare global {
|
|
|
1337
1400
|
}
|
|
1338
1401
|
}
|
|
1339
1402
|
|
|
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
|
|
1403
|
+
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 */
|
|
@@ -179,6 +195,10 @@ type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'test
|
|
|
179
195
|
* Storage commands that the server
|
|
180
196
|
*/
|
|
181
197
|
commands?: StorageCommands[];
|
|
198
|
+
/**
|
|
199
|
+
* Composition metadata from the server side
|
|
200
|
+
*/
|
|
201
|
+
compositionMetadata?: CompositionMetadata;
|
|
182
202
|
};
|
|
183
203
|
declare const SERVER_STATE_ID = "__UNIFORM_DATA__";
|
|
184
204
|
type TransitionDataStoreEvents = {
|
|
@@ -374,6 +394,7 @@ declare class ManifestInstance {
|
|
|
374
394
|
*/
|
|
375
395
|
computeAggregateDimensions(primitiveScores: ScoreVector): ScoreVector;
|
|
376
396
|
getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
|
|
397
|
+
getAggregateDimensionByKey(scoreKey: string): AggregateDimension | undefined;
|
|
377
398
|
}
|
|
378
399
|
|
|
379
400
|
interface paths {
|
|
@@ -1030,6 +1051,10 @@ type TestVariant = {
|
|
|
1030
1051
|
* If not provided, this variant will be selected in equal proportion to other variants without an explicit distribution.
|
|
1031
1052
|
*/
|
|
1032
1053
|
testDistribution?: number;
|
|
1054
|
+
/** Whether this variant is a control variant.
|
|
1055
|
+
* Can be undefined for backward compatibility with older versions of the SDK which were not explicitly setting the control flag.
|
|
1056
|
+
*/
|
|
1057
|
+
control?: boolean;
|
|
1033
1058
|
};
|
|
1034
1059
|
/** The result of computing an A/B test result */
|
|
1035
1060
|
type TestResult<TVariant> = {
|
|
@@ -1051,6 +1076,8 @@ interface PersonalizeOptions<TVariant> {
|
|
|
1051
1076
|
take?: number;
|
|
1052
1077
|
/** Name of the personalization selection algorithm to use. Defaults to top-down criteria when not specified. */
|
|
1053
1078
|
algorithm?: string;
|
|
1079
|
+
/** Composition metadata where the personalization is being rendered for analytics tracking */
|
|
1080
|
+
compositionMetadata?: CompositionMetadata;
|
|
1054
1081
|
}
|
|
1055
1082
|
interface PersonalizationSelectionAlgorithmOptions<TCriteria, TVariant extends PersonalizedVariant<TCriteria> = PersonalizedVariant<TCriteria>> {
|
|
1056
1083
|
/** Name of placement (sent to analytics) */
|
|
@@ -1070,6 +1097,8 @@ type TestOptions<TVariant extends TestVariant> = {
|
|
|
1070
1097
|
name: string;
|
|
1071
1098
|
/** Variations that are being tested. */
|
|
1072
1099
|
variations: TVariant[];
|
|
1100
|
+
/** Composition metadata where the personalization is being rendered for analytics tracking */
|
|
1101
|
+
compositionMetadata?: CompositionMetadata;
|
|
1073
1102
|
};
|
|
1074
1103
|
declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, onLogMessage, }: TestOptions<TVariant> & {
|
|
1075
1104
|
context: Context;
|
|
@@ -1092,8 +1121,8 @@ type ContextPlugin = {
|
|
|
1092
1121
|
init?: (context: Context) => () => void;
|
|
1093
1122
|
/** Plugin-specific actions to perform when a user is forgotten */
|
|
1094
1123
|
forget?: () => Promise<void> | void;
|
|
1095
|
-
/** Plugin-specific actions to perform when the visitor context is updated */
|
|
1096
|
-
update?: (newData: Partial<ContextState
|
|
1124
|
+
/** Plugin-specific actions to perform when the visitor context is updated, second parameter is the recalculated scores after the update */
|
|
1125
|
+
update?: (newData: Partial<ContextState>, recalculatedScores: ScoreVector) => Promise<void> | void;
|
|
1097
1126
|
/**
|
|
1098
1127
|
* Allows the plugin to register named personalization selection algorithms
|
|
1099
1128
|
*
|
|
@@ -1140,6 +1169,12 @@ type PersonalizationEvent = {
|
|
|
1140
1169
|
* False: the variant(s) selected were the same as a previous evaluation of this placement.
|
|
1141
1170
|
*/
|
|
1142
1171
|
changed: boolean;
|
|
1172
|
+
/**
|
|
1173
|
+
* Contains information about the composition that contains personalization wrapper component,
|
|
1174
|
+
* which triggered the personalization event.
|
|
1175
|
+
* Only references top level root composition after pattern resolutions.
|
|
1176
|
+
*/
|
|
1177
|
+
compositionMetadata?: CompositionMetadata;
|
|
1143
1178
|
};
|
|
1144
1179
|
/** Emitted event when an A/B test runs */
|
|
1145
1180
|
type TestEvent = {
|
|
@@ -1147,12 +1182,22 @@ type TestEvent = {
|
|
|
1147
1182
|
name: string;
|
|
1148
1183
|
/** ID of the variant that was selected */
|
|
1149
1184
|
variantId: string | undefined;
|
|
1185
|
+
/**
|
|
1186
|
+
* Whether the variant is part of the control group.
|
|
1187
|
+
*/
|
|
1188
|
+
control: boolean;
|
|
1150
1189
|
/**
|
|
1151
1190
|
* Whether the test variant was newly assigned to the visitor.
|
|
1152
1191
|
* True: variant was assigned to the visitor for the first time.
|
|
1153
1192
|
* False: variant was already assigned to the visitor and is being reused.
|
|
1154
1193
|
*/
|
|
1155
1194
|
variantAssigned: boolean;
|
|
1195
|
+
/**
|
|
1196
|
+
* Contains information about the composition that contains A/B test wrapper component,
|
|
1197
|
+
* which triggered the A/B test event.
|
|
1198
|
+
* Only references top level root composition after pattern resolutions.
|
|
1199
|
+
*/
|
|
1200
|
+
compositionMetadata?: CompositionMetadata;
|
|
1156
1201
|
};
|
|
1157
1202
|
type ContextEvents = {
|
|
1158
1203
|
/**
|
|
@@ -1176,6 +1221,8 @@ type ContextEvents = {
|
|
|
1176
1221
|
testResult: TestEvent;
|
|
1177
1222
|
/** Personalization variants have been selected */
|
|
1178
1223
|
personalizationResult: PersonalizationEvent;
|
|
1224
|
+
/** Composition metadata has been set/updated, usually happens when new composition is being rendered during client-side navigation for example */
|
|
1225
|
+
canvasDataUpdated: CompositionMetadata;
|
|
1179
1226
|
};
|
|
1180
1227
|
interface ContextInstance {
|
|
1181
1228
|
get scores(): Readonly<ScoreVector>;
|
|
@@ -1197,6 +1244,14 @@ interface ContextInstance {
|
|
|
1197
1244
|
internal_processTestEvent(event: TestEvent): void;
|
|
1198
1245
|
/** @deprecated */
|
|
1199
1246
|
internal_processPersonalizationEvent(event: PersonalizationEvent): void;
|
|
1247
|
+
/**
|
|
1248
|
+
* Gets the current canvas data
|
|
1249
|
+
*/
|
|
1250
|
+
getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
|
|
1251
|
+
/**
|
|
1252
|
+
* Updates the canvas data and emits a canvasDataUpdated event
|
|
1253
|
+
*/
|
|
1254
|
+
updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
|
|
1200
1255
|
}
|
|
1201
1256
|
declare class Context implements ContextInstance {
|
|
1202
1257
|
#private;
|
|
@@ -1266,6 +1321,14 @@ declare class Context implements ContextInstance {
|
|
|
1266
1321
|
internal_processTestEvent(event: TestEvent): void;
|
|
1267
1322
|
/** @deprecated */
|
|
1268
1323
|
internal_processPersonalizationEvent(event: PersonalizationEvent): void;
|
|
1324
|
+
/**
|
|
1325
|
+
* Gets the current canvas data
|
|
1326
|
+
*/
|
|
1327
|
+
getCompositionMetadata(): Readonly<CompositionMetadata | undefined>;
|
|
1328
|
+
/**
|
|
1329
|
+
* Updates the canvas data and emits a canvasDataUpdated event
|
|
1330
|
+
*/
|
|
1331
|
+
updateCompositionMetadata(newData: CompositionMetadata): Promise<void>;
|
|
1269
1332
|
}
|
|
1270
1333
|
|
|
1271
1334
|
/**
|
|
@@ -1337,4 +1400,4 @@ declare global {
|
|
|
1337
1400
|
}
|
|
1338
1401
|
}
|
|
1339
1402
|
|
|
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
|
|
1403
|
+
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.35.
|
|
3
|
+
"version": "20.35.1-alpha.210+4fa236da76",
|
|
4
4
|
"description": "Uniform Context core package",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,11 +53,9 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/js-cookie": "3.0.6",
|
|
55
55
|
"@types/uuid": "9.0.4",
|
|
56
|
-
"@vitest/coverage-v8": "3.2.4",
|
|
57
56
|
"benny": "3.7.1",
|
|
58
57
|
"vite": "7.1.5",
|
|
59
|
-
"vite-tsconfig-paths": "^5.1.4"
|
|
60
|
-
"vitest": "3.2.4"
|
|
58
|
+
"vite-tsconfig-paths": "^5.1.4"
|
|
61
59
|
},
|
|
62
60
|
"dependencies": {
|
|
63
61
|
"dequal": "^2.0.2",
|
|
@@ -72,5 +70,5 @@
|
|
|
72
70
|
"publishConfig": {
|
|
73
71
|
"access": "public"
|
|
74
72
|
},
|
|
75
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "4fa236da76e057582eae6c2595a2fa763fda886a"
|
|
76
74
|
}
|