@uniformdev/context 20.80.1-alpha.3.sha-1a5ce5809e → 20.80.2-alpha.14.sha-1c81418f05
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -21
- package/dist/index.d.ts +1 -21
- package/dist/index.esm.js +0 -356
- package/dist/index.js +0 -357
- package/dist/index.mjs +0 -356
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -217,26 +217,6 @@ type EdgeTestComponentOptions = {
|
|
|
217
217
|
};
|
|
218
218
|
declare const EdgeNodeTagName = "nesitag";
|
|
219
219
|
|
|
220
|
-
type InsightsEndpoint = {
|
|
221
|
-
type: 'api';
|
|
222
|
-
host: string;
|
|
223
|
-
apiKey: string;
|
|
224
|
-
projectId: string;
|
|
225
|
-
} | {
|
|
226
|
-
type: 'proxy';
|
|
227
|
-
path: string;
|
|
228
|
-
apiKey?: string;
|
|
229
|
-
projectId?: string;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
type EnableUniformInsightsOptions = {
|
|
233
|
-
endpoint: InsightsEndpoint;
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* @deprecated Use `import { enableUniformInsights } from '@uniformdev/insights'` instead
|
|
237
|
-
*/
|
|
238
|
-
declare const enableUniformInsights: (options: EnableUniformInsightsOptions) => ContextPlugin;
|
|
239
|
-
|
|
240
220
|
type QuickConnectConfig = {
|
|
241
221
|
apiKey: string;
|
|
242
222
|
projectId: string;
|
|
@@ -245,4 +225,4 @@ type QuickConnectConfig = {
|
|
|
245
225
|
declare function serializeQuickConnect(config: QuickConnectConfig): string;
|
|
246
226
|
declare function parseQuickConnect(serialized: string): Required<QuickConnectConfig>;
|
|
247
227
|
|
|
248
|
-
export { AggregateDimension, type ConsoleDebugLogDrainOptions, Context, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions,
|
|
228
|
+
export { AggregateDimension, type ConsoleDebugLogDrainOptions, Context, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, PersonalizationSelectionAlgorithmOptions, PersonalizeOptions, PersonalizedResult, PersonalizedVariant, QUIRK_SEP, type QuickConnectConfig, Quirks, STRONGEST_SCORE_PERSONALIZATION_ALGORITHM, ScoreVector, ScriptType, StorageCommands, StringMatch, TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VariationMatchDimensionCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, personalizeVariations, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks, strongestScorePersonalizationSelectionAlgorithm, topDownCriteriaPersonalizationSelectionAlgorithm };
|
package/dist/index.d.ts
CHANGED
|
@@ -217,26 +217,6 @@ type EdgeTestComponentOptions = {
|
|
|
217
217
|
};
|
|
218
218
|
declare const EdgeNodeTagName = "nesitag";
|
|
219
219
|
|
|
220
|
-
type InsightsEndpoint = {
|
|
221
|
-
type: 'api';
|
|
222
|
-
host: string;
|
|
223
|
-
apiKey: string;
|
|
224
|
-
projectId: string;
|
|
225
|
-
} | {
|
|
226
|
-
type: 'proxy';
|
|
227
|
-
path: string;
|
|
228
|
-
apiKey?: string;
|
|
229
|
-
projectId?: string;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
type EnableUniformInsightsOptions = {
|
|
233
|
-
endpoint: InsightsEndpoint;
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* @deprecated Use `import { enableUniformInsights } from '@uniformdev/insights'` instead
|
|
237
|
-
*/
|
|
238
|
-
declare const enableUniformInsights: (options: EnableUniformInsightsOptions) => ContextPlugin;
|
|
239
|
-
|
|
240
220
|
type QuickConnectConfig = {
|
|
241
221
|
apiKey: string;
|
|
242
222
|
projectId: string;
|
|
@@ -245,4 +225,4 @@ type QuickConnectConfig = {
|
|
|
245
225
|
declare function serializeQuickConnect(config: QuickConnectConfig): string;
|
|
246
226
|
declare function parseQuickConnect(serialized: string): Required<QuickConnectConfig>;
|
|
247
227
|
|
|
248
|
-
export { AggregateDimension, type ConsoleDebugLogDrainOptions, Context, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions,
|
|
228
|
+
export { AggregateDimension, type ConsoleDebugLogDrainOptions, Context, type ContextDevToolOptions, ContextPlugin, CookieTransitionDataStore, type CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DevToolsEvents, ENR_SEPARATOR, EdgeNodeTagName, type EdgePersonalizeComponentOptions, type EdgeTestComponentOptions, EdgeTransitionDataStore, type EdgeTransitionDataStoreOptions, KV_SEP, type LinearDecayOptions, LogDrain, LogMessage, OutputSeverity, PAIR_SEP, PersonalizationSelectionAlgorithmOptions, PersonalizeOptions, PersonalizedResult, PersonalizedVariant, QUIRK_SEP, type QuickConnectConfig, Quirks, STRONGEST_SCORE_PERSONALIZATION_ALGORITHM, ScoreVector, ScriptType, StorageCommands, StringMatch, TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM, TYPE_SEP, TransitionDataStore, TransitionDataStoreOptions, UNIFORM_DEFAULT_COOKIE_NAME, UNIFORM_DEFAULT_QUIRK_COOKIE_NAME, VariantMatchCriteria, VariationMatchDimensionCriteria, VisitorData, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, currentPageEvaluator, decodeCookieType, decodePersonalizeVariants, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, encodeCookieType, evaluateVariantMatch, eventEvaluator, explainStringMatch, explainStringMatchCriteria, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, parseCookieScores, parseCookieType, parseQuickConnect, parseQuirkCookie, parseScoreCookie, personalizeVariations, queryStringEvaluator, quirkEvaluator, serializeCookie, serializeCookieType, serializePersonalizeVariants, serializeQuickConnect, serializeQuirks, strongestScorePersonalizationSelectionAlgorithm, topDownCriteriaPersonalizationSelectionAlgorithm };
|
package/dist/index.esm.js
CHANGED
|
@@ -2316,361 +2316,6 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
|
|
|
2316
2316
|
})(ScriptType || {});
|
|
2317
2317
|
var EdgeNodeTagName = "nesitag";
|
|
2318
2318
|
|
|
2319
|
-
// src/insights/storage.ts
|
|
2320
|
-
var createInsightsStorage = () => {
|
|
2321
|
-
const STORAGE_KEY2 = "ufin";
|
|
2322
|
-
return {
|
|
2323
|
-
get: () => {
|
|
2324
|
-
const data = localStorage.getItem(STORAGE_KEY2);
|
|
2325
|
-
if (!data) {
|
|
2326
|
-
return;
|
|
2327
|
-
}
|
|
2328
|
-
return JSON.parse(data);
|
|
2329
|
-
},
|
|
2330
|
-
set: (data) => {
|
|
2331
|
-
const toSet = {
|
|
2332
|
-
...data,
|
|
2333
|
-
updated: Date.now()
|
|
2334
|
-
};
|
|
2335
|
-
localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
|
|
2336
|
-
},
|
|
2337
|
-
clear: () => {
|
|
2338
|
-
localStorage.removeItem(STORAGE_KEY2);
|
|
2339
|
-
}
|
|
2340
|
-
};
|
|
2341
|
-
};
|
|
2342
|
-
|
|
2343
|
-
// src/insights/types.ts
|
|
2344
|
-
var getBasePayload = () => {
|
|
2345
|
-
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2346
|
-
const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
|
|
2347
|
-
return {
|
|
2348
|
-
"user-agent": window.navigator.userAgent,
|
|
2349
|
-
locale,
|
|
2350
|
-
location: timeZone,
|
|
2351
|
-
referrer: document.referrer,
|
|
2352
|
-
pathname: window.location.pathname,
|
|
2353
|
-
href: window.location.href
|
|
2354
|
-
};
|
|
2355
|
-
};
|
|
2356
|
-
var generateVisitorId = () => {
|
|
2357
|
-
return `visitor_${generalRandomId()}`;
|
|
2358
|
-
};
|
|
2359
|
-
var generateSessionId = () => {
|
|
2360
|
-
return `session_${generalRandomId()}`;
|
|
2361
|
-
};
|
|
2362
|
-
var generatePageId = () => {
|
|
2363
|
-
return `page_${generalRandomId()}`;
|
|
2364
|
-
};
|
|
2365
|
-
var generalRandomId = () => {
|
|
2366
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
2367
|
-
const id = crypto.randomUUID();
|
|
2368
|
-
return id.replaceAll("-", "").toLowerCase();
|
|
2369
|
-
}
|
|
2370
|
-
return Math.random().toString(32).substring(2);
|
|
2371
|
-
};
|
|
2372
|
-
|
|
2373
|
-
// src/insights/v1.ts
|
|
2374
|
-
var createInsightsClient = ({ endpoint }) => {
|
|
2375
|
-
let endpointUrl;
|
|
2376
|
-
const apiKey = endpoint.apiKey;
|
|
2377
|
-
const projectId = endpoint.projectId;
|
|
2378
|
-
if (endpoint.type === "api") {
|
|
2379
|
-
const url = new URL(endpoint.host);
|
|
2380
|
-
url.pathname = `/v0/events`;
|
|
2381
|
-
if (endpoint.host.includes("tinybird.co")) {
|
|
2382
|
-
url.pathname = "/v0/events";
|
|
2383
|
-
}
|
|
2384
|
-
url.searchParams.set("name", "analytics_events");
|
|
2385
|
-
endpointUrl = url.toString();
|
|
2386
|
-
} else {
|
|
2387
|
-
endpointUrl = endpoint.path;
|
|
2388
|
-
}
|
|
2389
|
-
const sendMessage = async (message) => {
|
|
2390
|
-
if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
|
|
2391
|
-
return;
|
|
2392
|
-
}
|
|
2393
|
-
const converted = {
|
|
2394
|
-
...message,
|
|
2395
|
-
payload: JSON.stringify(message.payload)
|
|
2396
|
-
};
|
|
2397
|
-
const headers = {
|
|
2398
|
-
"Content-Type": "application/json"
|
|
2399
|
-
};
|
|
2400
|
-
if (apiKey) {
|
|
2401
|
-
headers.Authorization = `Bearer ${apiKey}`;
|
|
2402
|
-
}
|
|
2403
|
-
const response = await fetch(endpointUrl, {
|
|
2404
|
-
method: "POST",
|
|
2405
|
-
headers,
|
|
2406
|
-
body: JSON.stringify(converted)
|
|
2407
|
-
});
|
|
2408
|
-
const json = await response.json();
|
|
2409
|
-
return json;
|
|
2410
|
-
};
|
|
2411
|
-
return {
|
|
2412
|
-
sessionStart: (options) => {
|
|
2413
|
-
const message = {
|
|
2414
|
-
action: "session_start",
|
|
2415
|
-
version: "1",
|
|
2416
|
-
session_id: options.sessionId,
|
|
2417
|
-
visitor_id: options.visitorId,
|
|
2418
|
-
page_view_id: options.pageId,
|
|
2419
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2420
|
-
project_id: projectId,
|
|
2421
|
-
payload: {
|
|
2422
|
-
...getBasePayload(),
|
|
2423
|
-
previous_session_id: options.previousSessionId
|
|
2424
|
-
}
|
|
2425
|
-
};
|
|
2426
|
-
return sendMessage(message);
|
|
2427
|
-
},
|
|
2428
|
-
pageHit: (options) => {
|
|
2429
|
-
const message = {
|
|
2430
|
-
action: "page_hit",
|
|
2431
|
-
version: "1",
|
|
2432
|
-
session_id: options.sessionId,
|
|
2433
|
-
visitor_id: options.visitorId,
|
|
2434
|
-
page_view_id: options.pageId,
|
|
2435
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2436
|
-
project_id: projectId,
|
|
2437
|
-
payload: getBasePayload()
|
|
2438
|
-
};
|
|
2439
|
-
return sendMessage(message);
|
|
2440
|
-
},
|
|
2441
|
-
testResult: async (options) => {
|
|
2442
|
-
const message = {
|
|
2443
|
-
action: "test_result",
|
|
2444
|
-
version: "1",
|
|
2445
|
-
session_id: options.sessionId,
|
|
2446
|
-
visitor_id: options.visitorId,
|
|
2447
|
-
page_view_id: options.pageId,
|
|
2448
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2449
|
-
project_id: projectId,
|
|
2450
|
-
payload: {
|
|
2451
|
-
...getBasePayload(),
|
|
2452
|
-
...options
|
|
2453
|
-
}
|
|
2454
|
-
};
|
|
2455
|
-
return sendMessage(message);
|
|
2456
|
-
},
|
|
2457
|
-
personalizationResult: async (options) => {
|
|
2458
|
-
const messages = options.variantIds.map((variant) => {
|
|
2459
|
-
const message = {
|
|
2460
|
-
action: "personalization_result",
|
|
2461
|
-
version: "1",
|
|
2462
|
-
session_id: options.sessionId,
|
|
2463
|
-
visitor_id: options.visitorId,
|
|
2464
|
-
page_view_id: options.pageId,
|
|
2465
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2466
|
-
project_id: projectId,
|
|
2467
|
-
payload: {
|
|
2468
|
-
...getBasePayload(),
|
|
2469
|
-
name: options.name,
|
|
2470
|
-
variantId: variant.id,
|
|
2471
|
-
control: variant.control || options.control,
|
|
2472
|
-
changed: options.changed
|
|
2473
|
-
}
|
|
2474
|
-
};
|
|
2475
|
-
return message;
|
|
2476
|
-
});
|
|
2477
|
-
await Promise.all(messages.map((message) => sendMessage(message)));
|
|
2478
|
-
},
|
|
2479
|
-
goalConvert: (options) => {
|
|
2480
|
-
const message = {
|
|
2481
|
-
action: "goal_convert",
|
|
2482
|
-
version: "1",
|
|
2483
|
-
session_id: options.sessionId,
|
|
2484
|
-
visitor_id: options.visitorId,
|
|
2485
|
-
page_view_id: options.pageId,
|
|
2486
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2487
|
-
project_id: projectId,
|
|
2488
|
-
payload: {
|
|
2489
|
-
...getBasePayload(),
|
|
2490
|
-
goalId: options.goalId
|
|
2491
|
-
}
|
|
2492
|
-
};
|
|
2493
|
-
return sendMessage(message);
|
|
2494
|
-
},
|
|
2495
|
-
scoresChange: async (options) => {
|
|
2496
|
-
const message = {
|
|
2497
|
-
action: "scores_change",
|
|
2498
|
-
version: "1",
|
|
2499
|
-
session_id: options.sessionId,
|
|
2500
|
-
visitor_id: options.visitorId,
|
|
2501
|
-
page_view_id: options.pageId,
|
|
2502
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2503
|
-
project_id: projectId,
|
|
2504
|
-
payload: {
|
|
2505
|
-
...getBasePayload(),
|
|
2506
|
-
scores: options.scores
|
|
2507
|
-
}
|
|
2508
|
-
};
|
|
2509
|
-
return sendMessage(message);
|
|
2510
|
-
}
|
|
2511
|
-
};
|
|
2512
|
-
};
|
|
2513
|
-
var createInsightsV1 = ({
|
|
2514
|
-
endpoint,
|
|
2515
|
-
sessionDurationSeconds = 30 * 60
|
|
2516
|
-
}) => {
|
|
2517
|
-
const client = createInsightsClient({
|
|
2518
|
-
endpoint
|
|
2519
|
-
});
|
|
2520
|
-
const storage = createInsightsStorage();
|
|
2521
|
-
let storageData = void 0;
|
|
2522
|
-
let pageId = generatePageId();
|
|
2523
|
-
let previousUrl = void 0;
|
|
2524
|
-
return {
|
|
2525
|
-
init: () => {
|
|
2526
|
-
storageData = storage.get();
|
|
2527
|
-
if (!storageData || Date.now() - storageData.updated > sessionDurationSeconds * 1e3) {
|
|
2528
|
-
const previousSessionId = storageData == null ? void 0 : storageData.sessionId;
|
|
2529
|
-
storageData = {
|
|
2530
|
-
visitorId: (storageData == null ? void 0 : storageData.visitorId) || generateVisitorId(),
|
|
2531
|
-
sessionId: generateSessionId(),
|
|
2532
|
-
updated: Date.now()
|
|
2533
|
-
};
|
|
2534
|
-
storage.set(storageData);
|
|
2535
|
-
client.sessionStart({
|
|
2536
|
-
visitorId: storageData.visitorId,
|
|
2537
|
-
sessionId: storageData.sessionId,
|
|
2538
|
-
previousSessionId,
|
|
2539
|
-
maxAgeSeconds: sessionDurationSeconds,
|
|
2540
|
-
pageId
|
|
2541
|
-
});
|
|
2542
|
-
} else if (storageData) {
|
|
2543
|
-
storage.set(storageData);
|
|
2544
|
-
}
|
|
2545
|
-
},
|
|
2546
|
-
pageHit: () => {
|
|
2547
|
-
if (!storageData) {
|
|
2548
|
-
return;
|
|
2549
|
-
}
|
|
2550
|
-
if (previousUrl === window.location.href) {
|
|
2551
|
-
return;
|
|
2552
|
-
}
|
|
2553
|
-
previousUrl = window.location.href;
|
|
2554
|
-
pageId = generatePageId();
|
|
2555
|
-
client.pageHit({
|
|
2556
|
-
visitorId: storageData.visitorId,
|
|
2557
|
-
sessionId: storageData.sessionId,
|
|
2558
|
-
pageId
|
|
2559
|
-
});
|
|
2560
|
-
},
|
|
2561
|
-
testResult: (result) => {
|
|
2562
|
-
if (!storageData) {
|
|
2563
|
-
return;
|
|
2564
|
-
}
|
|
2565
|
-
client.testResult({
|
|
2566
|
-
...result,
|
|
2567
|
-
visitorId: storageData.visitorId,
|
|
2568
|
-
sessionId: storageData.sessionId,
|
|
2569
|
-
pageId
|
|
2570
|
-
});
|
|
2571
|
-
},
|
|
2572
|
-
personalizationResult: (result) => {
|
|
2573
|
-
if (!storageData) {
|
|
2574
|
-
return;
|
|
2575
|
-
}
|
|
2576
|
-
client.personalizationResult({
|
|
2577
|
-
...result,
|
|
2578
|
-
visitorId: storageData.visitorId,
|
|
2579
|
-
sessionId: storageData.sessionId,
|
|
2580
|
-
pageId
|
|
2581
|
-
});
|
|
2582
|
-
},
|
|
2583
|
-
goalConvert: (goalId) => {
|
|
2584
|
-
if (!storageData) {
|
|
2585
|
-
return;
|
|
2586
|
-
}
|
|
2587
|
-
client.goalConvert({
|
|
2588
|
-
visitorId: storageData.visitorId,
|
|
2589
|
-
sessionId: storageData.sessionId,
|
|
2590
|
-
goalId,
|
|
2591
|
-
pageId
|
|
2592
|
-
});
|
|
2593
|
-
},
|
|
2594
|
-
scoresChange: (scores) => {
|
|
2595
|
-
if (!storageData) {
|
|
2596
|
-
return;
|
|
2597
|
-
}
|
|
2598
|
-
client.scoresChange({
|
|
2599
|
-
visitorId: storageData.visitorId,
|
|
2600
|
-
sessionId: storageData.sessionId,
|
|
2601
|
-
scores,
|
|
2602
|
-
pageId
|
|
2603
|
-
});
|
|
2604
|
-
},
|
|
2605
|
-
forget: () => {
|
|
2606
|
-
storage.clear();
|
|
2607
|
-
storageData = void 0;
|
|
2608
|
-
},
|
|
2609
|
-
get sessionId() {
|
|
2610
|
-
return storageData == null ? void 0 : storageData.sessionId;
|
|
2611
|
-
}
|
|
2612
|
-
};
|
|
2613
|
-
};
|
|
2614
|
-
|
|
2615
|
-
// src/insights/index.ts
|
|
2616
|
-
var enableUniformInsights = (options) => {
|
|
2617
|
-
const insights = createInsightsV1({
|
|
2618
|
-
endpoint: options.endpoint
|
|
2619
|
-
});
|
|
2620
|
-
let previousUrl = void 0;
|
|
2621
|
-
return {
|
|
2622
|
-
init: (context) => {
|
|
2623
|
-
if (typeof window === "undefined") {
|
|
2624
|
-
return () => {
|
|
2625
|
-
};
|
|
2626
|
-
}
|
|
2627
|
-
const consentChanged = () => {
|
|
2628
|
-
if (context.storage.data.consent) {
|
|
2629
|
-
insights.init();
|
|
2630
|
-
} else {
|
|
2631
|
-
insights.forget();
|
|
2632
|
-
}
|
|
2633
|
-
};
|
|
2634
|
-
const handlePersonalizationResult = (data) => {
|
|
2635
|
-
insights.personalizationResult(data);
|
|
2636
|
-
};
|
|
2637
|
-
const handleTestResult = (result) => {
|
|
2638
|
-
insights.testResult(result);
|
|
2639
|
-
};
|
|
2640
|
-
const handleGoalConvert = (result) => {
|
|
2641
|
-
insights.goalConvert(result.goalId);
|
|
2642
|
-
};
|
|
2643
|
-
const handleScoreChange = (scores) => {
|
|
2644
|
-
insights.scoresChange(scores);
|
|
2645
|
-
};
|
|
2646
|
-
context.storage.events.on("goalConverted", handleGoalConvert);
|
|
2647
|
-
context.storage.events.on("consentUpdated", consentChanged);
|
|
2648
|
-
context.events.on("personalizationResult", handlePersonalizationResult);
|
|
2649
|
-
context.events.on("testResult", handleTestResult);
|
|
2650
|
-
context.events.on("scoresUpdated", handleScoreChange);
|
|
2651
|
-
if (context.storage.data.consent) {
|
|
2652
|
-
consentChanged();
|
|
2653
|
-
}
|
|
2654
|
-
return () => {
|
|
2655
|
-
context.storage.events.off("consentUpdated", consentChanged);
|
|
2656
|
-
context.storage.events.off("goalConverted", handleGoalConvert);
|
|
2657
|
-
context.events.off("personalizationResult", handlePersonalizationResult);
|
|
2658
|
-
context.events.off("testResult", handleTestResult);
|
|
2659
|
-
context.events.off("scoresUpdated", handleScoreChange);
|
|
2660
|
-
};
|
|
2661
|
-
},
|
|
2662
|
-
update: (context) => {
|
|
2663
|
-
if (context.url && context.url.toString() !== previousUrl) {
|
|
2664
|
-
previousUrl = context.url.toString();
|
|
2665
|
-
insights.pageHit();
|
|
2666
|
-
}
|
|
2667
|
-
},
|
|
2668
|
-
forget: () => {
|
|
2669
|
-
insights.forget();
|
|
2670
|
-
}
|
|
2671
|
-
};
|
|
2672
|
-
};
|
|
2673
|
-
|
|
2674
2319
|
// src/logging/enableConsoleLogDrain.ts
|
|
2675
2320
|
import rfdc2 from "rfdc";
|
|
2676
2321
|
|
|
@@ -2889,7 +2534,6 @@ export {
|
|
|
2889
2534
|
enableConsoleLogDrain,
|
|
2890
2535
|
enableContextDevTools,
|
|
2891
2536
|
enableDebugConsoleLogDrain,
|
|
2892
|
-
enableUniformInsights,
|
|
2893
2537
|
encodeCookieType,
|
|
2894
2538
|
evaluateVariantMatch,
|
|
2895
2539
|
eventEvaluator,
|
package/dist/index.js
CHANGED
|
@@ -74,7 +74,6 @@ __export(index_exports, {
|
|
|
74
74
|
enableConsoleLogDrain: () => enableConsoleLogDrain,
|
|
75
75
|
enableContextDevTools: () => enableContextDevTools,
|
|
76
76
|
enableDebugConsoleLogDrain: () => enableDebugConsoleLogDrain,
|
|
77
|
-
enableUniformInsights: () => enableUniformInsights,
|
|
78
77
|
encodeCookieType: () => encodeCookieType,
|
|
79
78
|
evaluateVariantMatch: () => evaluateVariantMatch,
|
|
80
79
|
eventEvaluator: () => eventEvaluator,
|
|
@@ -2409,361 +2408,6 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
|
|
|
2409
2408
|
})(ScriptType || {});
|
|
2410
2409
|
var EdgeNodeTagName = "nesitag";
|
|
2411
2410
|
|
|
2412
|
-
// src/insights/storage.ts
|
|
2413
|
-
var createInsightsStorage = () => {
|
|
2414
|
-
const STORAGE_KEY2 = "ufin";
|
|
2415
|
-
return {
|
|
2416
|
-
get: () => {
|
|
2417
|
-
const data = localStorage.getItem(STORAGE_KEY2);
|
|
2418
|
-
if (!data) {
|
|
2419
|
-
return;
|
|
2420
|
-
}
|
|
2421
|
-
return JSON.parse(data);
|
|
2422
|
-
},
|
|
2423
|
-
set: (data) => {
|
|
2424
|
-
const toSet = {
|
|
2425
|
-
...data,
|
|
2426
|
-
updated: Date.now()
|
|
2427
|
-
};
|
|
2428
|
-
localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
|
|
2429
|
-
},
|
|
2430
|
-
clear: () => {
|
|
2431
|
-
localStorage.removeItem(STORAGE_KEY2);
|
|
2432
|
-
}
|
|
2433
|
-
};
|
|
2434
|
-
};
|
|
2435
|
-
|
|
2436
|
-
// src/insights/types.ts
|
|
2437
|
-
var getBasePayload = () => {
|
|
2438
|
-
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2439
|
-
const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
|
|
2440
|
-
return {
|
|
2441
|
-
"user-agent": window.navigator.userAgent,
|
|
2442
|
-
locale,
|
|
2443
|
-
location: timeZone,
|
|
2444
|
-
referrer: document.referrer,
|
|
2445
|
-
pathname: window.location.pathname,
|
|
2446
|
-
href: window.location.href
|
|
2447
|
-
};
|
|
2448
|
-
};
|
|
2449
|
-
var generateVisitorId = () => {
|
|
2450
|
-
return `visitor_${generalRandomId()}`;
|
|
2451
|
-
};
|
|
2452
|
-
var generateSessionId = () => {
|
|
2453
|
-
return `session_${generalRandomId()}`;
|
|
2454
|
-
};
|
|
2455
|
-
var generatePageId = () => {
|
|
2456
|
-
return `page_${generalRandomId()}`;
|
|
2457
|
-
};
|
|
2458
|
-
var generalRandomId = () => {
|
|
2459
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
2460
|
-
const id = crypto.randomUUID();
|
|
2461
|
-
return id.replaceAll("-", "").toLowerCase();
|
|
2462
|
-
}
|
|
2463
|
-
return Math.random().toString(32).substring(2);
|
|
2464
|
-
};
|
|
2465
|
-
|
|
2466
|
-
// src/insights/v1.ts
|
|
2467
|
-
var createInsightsClient = ({ endpoint }) => {
|
|
2468
|
-
let endpointUrl;
|
|
2469
|
-
const apiKey = endpoint.apiKey;
|
|
2470
|
-
const projectId = endpoint.projectId;
|
|
2471
|
-
if (endpoint.type === "api") {
|
|
2472
|
-
const url = new URL(endpoint.host);
|
|
2473
|
-
url.pathname = `/v0/events`;
|
|
2474
|
-
if (endpoint.host.includes("tinybird.co")) {
|
|
2475
|
-
url.pathname = "/v0/events";
|
|
2476
|
-
}
|
|
2477
|
-
url.searchParams.set("name", "analytics_events");
|
|
2478
|
-
endpointUrl = url.toString();
|
|
2479
|
-
} else {
|
|
2480
|
-
endpointUrl = endpoint.path;
|
|
2481
|
-
}
|
|
2482
|
-
const sendMessage = async (message) => {
|
|
2483
|
-
if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
|
|
2484
|
-
return;
|
|
2485
|
-
}
|
|
2486
|
-
const converted = {
|
|
2487
|
-
...message,
|
|
2488
|
-
payload: JSON.stringify(message.payload)
|
|
2489
|
-
};
|
|
2490
|
-
const headers = {
|
|
2491
|
-
"Content-Type": "application/json"
|
|
2492
|
-
};
|
|
2493
|
-
if (apiKey) {
|
|
2494
|
-
headers.Authorization = `Bearer ${apiKey}`;
|
|
2495
|
-
}
|
|
2496
|
-
const response = await fetch(endpointUrl, {
|
|
2497
|
-
method: "POST",
|
|
2498
|
-
headers,
|
|
2499
|
-
body: JSON.stringify(converted)
|
|
2500
|
-
});
|
|
2501
|
-
const json = await response.json();
|
|
2502
|
-
return json;
|
|
2503
|
-
};
|
|
2504
|
-
return {
|
|
2505
|
-
sessionStart: (options) => {
|
|
2506
|
-
const message = {
|
|
2507
|
-
action: "session_start",
|
|
2508
|
-
version: "1",
|
|
2509
|
-
session_id: options.sessionId,
|
|
2510
|
-
visitor_id: options.visitorId,
|
|
2511
|
-
page_view_id: options.pageId,
|
|
2512
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2513
|
-
project_id: projectId,
|
|
2514
|
-
payload: {
|
|
2515
|
-
...getBasePayload(),
|
|
2516
|
-
previous_session_id: options.previousSessionId
|
|
2517
|
-
}
|
|
2518
|
-
};
|
|
2519
|
-
return sendMessage(message);
|
|
2520
|
-
},
|
|
2521
|
-
pageHit: (options) => {
|
|
2522
|
-
const message = {
|
|
2523
|
-
action: "page_hit",
|
|
2524
|
-
version: "1",
|
|
2525
|
-
session_id: options.sessionId,
|
|
2526
|
-
visitor_id: options.visitorId,
|
|
2527
|
-
page_view_id: options.pageId,
|
|
2528
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2529
|
-
project_id: projectId,
|
|
2530
|
-
payload: getBasePayload()
|
|
2531
|
-
};
|
|
2532
|
-
return sendMessage(message);
|
|
2533
|
-
},
|
|
2534
|
-
testResult: async (options) => {
|
|
2535
|
-
const message = {
|
|
2536
|
-
action: "test_result",
|
|
2537
|
-
version: "1",
|
|
2538
|
-
session_id: options.sessionId,
|
|
2539
|
-
visitor_id: options.visitorId,
|
|
2540
|
-
page_view_id: options.pageId,
|
|
2541
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2542
|
-
project_id: projectId,
|
|
2543
|
-
payload: {
|
|
2544
|
-
...getBasePayload(),
|
|
2545
|
-
...options
|
|
2546
|
-
}
|
|
2547
|
-
};
|
|
2548
|
-
return sendMessage(message);
|
|
2549
|
-
},
|
|
2550
|
-
personalizationResult: async (options) => {
|
|
2551
|
-
const messages = options.variantIds.map((variant) => {
|
|
2552
|
-
const message = {
|
|
2553
|
-
action: "personalization_result",
|
|
2554
|
-
version: "1",
|
|
2555
|
-
session_id: options.sessionId,
|
|
2556
|
-
visitor_id: options.visitorId,
|
|
2557
|
-
page_view_id: options.pageId,
|
|
2558
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2559
|
-
project_id: projectId,
|
|
2560
|
-
payload: {
|
|
2561
|
-
...getBasePayload(),
|
|
2562
|
-
name: options.name,
|
|
2563
|
-
variantId: variant.id,
|
|
2564
|
-
control: variant.control || options.control,
|
|
2565
|
-
changed: options.changed
|
|
2566
|
-
}
|
|
2567
|
-
};
|
|
2568
|
-
return message;
|
|
2569
|
-
});
|
|
2570
|
-
await Promise.all(messages.map((message) => sendMessage(message)));
|
|
2571
|
-
},
|
|
2572
|
-
goalConvert: (options) => {
|
|
2573
|
-
const message = {
|
|
2574
|
-
action: "goal_convert",
|
|
2575
|
-
version: "1",
|
|
2576
|
-
session_id: options.sessionId,
|
|
2577
|
-
visitor_id: options.visitorId,
|
|
2578
|
-
page_view_id: options.pageId,
|
|
2579
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2580
|
-
project_id: projectId,
|
|
2581
|
-
payload: {
|
|
2582
|
-
...getBasePayload(),
|
|
2583
|
-
goalId: options.goalId
|
|
2584
|
-
}
|
|
2585
|
-
};
|
|
2586
|
-
return sendMessage(message);
|
|
2587
|
-
},
|
|
2588
|
-
scoresChange: async (options) => {
|
|
2589
|
-
const message = {
|
|
2590
|
-
action: "scores_change",
|
|
2591
|
-
version: "1",
|
|
2592
|
-
session_id: options.sessionId,
|
|
2593
|
-
visitor_id: options.visitorId,
|
|
2594
|
-
page_view_id: options.pageId,
|
|
2595
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2596
|
-
project_id: projectId,
|
|
2597
|
-
payload: {
|
|
2598
|
-
...getBasePayload(),
|
|
2599
|
-
scores: options.scores
|
|
2600
|
-
}
|
|
2601
|
-
};
|
|
2602
|
-
return sendMessage(message);
|
|
2603
|
-
}
|
|
2604
|
-
};
|
|
2605
|
-
};
|
|
2606
|
-
var createInsightsV1 = ({
|
|
2607
|
-
endpoint,
|
|
2608
|
-
sessionDurationSeconds = 30 * 60
|
|
2609
|
-
}) => {
|
|
2610
|
-
const client = createInsightsClient({
|
|
2611
|
-
endpoint
|
|
2612
|
-
});
|
|
2613
|
-
const storage = createInsightsStorage();
|
|
2614
|
-
let storageData = void 0;
|
|
2615
|
-
let pageId = generatePageId();
|
|
2616
|
-
let previousUrl = void 0;
|
|
2617
|
-
return {
|
|
2618
|
-
init: () => {
|
|
2619
|
-
storageData = storage.get();
|
|
2620
|
-
if (!storageData || Date.now() - storageData.updated > sessionDurationSeconds * 1e3) {
|
|
2621
|
-
const previousSessionId = storageData == null ? void 0 : storageData.sessionId;
|
|
2622
|
-
storageData = {
|
|
2623
|
-
visitorId: (storageData == null ? void 0 : storageData.visitorId) || generateVisitorId(),
|
|
2624
|
-
sessionId: generateSessionId(),
|
|
2625
|
-
updated: Date.now()
|
|
2626
|
-
};
|
|
2627
|
-
storage.set(storageData);
|
|
2628
|
-
client.sessionStart({
|
|
2629
|
-
visitorId: storageData.visitorId,
|
|
2630
|
-
sessionId: storageData.sessionId,
|
|
2631
|
-
previousSessionId,
|
|
2632
|
-
maxAgeSeconds: sessionDurationSeconds,
|
|
2633
|
-
pageId
|
|
2634
|
-
});
|
|
2635
|
-
} else if (storageData) {
|
|
2636
|
-
storage.set(storageData);
|
|
2637
|
-
}
|
|
2638
|
-
},
|
|
2639
|
-
pageHit: () => {
|
|
2640
|
-
if (!storageData) {
|
|
2641
|
-
return;
|
|
2642
|
-
}
|
|
2643
|
-
if (previousUrl === window.location.href) {
|
|
2644
|
-
return;
|
|
2645
|
-
}
|
|
2646
|
-
previousUrl = window.location.href;
|
|
2647
|
-
pageId = generatePageId();
|
|
2648
|
-
client.pageHit({
|
|
2649
|
-
visitorId: storageData.visitorId,
|
|
2650
|
-
sessionId: storageData.sessionId,
|
|
2651
|
-
pageId
|
|
2652
|
-
});
|
|
2653
|
-
},
|
|
2654
|
-
testResult: (result) => {
|
|
2655
|
-
if (!storageData) {
|
|
2656
|
-
return;
|
|
2657
|
-
}
|
|
2658
|
-
client.testResult({
|
|
2659
|
-
...result,
|
|
2660
|
-
visitorId: storageData.visitorId,
|
|
2661
|
-
sessionId: storageData.sessionId,
|
|
2662
|
-
pageId
|
|
2663
|
-
});
|
|
2664
|
-
},
|
|
2665
|
-
personalizationResult: (result) => {
|
|
2666
|
-
if (!storageData) {
|
|
2667
|
-
return;
|
|
2668
|
-
}
|
|
2669
|
-
client.personalizationResult({
|
|
2670
|
-
...result,
|
|
2671
|
-
visitorId: storageData.visitorId,
|
|
2672
|
-
sessionId: storageData.sessionId,
|
|
2673
|
-
pageId
|
|
2674
|
-
});
|
|
2675
|
-
},
|
|
2676
|
-
goalConvert: (goalId) => {
|
|
2677
|
-
if (!storageData) {
|
|
2678
|
-
return;
|
|
2679
|
-
}
|
|
2680
|
-
client.goalConvert({
|
|
2681
|
-
visitorId: storageData.visitorId,
|
|
2682
|
-
sessionId: storageData.sessionId,
|
|
2683
|
-
goalId,
|
|
2684
|
-
pageId
|
|
2685
|
-
});
|
|
2686
|
-
},
|
|
2687
|
-
scoresChange: (scores) => {
|
|
2688
|
-
if (!storageData) {
|
|
2689
|
-
return;
|
|
2690
|
-
}
|
|
2691
|
-
client.scoresChange({
|
|
2692
|
-
visitorId: storageData.visitorId,
|
|
2693
|
-
sessionId: storageData.sessionId,
|
|
2694
|
-
scores,
|
|
2695
|
-
pageId
|
|
2696
|
-
});
|
|
2697
|
-
},
|
|
2698
|
-
forget: () => {
|
|
2699
|
-
storage.clear();
|
|
2700
|
-
storageData = void 0;
|
|
2701
|
-
},
|
|
2702
|
-
get sessionId() {
|
|
2703
|
-
return storageData == null ? void 0 : storageData.sessionId;
|
|
2704
|
-
}
|
|
2705
|
-
};
|
|
2706
|
-
};
|
|
2707
|
-
|
|
2708
|
-
// src/insights/index.ts
|
|
2709
|
-
var enableUniformInsights = (options) => {
|
|
2710
|
-
const insights = createInsightsV1({
|
|
2711
|
-
endpoint: options.endpoint
|
|
2712
|
-
});
|
|
2713
|
-
let previousUrl = void 0;
|
|
2714
|
-
return {
|
|
2715
|
-
init: (context) => {
|
|
2716
|
-
if (typeof window === "undefined") {
|
|
2717
|
-
return () => {
|
|
2718
|
-
};
|
|
2719
|
-
}
|
|
2720
|
-
const consentChanged = () => {
|
|
2721
|
-
if (context.storage.data.consent) {
|
|
2722
|
-
insights.init();
|
|
2723
|
-
} else {
|
|
2724
|
-
insights.forget();
|
|
2725
|
-
}
|
|
2726
|
-
};
|
|
2727
|
-
const handlePersonalizationResult = (data) => {
|
|
2728
|
-
insights.personalizationResult(data);
|
|
2729
|
-
};
|
|
2730
|
-
const handleTestResult = (result) => {
|
|
2731
|
-
insights.testResult(result);
|
|
2732
|
-
};
|
|
2733
|
-
const handleGoalConvert = (result) => {
|
|
2734
|
-
insights.goalConvert(result.goalId);
|
|
2735
|
-
};
|
|
2736
|
-
const handleScoreChange = (scores) => {
|
|
2737
|
-
insights.scoresChange(scores);
|
|
2738
|
-
};
|
|
2739
|
-
context.storage.events.on("goalConverted", handleGoalConvert);
|
|
2740
|
-
context.storage.events.on("consentUpdated", consentChanged);
|
|
2741
|
-
context.events.on("personalizationResult", handlePersonalizationResult);
|
|
2742
|
-
context.events.on("testResult", handleTestResult);
|
|
2743
|
-
context.events.on("scoresUpdated", handleScoreChange);
|
|
2744
|
-
if (context.storage.data.consent) {
|
|
2745
|
-
consentChanged();
|
|
2746
|
-
}
|
|
2747
|
-
return () => {
|
|
2748
|
-
context.storage.events.off("consentUpdated", consentChanged);
|
|
2749
|
-
context.storage.events.off("goalConverted", handleGoalConvert);
|
|
2750
|
-
context.events.off("personalizationResult", handlePersonalizationResult);
|
|
2751
|
-
context.events.off("testResult", handleTestResult);
|
|
2752
|
-
context.events.off("scoresUpdated", handleScoreChange);
|
|
2753
|
-
};
|
|
2754
|
-
},
|
|
2755
|
-
update: (context) => {
|
|
2756
|
-
if (context.url && context.url.toString() !== previousUrl) {
|
|
2757
|
-
previousUrl = context.url.toString();
|
|
2758
|
-
insights.pageHit();
|
|
2759
|
-
}
|
|
2760
|
-
},
|
|
2761
|
-
forget: () => {
|
|
2762
|
-
insights.forget();
|
|
2763
|
-
}
|
|
2764
|
-
};
|
|
2765
|
-
};
|
|
2766
|
-
|
|
2767
2411
|
// src/logging/enableConsoleLogDrain.ts
|
|
2768
2412
|
var import_rfdc2 = __toESM(require("rfdc"));
|
|
2769
2413
|
|
|
@@ -2983,7 +2627,6 @@ function parseQuickConnect(serialized) {
|
|
|
2983
2627
|
enableConsoleLogDrain,
|
|
2984
2628
|
enableContextDevTools,
|
|
2985
2629
|
enableDebugConsoleLogDrain,
|
|
2986
|
-
enableUniformInsights,
|
|
2987
2630
|
encodeCookieType,
|
|
2988
2631
|
evaluateVariantMatch,
|
|
2989
2632
|
eventEvaluator,
|
package/dist/index.mjs
CHANGED
|
@@ -2316,361 +2316,6 @@ var ScriptType = /* @__PURE__ */ ((ScriptType2) => {
|
|
|
2316
2316
|
})(ScriptType || {});
|
|
2317
2317
|
var EdgeNodeTagName = "nesitag";
|
|
2318
2318
|
|
|
2319
|
-
// src/insights/storage.ts
|
|
2320
|
-
var createInsightsStorage = () => {
|
|
2321
|
-
const STORAGE_KEY2 = "ufin";
|
|
2322
|
-
return {
|
|
2323
|
-
get: () => {
|
|
2324
|
-
const data = localStorage.getItem(STORAGE_KEY2);
|
|
2325
|
-
if (!data) {
|
|
2326
|
-
return;
|
|
2327
|
-
}
|
|
2328
|
-
return JSON.parse(data);
|
|
2329
|
-
},
|
|
2330
|
-
set: (data) => {
|
|
2331
|
-
const toSet = {
|
|
2332
|
-
...data,
|
|
2333
|
-
updated: Date.now()
|
|
2334
|
-
};
|
|
2335
|
-
localStorage.setItem(STORAGE_KEY2, JSON.stringify(toSet));
|
|
2336
|
-
},
|
|
2337
|
-
clear: () => {
|
|
2338
|
-
localStorage.removeItem(STORAGE_KEY2);
|
|
2339
|
-
}
|
|
2340
|
-
};
|
|
2341
|
-
};
|
|
2342
|
-
|
|
2343
|
-
// src/insights/types.ts
|
|
2344
|
-
var getBasePayload = () => {
|
|
2345
|
-
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2346
|
-
const locale = navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.userLanguage || navigator.language || navigator.browserLanguage || "en";
|
|
2347
|
-
return {
|
|
2348
|
-
"user-agent": window.navigator.userAgent,
|
|
2349
|
-
locale,
|
|
2350
|
-
location: timeZone,
|
|
2351
|
-
referrer: document.referrer,
|
|
2352
|
-
pathname: window.location.pathname,
|
|
2353
|
-
href: window.location.href
|
|
2354
|
-
};
|
|
2355
|
-
};
|
|
2356
|
-
var generateVisitorId = () => {
|
|
2357
|
-
return `visitor_${generalRandomId()}`;
|
|
2358
|
-
};
|
|
2359
|
-
var generateSessionId = () => {
|
|
2360
|
-
return `session_${generalRandomId()}`;
|
|
2361
|
-
};
|
|
2362
|
-
var generatePageId = () => {
|
|
2363
|
-
return `page_${generalRandomId()}`;
|
|
2364
|
-
};
|
|
2365
|
-
var generalRandomId = () => {
|
|
2366
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
2367
|
-
const id = crypto.randomUUID();
|
|
2368
|
-
return id.replaceAll("-", "").toLowerCase();
|
|
2369
|
-
}
|
|
2370
|
-
return Math.random().toString(32).substring(2);
|
|
2371
|
-
};
|
|
2372
|
-
|
|
2373
|
-
// src/insights/v1.ts
|
|
2374
|
-
var createInsightsClient = ({ endpoint }) => {
|
|
2375
|
-
let endpointUrl;
|
|
2376
|
-
const apiKey = endpoint.apiKey;
|
|
2377
|
-
const projectId = endpoint.projectId;
|
|
2378
|
-
if (endpoint.type === "api") {
|
|
2379
|
-
const url = new URL(endpoint.host);
|
|
2380
|
-
url.pathname = `/v0/events`;
|
|
2381
|
-
if (endpoint.host.includes("tinybird.co")) {
|
|
2382
|
-
url.pathname = "/v0/events";
|
|
2383
|
-
}
|
|
2384
|
-
url.searchParams.set("name", "analytics_events");
|
|
2385
|
-
endpointUrl = url.toString();
|
|
2386
|
-
} else {
|
|
2387
|
-
endpointUrl = endpoint.path;
|
|
2388
|
-
}
|
|
2389
|
-
const sendMessage = async (message) => {
|
|
2390
|
-
if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
|
|
2391
|
-
return;
|
|
2392
|
-
}
|
|
2393
|
-
const converted = {
|
|
2394
|
-
...message,
|
|
2395
|
-
payload: JSON.stringify(message.payload)
|
|
2396
|
-
};
|
|
2397
|
-
const headers = {
|
|
2398
|
-
"Content-Type": "application/json"
|
|
2399
|
-
};
|
|
2400
|
-
if (apiKey) {
|
|
2401
|
-
headers.Authorization = `Bearer ${apiKey}`;
|
|
2402
|
-
}
|
|
2403
|
-
const response = await fetch(endpointUrl, {
|
|
2404
|
-
method: "POST",
|
|
2405
|
-
headers,
|
|
2406
|
-
body: JSON.stringify(converted)
|
|
2407
|
-
});
|
|
2408
|
-
const json = await response.json();
|
|
2409
|
-
return json;
|
|
2410
|
-
};
|
|
2411
|
-
return {
|
|
2412
|
-
sessionStart: (options) => {
|
|
2413
|
-
const message = {
|
|
2414
|
-
action: "session_start",
|
|
2415
|
-
version: "1",
|
|
2416
|
-
session_id: options.sessionId,
|
|
2417
|
-
visitor_id: options.visitorId,
|
|
2418
|
-
page_view_id: options.pageId,
|
|
2419
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2420
|
-
project_id: projectId,
|
|
2421
|
-
payload: {
|
|
2422
|
-
...getBasePayload(),
|
|
2423
|
-
previous_session_id: options.previousSessionId
|
|
2424
|
-
}
|
|
2425
|
-
};
|
|
2426
|
-
return sendMessage(message);
|
|
2427
|
-
},
|
|
2428
|
-
pageHit: (options) => {
|
|
2429
|
-
const message = {
|
|
2430
|
-
action: "page_hit",
|
|
2431
|
-
version: "1",
|
|
2432
|
-
session_id: options.sessionId,
|
|
2433
|
-
visitor_id: options.visitorId,
|
|
2434
|
-
page_view_id: options.pageId,
|
|
2435
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2436
|
-
project_id: projectId,
|
|
2437
|
-
payload: getBasePayload()
|
|
2438
|
-
};
|
|
2439
|
-
return sendMessage(message);
|
|
2440
|
-
},
|
|
2441
|
-
testResult: async (options) => {
|
|
2442
|
-
const message = {
|
|
2443
|
-
action: "test_result",
|
|
2444
|
-
version: "1",
|
|
2445
|
-
session_id: options.sessionId,
|
|
2446
|
-
visitor_id: options.visitorId,
|
|
2447
|
-
page_view_id: options.pageId,
|
|
2448
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2449
|
-
project_id: projectId,
|
|
2450
|
-
payload: {
|
|
2451
|
-
...getBasePayload(),
|
|
2452
|
-
...options
|
|
2453
|
-
}
|
|
2454
|
-
};
|
|
2455
|
-
return sendMessage(message);
|
|
2456
|
-
},
|
|
2457
|
-
personalizationResult: async (options) => {
|
|
2458
|
-
const messages = options.variantIds.map((variant) => {
|
|
2459
|
-
const message = {
|
|
2460
|
-
action: "personalization_result",
|
|
2461
|
-
version: "1",
|
|
2462
|
-
session_id: options.sessionId,
|
|
2463
|
-
visitor_id: options.visitorId,
|
|
2464
|
-
page_view_id: options.pageId,
|
|
2465
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2466
|
-
project_id: projectId,
|
|
2467
|
-
payload: {
|
|
2468
|
-
...getBasePayload(),
|
|
2469
|
-
name: options.name,
|
|
2470
|
-
variantId: variant.id,
|
|
2471
|
-
control: variant.control || options.control,
|
|
2472
|
-
changed: options.changed
|
|
2473
|
-
}
|
|
2474
|
-
};
|
|
2475
|
-
return message;
|
|
2476
|
-
});
|
|
2477
|
-
await Promise.all(messages.map((message) => sendMessage(message)));
|
|
2478
|
-
},
|
|
2479
|
-
goalConvert: (options) => {
|
|
2480
|
-
const message = {
|
|
2481
|
-
action: "goal_convert",
|
|
2482
|
-
version: "1",
|
|
2483
|
-
session_id: options.sessionId,
|
|
2484
|
-
visitor_id: options.visitorId,
|
|
2485
|
-
page_view_id: options.pageId,
|
|
2486
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2487
|
-
project_id: projectId,
|
|
2488
|
-
payload: {
|
|
2489
|
-
...getBasePayload(),
|
|
2490
|
-
goalId: options.goalId
|
|
2491
|
-
}
|
|
2492
|
-
};
|
|
2493
|
-
return sendMessage(message);
|
|
2494
|
-
},
|
|
2495
|
-
scoresChange: async (options) => {
|
|
2496
|
-
const message = {
|
|
2497
|
-
action: "scores_change",
|
|
2498
|
-
version: "1",
|
|
2499
|
-
session_id: options.sessionId,
|
|
2500
|
-
visitor_id: options.visitorId,
|
|
2501
|
-
page_view_id: options.pageId,
|
|
2502
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2503
|
-
project_id: projectId,
|
|
2504
|
-
payload: {
|
|
2505
|
-
...getBasePayload(),
|
|
2506
|
-
scores: options.scores
|
|
2507
|
-
}
|
|
2508
|
-
};
|
|
2509
|
-
return sendMessage(message);
|
|
2510
|
-
}
|
|
2511
|
-
};
|
|
2512
|
-
};
|
|
2513
|
-
var createInsightsV1 = ({
|
|
2514
|
-
endpoint,
|
|
2515
|
-
sessionDurationSeconds = 30 * 60
|
|
2516
|
-
}) => {
|
|
2517
|
-
const client = createInsightsClient({
|
|
2518
|
-
endpoint
|
|
2519
|
-
});
|
|
2520
|
-
const storage = createInsightsStorage();
|
|
2521
|
-
let storageData = void 0;
|
|
2522
|
-
let pageId = generatePageId();
|
|
2523
|
-
let previousUrl = void 0;
|
|
2524
|
-
return {
|
|
2525
|
-
init: () => {
|
|
2526
|
-
storageData = storage.get();
|
|
2527
|
-
if (!storageData || Date.now() - storageData.updated > sessionDurationSeconds * 1e3) {
|
|
2528
|
-
const previousSessionId = storageData == null ? void 0 : storageData.sessionId;
|
|
2529
|
-
storageData = {
|
|
2530
|
-
visitorId: (storageData == null ? void 0 : storageData.visitorId) || generateVisitorId(),
|
|
2531
|
-
sessionId: generateSessionId(),
|
|
2532
|
-
updated: Date.now()
|
|
2533
|
-
};
|
|
2534
|
-
storage.set(storageData);
|
|
2535
|
-
client.sessionStart({
|
|
2536
|
-
visitorId: storageData.visitorId,
|
|
2537
|
-
sessionId: storageData.sessionId,
|
|
2538
|
-
previousSessionId,
|
|
2539
|
-
maxAgeSeconds: sessionDurationSeconds,
|
|
2540
|
-
pageId
|
|
2541
|
-
});
|
|
2542
|
-
} else if (storageData) {
|
|
2543
|
-
storage.set(storageData);
|
|
2544
|
-
}
|
|
2545
|
-
},
|
|
2546
|
-
pageHit: () => {
|
|
2547
|
-
if (!storageData) {
|
|
2548
|
-
return;
|
|
2549
|
-
}
|
|
2550
|
-
if (previousUrl === window.location.href) {
|
|
2551
|
-
return;
|
|
2552
|
-
}
|
|
2553
|
-
previousUrl = window.location.href;
|
|
2554
|
-
pageId = generatePageId();
|
|
2555
|
-
client.pageHit({
|
|
2556
|
-
visitorId: storageData.visitorId,
|
|
2557
|
-
sessionId: storageData.sessionId,
|
|
2558
|
-
pageId
|
|
2559
|
-
});
|
|
2560
|
-
},
|
|
2561
|
-
testResult: (result) => {
|
|
2562
|
-
if (!storageData) {
|
|
2563
|
-
return;
|
|
2564
|
-
}
|
|
2565
|
-
client.testResult({
|
|
2566
|
-
...result,
|
|
2567
|
-
visitorId: storageData.visitorId,
|
|
2568
|
-
sessionId: storageData.sessionId,
|
|
2569
|
-
pageId
|
|
2570
|
-
});
|
|
2571
|
-
},
|
|
2572
|
-
personalizationResult: (result) => {
|
|
2573
|
-
if (!storageData) {
|
|
2574
|
-
return;
|
|
2575
|
-
}
|
|
2576
|
-
client.personalizationResult({
|
|
2577
|
-
...result,
|
|
2578
|
-
visitorId: storageData.visitorId,
|
|
2579
|
-
sessionId: storageData.sessionId,
|
|
2580
|
-
pageId
|
|
2581
|
-
});
|
|
2582
|
-
},
|
|
2583
|
-
goalConvert: (goalId) => {
|
|
2584
|
-
if (!storageData) {
|
|
2585
|
-
return;
|
|
2586
|
-
}
|
|
2587
|
-
client.goalConvert({
|
|
2588
|
-
visitorId: storageData.visitorId,
|
|
2589
|
-
sessionId: storageData.sessionId,
|
|
2590
|
-
goalId,
|
|
2591
|
-
pageId
|
|
2592
|
-
});
|
|
2593
|
-
},
|
|
2594
|
-
scoresChange: (scores) => {
|
|
2595
|
-
if (!storageData) {
|
|
2596
|
-
return;
|
|
2597
|
-
}
|
|
2598
|
-
client.scoresChange({
|
|
2599
|
-
visitorId: storageData.visitorId,
|
|
2600
|
-
sessionId: storageData.sessionId,
|
|
2601
|
-
scores,
|
|
2602
|
-
pageId
|
|
2603
|
-
});
|
|
2604
|
-
},
|
|
2605
|
-
forget: () => {
|
|
2606
|
-
storage.clear();
|
|
2607
|
-
storageData = void 0;
|
|
2608
|
-
},
|
|
2609
|
-
get sessionId() {
|
|
2610
|
-
return storageData == null ? void 0 : storageData.sessionId;
|
|
2611
|
-
}
|
|
2612
|
-
};
|
|
2613
|
-
};
|
|
2614
|
-
|
|
2615
|
-
// src/insights/index.ts
|
|
2616
|
-
var enableUniformInsights = (options) => {
|
|
2617
|
-
const insights = createInsightsV1({
|
|
2618
|
-
endpoint: options.endpoint
|
|
2619
|
-
});
|
|
2620
|
-
let previousUrl = void 0;
|
|
2621
|
-
return {
|
|
2622
|
-
init: (context) => {
|
|
2623
|
-
if (typeof window === "undefined") {
|
|
2624
|
-
return () => {
|
|
2625
|
-
};
|
|
2626
|
-
}
|
|
2627
|
-
const consentChanged = () => {
|
|
2628
|
-
if (context.storage.data.consent) {
|
|
2629
|
-
insights.init();
|
|
2630
|
-
} else {
|
|
2631
|
-
insights.forget();
|
|
2632
|
-
}
|
|
2633
|
-
};
|
|
2634
|
-
const handlePersonalizationResult = (data) => {
|
|
2635
|
-
insights.personalizationResult(data);
|
|
2636
|
-
};
|
|
2637
|
-
const handleTestResult = (result) => {
|
|
2638
|
-
insights.testResult(result);
|
|
2639
|
-
};
|
|
2640
|
-
const handleGoalConvert = (result) => {
|
|
2641
|
-
insights.goalConvert(result.goalId);
|
|
2642
|
-
};
|
|
2643
|
-
const handleScoreChange = (scores) => {
|
|
2644
|
-
insights.scoresChange(scores);
|
|
2645
|
-
};
|
|
2646
|
-
context.storage.events.on("goalConverted", handleGoalConvert);
|
|
2647
|
-
context.storage.events.on("consentUpdated", consentChanged);
|
|
2648
|
-
context.events.on("personalizationResult", handlePersonalizationResult);
|
|
2649
|
-
context.events.on("testResult", handleTestResult);
|
|
2650
|
-
context.events.on("scoresUpdated", handleScoreChange);
|
|
2651
|
-
if (context.storage.data.consent) {
|
|
2652
|
-
consentChanged();
|
|
2653
|
-
}
|
|
2654
|
-
return () => {
|
|
2655
|
-
context.storage.events.off("consentUpdated", consentChanged);
|
|
2656
|
-
context.storage.events.off("goalConverted", handleGoalConvert);
|
|
2657
|
-
context.events.off("personalizationResult", handlePersonalizationResult);
|
|
2658
|
-
context.events.off("testResult", handleTestResult);
|
|
2659
|
-
context.events.off("scoresUpdated", handleScoreChange);
|
|
2660
|
-
};
|
|
2661
|
-
},
|
|
2662
|
-
update: (context) => {
|
|
2663
|
-
if (context.url && context.url.toString() !== previousUrl) {
|
|
2664
|
-
previousUrl = context.url.toString();
|
|
2665
|
-
insights.pageHit();
|
|
2666
|
-
}
|
|
2667
|
-
},
|
|
2668
|
-
forget: () => {
|
|
2669
|
-
insights.forget();
|
|
2670
|
-
}
|
|
2671
|
-
};
|
|
2672
|
-
};
|
|
2673
|
-
|
|
2674
2319
|
// src/logging/enableConsoleLogDrain.ts
|
|
2675
2320
|
import rfdc2 from "rfdc";
|
|
2676
2321
|
|
|
@@ -2889,7 +2534,6 @@ export {
|
|
|
2889
2534
|
enableConsoleLogDrain,
|
|
2890
2535
|
enableContextDevTools,
|
|
2891
2536
|
enableDebugConsoleLogDrain,
|
|
2892
|
-
enableUniformInsights,
|
|
2893
2537
|
encodeCookieType,
|
|
2894
2538
|
evaluateVariantMatch,
|
|
2895
2539
|
eventEvaluator,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/context",
|
|
3
|
-
"version": "20.80.
|
|
3
|
+
"version": "20.80.2-alpha.14.sha-1c81418f05",
|
|
4
4
|
"description": "Uniform Context core package",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "1c81418f0511232cde31935227eaec24af063252"
|
|
74
74
|
}
|