@uniformdev/context 19.146.1-alpha.1 → 19.146.2
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 -25
- package/dist/api/api.d.ts +1 -25
- package/dist/index.d.mts +3 -12
- package/dist/index.d.ts +3 -12
- package/dist/index.esm.js +7 -447
- package/dist/index.js +7 -448
- package/dist/index.mjs +7 -447
- package/dist/{types-DqYG-dCc.d.mts → types-WtfxfDct.d.mts} +2 -36
- package/dist/{types-DqYG-dCc.d.ts → types-WtfxfDct.d.ts} +2 -36
- package/package.json +3 -5
package/dist/index.js
CHANGED
@@ -80,7 +80,6 @@ __export(src_exports, {
|
|
80
80
|
enableConsoleLogDrain: () => enableConsoleLogDrain,
|
81
81
|
enableContextDevTools: () => enableContextDevTools,
|
82
82
|
enableDebugConsoleLogDrain: () => enableDebugConsoleLogDrain,
|
83
|
-
enableUniformInsights: () => enableUniformInsights,
|
84
83
|
evaluateVariantMatch: () => evaluateVariantMatch,
|
85
84
|
eventEvaluator: () => eventEvaluator,
|
86
85
|
explainStringMatch: () => explainStringMatch,
|
@@ -147,31 +146,6 @@ function computeAggregateDimension(primitiveScores, aggregateDimension, allAggre
|
|
147
146
|
// src/manifest/constants.ts
|
148
147
|
var ENR_SEPARATOR = "_";
|
149
148
|
|
150
|
-
// src/manifest/goals/evaluators/SignalGoalEvaluator.ts
|
151
|
-
var _signal, _id;
|
152
|
-
var SignalGoalEvaluator = class {
|
153
|
-
constructor(options) {
|
154
|
-
__privateAdd(this, _signal, void 0);
|
155
|
-
__privateAdd(this, _id, void 0);
|
156
|
-
__privateSet(this, _id, options.id);
|
157
|
-
__privateSet(this, _signal, options.signal);
|
158
|
-
}
|
159
|
-
get id() {
|
160
|
-
return __privateGet(this, _id);
|
161
|
-
}
|
162
|
-
evaluate({ scores, quirks }) {
|
163
|
-
const score = scores == null ? void 0 : scores[__privateGet(this, _id)];
|
164
|
-
const key = `goal_${__privateGet(this, _id)}_triggered`;
|
165
|
-
const hasGoalTriggered = (quirks == null ? void 0 : quirks[key]) === "1";
|
166
|
-
return {
|
167
|
-
key,
|
168
|
-
triggered: typeof score === "number" && !hasGoalTriggered
|
169
|
-
};
|
170
|
-
}
|
171
|
-
};
|
172
|
-
_signal = new WeakMap();
|
173
|
-
_id = new WeakMap();
|
174
|
-
|
175
149
|
// src/manifest/signals/SignalInstance.ts
|
176
150
|
var _evaluator, _onLogMessage;
|
177
151
|
var SignalInstance = class {
|
@@ -229,7 +203,7 @@ var rollForControlGroup = (value) => {
|
|
229
203
|
};
|
230
204
|
|
231
205
|
// src/manifest/ManifestInstance.ts
|
232
|
-
var _mf, _signalInstances,
|
206
|
+
var _mf, _signalInstances, _onLogMessage2;
|
233
207
|
var ManifestInstance = class {
|
234
208
|
constructor({
|
235
209
|
manifest,
|
@@ -241,19 +215,13 @@ var ManifestInstance = class {
|
|
241
215
|
__publicField(this, "data");
|
242
216
|
__privateAdd(this, _mf, void 0);
|
243
217
|
__privateAdd(this, _signalInstances, void 0);
|
244
|
-
__privateAdd(this, _goalEvaluators, []);
|
245
218
|
__privateAdd(this, _onLogMessage2, void 0);
|
246
|
-
var _a, _b, _c
|
219
|
+
var _a, _b, _c;
|
247
220
|
__privateSet(this, _mf, (_a = manifest.project) != null ? _a : {});
|
248
221
|
this.data = manifest;
|
249
222
|
__privateSet(this, _signalInstances, Object.entries((_c = (_b = __privateGet(this, _mf).pz) == null ? void 0 : _b.sig) != null ? _c : []).map(
|
250
223
|
([id, signal]) => new SignalInstance({ ...signal, id }, evaluator, onLogMessage)
|
251
224
|
));
|
252
|
-
Object.entries((_e = (_d = __privateGet(this, _mf).pz) == null ? void 0 : _d.sig) != null ? _e : []).forEach(([id, signal]) => {
|
253
|
-
if (signal.conversion) {
|
254
|
-
__privateGet(this, _goalEvaluators).push(new SignalGoalEvaluator({ id, signal }));
|
255
|
-
}
|
256
|
-
});
|
257
225
|
__privateSet(this, _onLogMessage2, onLogMessage);
|
258
226
|
}
|
259
227
|
rollForControlGroup() {
|
@@ -281,28 +249,6 @@ var ManifestInstance = class {
|
|
281
249
|
}
|
282
250
|
return commands;
|
283
251
|
}
|
284
|
-
computeGoals(data) {
|
285
|
-
const commands = [];
|
286
|
-
__privateGet(this, _goalEvaluators).forEach((evaluator) => {
|
287
|
-
const { triggered, key } = evaluator.evaluate(data);
|
288
|
-
if (triggered) {
|
289
|
-
commands.push({
|
290
|
-
type: "setgoal",
|
291
|
-
data: {
|
292
|
-
goal: evaluator.id
|
293
|
-
}
|
294
|
-
});
|
295
|
-
commands.push({
|
296
|
-
type: "setquirk",
|
297
|
-
data: {
|
298
|
-
key,
|
299
|
-
value: "1"
|
300
|
-
}
|
301
|
-
});
|
302
|
-
}
|
303
|
-
});
|
304
|
-
return commands;
|
305
|
-
}
|
306
252
|
/**
|
307
253
|
* Computes aggregated scores based on other dimensions
|
308
254
|
*/
|
@@ -321,7 +267,6 @@ var ManifestInstance = class {
|
|
321
267
|
};
|
322
268
|
_mf = new WeakMap();
|
323
269
|
_signalInstances = new WeakMap();
|
324
|
-
_goalEvaluators = new WeakMap();
|
325
270
|
_onLogMessage2 = new WeakMap();
|
326
271
|
|
327
272
|
// src/manifest/signals/criteria/evaluators/cookieEvaluator.ts
|
@@ -1213,7 +1158,6 @@ var emptyVisitorData = () => ({
|
|
1213
1158
|
scores: {},
|
1214
1159
|
sessionScores: {},
|
1215
1160
|
tests: {},
|
1216
|
-
goals: {},
|
1217
1161
|
consent: false,
|
1218
1162
|
controlGroup: false,
|
1219
1163
|
personalizeVariants: {}
|
@@ -1229,7 +1173,7 @@ var clone = (0, import_rfdc.default)();
|
|
1229
1173
|
function applyCommandsToData(commands, state, inControlGroup) {
|
1230
1174
|
const newData = state ? clone(state) : emptyVisitorData();
|
1231
1175
|
commands.forEach((command) => {
|
1232
|
-
var _a, _b
|
1176
|
+
var _a, _b;
|
1233
1177
|
switch (command.type) {
|
1234
1178
|
case "consent":
|
1235
1179
|
newData.consent = command.data;
|
@@ -1284,10 +1228,6 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1284
1228
|
console.warn("Overwriting existing control group definition is not allowed");
|
1285
1229
|
}
|
1286
1230
|
break;
|
1287
|
-
case "setgoal":
|
1288
|
-
newData.goals = (_c = newData.goals) != null ? _c : {};
|
1289
|
-
newData.goals[command.data.goal] = true;
|
1290
|
-
break;
|
1291
1231
|
default:
|
1292
1232
|
throw new Error(`Unknown command`);
|
1293
1233
|
}
|
@@ -1453,7 +1393,7 @@ currentData_get = function() {
|
|
1453
1393
|
};
|
1454
1394
|
_replaceData = new WeakSet();
|
1455
1395
|
replaceData_fn = function(data, quiet = false) {
|
1456
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
1396
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
1457
1397
|
const oldData = __privateGet(this, _currentData, currentData_get);
|
1458
1398
|
const now = Date.now();
|
1459
1399
|
if (data.controlGroup) {
|
@@ -1474,7 +1414,6 @@ replaceData_fn = function(data, quiet = false) {
|
|
1474
1414
|
const haveSessionScoresChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
|
1475
1415
|
const haveQuirksChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
|
1476
1416
|
const haveTestsChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
|
1477
|
-
const haveGoalsChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
|
1478
1417
|
const updatedData = {
|
1479
1418
|
updated: now,
|
1480
1419
|
visitorData: data
|
@@ -1499,15 +1438,6 @@ replaceData_fn = function(data, quiet = false) {
|
|
1499
1438
|
__privateGet(this, _mitt2).emit("controlGroupUpdated", data);
|
1500
1439
|
(_i = (_h = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _i.call(_h, ["debug", 104, (_g = data.controlGroup) != null ? _g : false]);
|
1501
1440
|
}
|
1502
|
-
if (haveGoalsChanged) {
|
1503
|
-
const newGoalKeys = Object.keys((_j = data.goals) != null ? _j : {});
|
1504
|
-
for (let i = 0; i < newGoalKeys.length; i++) {
|
1505
|
-
const key = newGoalKeys[i];
|
1506
|
-
if (!((_k = oldData == null ? void 0 : oldData.visitorData.goals) == null ? void 0 : _k[key])) {
|
1507
|
-
__privateGet(this, _mitt2).emit("goalConverted", { goalId: key });
|
1508
|
-
}
|
1509
|
-
}
|
1510
|
-
}
|
1511
1441
|
}
|
1512
1442
|
};
|
1513
1443
|
_setVisitTimeout = new WeakSet();
|
@@ -1560,11 +1490,10 @@ var import_lite4 = require("dequal/lite");
|
|
1560
1490
|
var import_mitt3 = __toESM(require("mitt"));
|
1561
1491
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1562
1492
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1563
|
-
var _serverTransitionState, _scores, _state, _pzCache,
|
1493
|
+
var _serverTransitionState, _scores, _state, _pzCache, _mitt3, _emitTest, emitTest_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
|
1564
1494
|
var Context = class {
|
1565
1495
|
constructor(options) {
|
1566
1496
|
__privateAdd(this, _emitTest);
|
1567
|
-
__privateAdd(this, _updateGoals);
|
1568
1497
|
__privateAdd(this, _updateComputedScores);
|
1569
1498
|
__privateAdd(this, _calculateScores);
|
1570
1499
|
__publicField(this, "manifest");
|
@@ -1572,7 +1501,6 @@ var Context = class {
|
|
1572
1501
|
__privateAdd(this, _scores, {});
|
1573
1502
|
__privateAdd(this, _state, void 0);
|
1574
1503
|
__privateAdd(this, _pzCache, {});
|
1575
|
-
__privateAdd(this, _plugins, void 0);
|
1576
1504
|
__privateAdd(this, _mitt3, (0, import_mitt3.default)());
|
1577
1505
|
/**
|
1578
1506
|
* Subscribe to events
|
@@ -1585,8 +1513,7 @@ var Context = class {
|
|
1585
1513
|
var _a, _b;
|
1586
1514
|
const { manifest, ...storageOptions } = options;
|
1587
1515
|
__privateSet(this, _state, {});
|
1588
|
-
|
1589
|
-
(_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
|
1516
|
+
(_a = options.plugins) == null ? void 0 : _a.forEach((plugin) => {
|
1590
1517
|
if (!plugin.logDrain) {
|
1591
1518
|
return;
|
1592
1519
|
}
|
@@ -1629,15 +1556,11 @@ var Context = class {
|
|
1629
1556
|
previousState: __privateGet(this, _state),
|
1630
1557
|
visitor: this.storage.data
|
1631
1558
|
});
|
1632
|
-
__privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
|
1633
|
-
quirks: quirks.quirks,
|
1634
|
-
scores: void 0
|
1635
|
-
});
|
1636
1559
|
this.storage.updateData(updates);
|
1637
1560
|
__privateGet(this, _mitt3).emit("quirksUpdated", quirks.quirks);
|
1638
1561
|
__privateGet(this, _mitt3).emit("log", ["info", 4, quirks.quirks]);
|
1639
1562
|
});
|
1640
|
-
(_b =
|
1563
|
+
(_b = options.plugins) == null ? void 0 : _b.forEach((plugin) => {
|
1641
1564
|
if (!plugin.init) {
|
1642
1565
|
return;
|
1643
1566
|
}
|
@@ -1772,15 +1695,6 @@ var Context = class {
|
|
1772
1695
|
__privateSet(this, _serverTransitionState, void 0);
|
1773
1696
|
__privateGet(this, _mitt3).emit("log", ["debug", 131]);
|
1774
1697
|
}
|
1775
|
-
if (__privateGet(this, _plugins)) {
|
1776
|
-
for (let i = 0; i < __privateGet(this, _plugins).length; i++) {
|
1777
|
-
const plugin = __privateGet(this, _plugins)[i];
|
1778
|
-
if (!plugin.update) {
|
1779
|
-
continue;
|
1780
|
-
}
|
1781
|
-
await plugin.update(newData);
|
1782
|
-
}
|
1783
|
-
}
|
1784
1698
|
} finally {
|
1785
1699
|
__privateGet(this, _mitt3).emit("log", ["info", 2, "ENDGROUP"]);
|
1786
1700
|
}
|
@@ -1876,15 +1790,6 @@ var Context = class {
|
|
1876
1790
|
*/
|
1877
1791
|
async forget(fromAllDevices) {
|
1878
1792
|
__privateSet(this, _state, {});
|
1879
|
-
if (__privateGet(this, _plugins)) {
|
1880
|
-
for (let i = 0; i < __privateGet(this, _plugins).length; i++) {
|
1881
|
-
const plugin = __privateGet(this, _plugins)[i];
|
1882
|
-
if (!plugin.forget) {
|
1883
|
-
continue;
|
1884
|
-
}
|
1885
|
-
await plugin.forget();
|
1886
|
-
}
|
1887
|
-
}
|
1888
1793
|
await this.storage.delete(fromAllDevices);
|
1889
1794
|
}
|
1890
1795
|
/**
|
@@ -1925,29 +1830,17 @@ _serverTransitionState = new WeakMap();
|
|
1925
1830
|
_scores = new WeakMap();
|
1926
1831
|
_state = new WeakMap();
|
1927
1832
|
_pzCache = new WeakMap();
|
1928
|
-
_plugins = new WeakMap();
|
1929
1833
|
_mitt3 = new WeakMap();
|
1930
1834
|
_emitTest = new WeakSet();
|
1931
1835
|
emitTest_fn = function(event) {
|
1932
1836
|
__privateGet(this, _mitt3).emit("testResult", event);
|
1933
1837
|
};
|
1934
|
-
_updateGoals = new WeakSet();
|
1935
|
-
updateGoals_fn = async function(data) {
|
1936
|
-
const goalCommands = this.manifest.computeGoals(data);
|
1937
|
-
if (goalCommands.length !== 0) {
|
1938
|
-
await this.storage.updateData(goalCommands);
|
1939
|
-
}
|
1940
|
-
};
|
1941
1838
|
_updateComputedScores = new WeakSet();
|
1942
1839
|
updateComputedScores_fn = function(newData) {
|
1943
1840
|
const newScores = __privateMethod(this, _calculateScores, calculateScores_fn).call(this, newData);
|
1944
1841
|
const newScoresHaveChanged = !(0, import_lite4.dequal)(newScores, __privateGet(this, _scores));
|
1945
1842
|
if (newScoresHaveChanged) {
|
1946
1843
|
__privateSet(this, _scores, newScores);
|
1947
|
-
__privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
|
1948
|
-
scores: __privateGet(this, _scores),
|
1949
|
-
quirks: void 0
|
1950
|
-
});
|
1951
1844
|
__privateGet(this, _mitt3).emit("scoresUpdated", newScores);
|
1952
1845
|
__privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
|
1953
1846
|
}
|
@@ -2086,339 +1979,6 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
|
|
2086
1979
|
})(ScriptType || {});
|
2087
1980
|
var EdgeNodeTagName = "nesitag";
|
2088
1981
|
|
2089
|
-
// src/insights/index.ts
|
2090
|
-
var import_uuid = require("uuid");
|
2091
|
-
var getBasePayload = () => {
|
2092
|
-
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
2093
|
-
const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
|
2094
|
-
return {
|
2095
|
-
"user-agent": window.navigator.userAgent,
|
2096
|
-
locale,
|
2097
|
-
location: timeZone,
|
2098
|
-
referrer: document.referrer,
|
2099
|
-
pathname: window.location.pathname,
|
2100
|
-
href: window.location.href
|
2101
|
-
};
|
2102
|
-
};
|
2103
|
-
var createInsightsClient = ({ endpoint }) => {
|
2104
|
-
const url = new URL(endpoint.host);
|
2105
|
-
url.pathname = "/v0/events";
|
2106
|
-
url.searchParams.set("name", "analytics_events");
|
2107
|
-
const endpointUrl = url.toString();
|
2108
|
-
const sendMessage = async (message) => {
|
2109
|
-
if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
|
2110
|
-
return;
|
2111
|
-
}
|
2112
|
-
const converted = {
|
2113
|
-
...message,
|
2114
|
-
payload: JSON.stringify(message.payload)
|
2115
|
-
};
|
2116
|
-
const response = await fetch(endpointUrl, {
|
2117
|
-
method: "POST",
|
2118
|
-
headers: {
|
2119
|
-
"Content-Type": "application/json",
|
2120
|
-
Authorization: `Bearer ${endpoint.apiKey}`
|
2121
|
-
},
|
2122
|
-
body: JSON.stringify(converted)
|
2123
|
-
});
|
2124
|
-
const json = await response.json();
|
2125
|
-
return json;
|
2126
|
-
};
|
2127
|
-
return {
|
2128
|
-
sessionStart: (options) => {
|
2129
|
-
const message = {
|
2130
|
-
action: "session_start",
|
2131
|
-
version: "1",
|
2132
|
-
session_id: options.sessionId,
|
2133
|
-
visitor_id: options.visitorId,
|
2134
|
-
page_view_id: options.pageId,
|
2135
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
2136
|
-
payload: {
|
2137
|
-
...getBasePayload(),
|
2138
|
-
previous_session_id: options.previousSessionId
|
2139
|
-
}
|
2140
|
-
};
|
2141
|
-
return sendMessage(message);
|
2142
|
-
},
|
2143
|
-
pageHit: (options) => {
|
2144
|
-
const message = {
|
2145
|
-
action: "page_hit",
|
2146
|
-
version: "1",
|
2147
|
-
session_id: options.sessionId,
|
2148
|
-
visitor_id: options.visitorId,
|
2149
|
-
page_view_id: options.pageId,
|
2150
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
2151
|
-
payload: getBasePayload()
|
2152
|
-
};
|
2153
|
-
return sendMessage(message);
|
2154
|
-
},
|
2155
|
-
testResult: async (options) => {
|
2156
|
-
const message = {
|
2157
|
-
action: "test_result",
|
2158
|
-
version: "1",
|
2159
|
-
session_id: options.sessionId,
|
2160
|
-
visitor_id: options.visitorId,
|
2161
|
-
page_view_id: options.pageId,
|
2162
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
2163
|
-
payload: {
|
2164
|
-
...getBasePayload(),
|
2165
|
-
...options
|
2166
|
-
}
|
2167
|
-
};
|
2168
|
-
return sendMessage(message);
|
2169
|
-
},
|
2170
|
-
personalizationResult: async (options) => {
|
2171
|
-
const messages = options.variantIds.map((variant) => {
|
2172
|
-
const message = {
|
2173
|
-
action: "personalization_result",
|
2174
|
-
version: "1",
|
2175
|
-
session_id: options.sessionId,
|
2176
|
-
visitor_id: options.visitorId,
|
2177
|
-
page_view_id: options.pageId,
|
2178
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
2179
|
-
payload: {
|
2180
|
-
...getBasePayload(),
|
2181
|
-
name: options.name,
|
2182
|
-
variantId: variant.id,
|
2183
|
-
control: variant.control || options.control,
|
2184
|
-
changed: options.changed
|
2185
|
-
}
|
2186
|
-
};
|
2187
|
-
return message;
|
2188
|
-
});
|
2189
|
-
await Promise.all(messages.map((message) => sendMessage(message)));
|
2190
|
-
},
|
2191
|
-
goalConvert: (options) => {
|
2192
|
-
const message = {
|
2193
|
-
action: "goal_convert",
|
2194
|
-
version: "1",
|
2195
|
-
session_id: options.sessionId,
|
2196
|
-
visitor_id: options.visitorId,
|
2197
|
-
page_view_id: options.pageId,
|
2198
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
2199
|
-
payload: {
|
2200
|
-
...getBasePayload(),
|
2201
|
-
goalId: options.goalId
|
2202
|
-
}
|
2203
|
-
};
|
2204
|
-
return sendMessage(message);
|
2205
|
-
},
|
2206
|
-
scoresChange: async (options) => {
|
2207
|
-
const message = {
|
2208
|
-
action: "scores_change",
|
2209
|
-
version: "1",
|
2210
|
-
session_id: options.sessionId,
|
2211
|
-
visitor_id: options.visitorId,
|
2212
|
-
page_view_id: options.pageId,
|
2213
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
2214
|
-
payload: {
|
2215
|
-
...getBasePayload(),
|
2216
|
-
scores: options.scores
|
2217
|
-
}
|
2218
|
-
};
|
2219
|
-
return sendMessage(message);
|
2220
|
-
}
|
2221
|
-
};
|
2222
|
-
};
|
2223
|
-
var createInsightsStorage = () => {
|
2224
|
-
const STORAGE_KEY2 = "ufin";
|
2225
|
-
return {
|
2226
|
-
get: () => {
|
2227
|
-
const data = localStorage.getItem(STORAGE_KEY2);
|
2228
|
-
if (!data) {
|
2229
|
-
return;
|
2230
|
-
}
|
2231
|
-
return JSON.parse(data);
|
2232
|
-
},
|
2233
|
-
set: (data) => {
|
2234
|
-
const toSet = {
|
2235
|
-
...data,
|
2236
|
-
updated: Date.now()
|
2237
|
-
};
|
2238
|
-
localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
|
2239
|
-
},
|
2240
|
-
clear: () => {
|
2241
|
-
localStorage.removeItem(STORAGE_KEY2);
|
2242
|
-
}
|
2243
|
-
};
|
2244
|
-
};
|
2245
|
-
var generateVisitorId = () => {
|
2246
|
-
return `visitor_${generalRandomId()}`;
|
2247
|
-
};
|
2248
|
-
var generateSessionId = () => {
|
2249
|
-
return `session_${generalRandomId()}`;
|
2250
|
-
};
|
2251
|
-
var generatePageId = () => {
|
2252
|
-
return `page_${generalRandomId()}`;
|
2253
|
-
};
|
2254
|
-
var createInsights = ({
|
2255
|
-
endpoint,
|
2256
|
-
sessionDurationSeconds = 30 * 60
|
2257
|
-
}) => {
|
2258
|
-
const client = createInsightsClient({
|
2259
|
-
endpoint
|
2260
|
-
});
|
2261
|
-
const storage = createInsightsStorage();
|
2262
|
-
let storageData = void 0;
|
2263
|
-
let pageId = generatePageId();
|
2264
|
-
let previousUrl = void 0;
|
2265
|
-
return {
|
2266
|
-
init: () => {
|
2267
|
-
storageData = storage.get();
|
2268
|
-
if (!storageData || Date.now() - storageData.updated > sessionDurationSeconds * 1e3) {
|
2269
|
-
const previousSessionId = storageData == null ? void 0 : storageData.sessionId;
|
2270
|
-
storageData = {
|
2271
|
-
visitorId: (storageData == null ? void 0 : storageData.visitorId) || generateVisitorId(),
|
2272
|
-
sessionId: generateSessionId(),
|
2273
|
-
updated: Date.now()
|
2274
|
-
};
|
2275
|
-
storage.set(storageData);
|
2276
|
-
client.sessionStart({
|
2277
|
-
visitorId: storageData.visitorId,
|
2278
|
-
sessionId: storageData.sessionId,
|
2279
|
-
previousSessionId,
|
2280
|
-
maxAgeSeconds: sessionDurationSeconds,
|
2281
|
-
pageId
|
2282
|
-
});
|
2283
|
-
} else if (storageData) {
|
2284
|
-
storage.set(storageData);
|
2285
|
-
}
|
2286
|
-
},
|
2287
|
-
pageHit: () => {
|
2288
|
-
if (!storageData) {
|
2289
|
-
console.error("Insights not initialized");
|
2290
|
-
return;
|
2291
|
-
}
|
2292
|
-
if (previousUrl === window.location.href) {
|
2293
|
-
return;
|
2294
|
-
}
|
2295
|
-
previousUrl = window.location.href;
|
2296
|
-
pageId = generatePageId();
|
2297
|
-
client.pageHit({
|
2298
|
-
visitorId: storageData.visitorId,
|
2299
|
-
sessionId: storageData.sessionId,
|
2300
|
-
pageId
|
2301
|
-
});
|
2302
|
-
},
|
2303
|
-
testResult: (result) => {
|
2304
|
-
if (!storageData) {
|
2305
|
-
console.error("Insights not initialized");
|
2306
|
-
return;
|
2307
|
-
}
|
2308
|
-
client.testResult({
|
2309
|
-
...result,
|
2310
|
-
visitorId: storageData.visitorId,
|
2311
|
-
sessionId: storageData.sessionId,
|
2312
|
-
pageId
|
2313
|
-
});
|
2314
|
-
},
|
2315
|
-
personalizationResult: (result) => {
|
2316
|
-
if (!storageData) {
|
2317
|
-
console.error("Insights not initialized");
|
2318
|
-
return;
|
2319
|
-
}
|
2320
|
-
client.personalizationResult({
|
2321
|
-
...result,
|
2322
|
-
visitorId: storageData.visitorId,
|
2323
|
-
sessionId: storageData.sessionId,
|
2324
|
-
pageId
|
2325
|
-
});
|
2326
|
-
},
|
2327
|
-
goalConvert: (goalId) => {
|
2328
|
-
if (!storageData) {
|
2329
|
-
console.error("Insights not initialized");
|
2330
|
-
return;
|
2331
|
-
}
|
2332
|
-
client.goalConvert({
|
2333
|
-
visitorId: storageData.visitorId,
|
2334
|
-
sessionId: storageData.sessionId,
|
2335
|
-
goalId,
|
2336
|
-
pageId
|
2337
|
-
});
|
2338
|
-
},
|
2339
|
-
scoresChange: (scores) => {
|
2340
|
-
if (!storageData) {
|
2341
|
-
console.error("Insights not initialized");
|
2342
|
-
return;
|
2343
|
-
}
|
2344
|
-
client.scoresChange({
|
2345
|
-
visitorId: storageData.visitorId,
|
2346
|
-
sessionId: storageData.sessionId,
|
2347
|
-
scores,
|
2348
|
-
pageId
|
2349
|
-
});
|
2350
|
-
},
|
2351
|
-
forget: () => {
|
2352
|
-
storage.clear();
|
2353
|
-
storageData = void 0;
|
2354
|
-
},
|
2355
|
-
get sessionId() {
|
2356
|
-
return storageData == null ? void 0 : storageData.sessionId;
|
2357
|
-
}
|
2358
|
-
};
|
2359
|
-
};
|
2360
|
-
var enableUniformInsights = (options) => {
|
2361
|
-
const insights = createInsights({
|
2362
|
-
endpoint: options.endpoint
|
2363
|
-
});
|
2364
|
-
let previousUrl = void 0;
|
2365
|
-
return {
|
2366
|
-
init: (context) => {
|
2367
|
-
if (typeof window === "undefined") {
|
2368
|
-
return () => {
|
2369
|
-
};
|
2370
|
-
}
|
2371
|
-
const consentChanged = () => {
|
2372
|
-
if (context.storage.data.consent) {
|
2373
|
-
insights.init();
|
2374
|
-
} else {
|
2375
|
-
insights.forget();
|
2376
|
-
}
|
2377
|
-
};
|
2378
|
-
const handlePersonalizationResult = (data) => {
|
2379
|
-
insights.personalizationResult(data);
|
2380
|
-
};
|
2381
|
-
const handleTestResult = (result) => {
|
2382
|
-
insights.testResult(result);
|
2383
|
-
};
|
2384
|
-
const handleGoalConvert = (result) => {
|
2385
|
-
insights.goalConvert(result.goalId);
|
2386
|
-
};
|
2387
|
-
const handleScoreChange = (scores) => {
|
2388
|
-
insights.scoresChange(scores);
|
2389
|
-
};
|
2390
|
-
context.storage.events.on("goalConverted", handleGoalConvert);
|
2391
|
-
context.storage.events.on("consentUpdated", consentChanged);
|
2392
|
-
context.events.on("personalizationResult", handlePersonalizationResult);
|
2393
|
-
context.events.on("testResult", handleTestResult);
|
2394
|
-
context.events.on("scoresUpdated", handleScoreChange);
|
2395
|
-
if (context.storage.data.consent) {
|
2396
|
-
consentChanged();
|
2397
|
-
}
|
2398
|
-
return () => {
|
2399
|
-
context.storage.events.off("consentUpdated", consentChanged);
|
2400
|
-
context.storage.events.off("goalConverted", handleGoalConvert);
|
2401
|
-
context.events.off("personalizationResult", handlePersonalizationResult);
|
2402
|
-
context.events.off("testResult", handleTestResult);
|
2403
|
-
context.events.off("scoresUpdated", handleScoreChange);
|
2404
|
-
};
|
2405
|
-
},
|
2406
|
-
update: (context) => {
|
2407
|
-
if (context.url && context.url !== previousUrl) {
|
2408
|
-
previousUrl = context.url;
|
2409
|
-
insights.pageHit();
|
2410
|
-
}
|
2411
|
-
},
|
2412
|
-
forget: () => {
|
2413
|
-
insights.forget();
|
2414
|
-
}
|
2415
|
-
};
|
2416
|
-
};
|
2417
|
-
var generalRandomId = () => {
|
2418
|
-
const id = (0, import_uuid.v4)();
|
2419
|
-
return id.replaceAll("-", "").toLowerCase();
|
2420
|
-
};
|
2421
|
-
|
2422
1982
|
// src/logging/enableConsoleLogDrain.ts
|
2423
1983
|
var import_rfdc2 = __toESM(require("rfdc"));
|
2424
1984
|
|
@@ -2623,7 +2183,6 @@ function parseQuickConnect(serialized) {
|
|
2623
2183
|
enableConsoleLogDrain,
|
2624
2184
|
enableContextDevTools,
|
2625
2185
|
enableDebugConsoleLogDrain,
|
2626
|
-
enableUniformInsights,
|
2627
2186
|
evaluateVariantMatch,
|
2628
2187
|
eventEvaluator,
|
2629
2188
|
explainStringMatch,
|