@uniformdev/insights 20.31.1-alpha.185 → 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/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +138 -5
- package/dist/index.js +138 -5
- package/dist/index.mjs +138 -5
- package/package.json +4 -6
package/dist/index.d.mts
CHANGED
|
@@ -84,6 +84,8 @@ type UniformInsights = {
|
|
|
84
84
|
testResult: (result: TestEvent, compositionData?: UniformMetadata) => void;
|
|
85
85
|
personalizationResult: (result: PersonalizationEvent, compositionData?: UniformMetadata) => void;
|
|
86
86
|
goalConvert: (goalId: string, compositionData?: UniformMetadata) => void;
|
|
87
|
+
segmentUpdated: (segmentId: string, value: number, compositionData?: UniformMetadata) => void;
|
|
88
|
+
enrichmentUpdated: (enrichmentId: string, key: string, strength: number, compositionData?: UniformMetadata) => void;
|
|
87
89
|
get sessionId(): string | undefined;
|
|
88
90
|
};
|
|
89
91
|
|
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,8 @@ type UniformInsights = {
|
|
|
84
84
|
testResult: (result: TestEvent, compositionData?: UniformMetadata) => void;
|
|
85
85
|
personalizationResult: (result: PersonalizationEvent, compositionData?: UniformMetadata) => void;
|
|
86
86
|
goalConvert: (goalId: string, compositionData?: UniformMetadata) => void;
|
|
87
|
+
segmentUpdated: (segmentId: string, value: number, compositionData?: UniformMetadata) => void;
|
|
88
|
+
enrichmentUpdated: (enrichmentId: string, key: string, strength: number, compositionData?: UniformMetadata) => void;
|
|
87
89
|
get sessionId(): string | undefined;
|
|
88
90
|
};
|
|
89
91
|
|
package/dist/index.esm.js
CHANGED
|
@@ -217,6 +217,33 @@ var convertUniformMetadataToInsightsMetadata = (uniformMetadata) => {
|
|
|
217
217
|
} : void 0;
|
|
218
218
|
};
|
|
219
219
|
|
|
220
|
+
// src/events/enrichment.ts
|
|
221
|
+
var buildEnrichmentUpdatedMessage = ({
|
|
222
|
+
sessionId,
|
|
223
|
+
visitorId,
|
|
224
|
+
pageId,
|
|
225
|
+
projectId,
|
|
226
|
+
enrichmentId,
|
|
227
|
+
key,
|
|
228
|
+
strength,
|
|
229
|
+
compositionData
|
|
230
|
+
}) => ({
|
|
231
|
+
action: "enrichment_updated",
|
|
232
|
+
version: "2",
|
|
233
|
+
session_id: sessionId,
|
|
234
|
+
visitor_id: visitorId,
|
|
235
|
+
page_view_id: pageId,
|
|
236
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
237
|
+
project_id: projectId,
|
|
238
|
+
payload: {
|
|
239
|
+
id: enrichmentId,
|
|
240
|
+
key,
|
|
241
|
+
strength
|
|
242
|
+
},
|
|
243
|
+
web_metadata: getWebMetadata(),
|
|
244
|
+
uniform: compositionData || {}
|
|
245
|
+
});
|
|
246
|
+
|
|
220
247
|
// src/events/goal.ts
|
|
221
248
|
var buildGoalConvertMessage = (sessionId, visitorId, pageId, projectId, goalId, compositionData) => ({
|
|
222
249
|
action: "goal_convert",
|
|
@@ -266,6 +293,31 @@ var buildPersonalizationResultMessage = (sessionId, visitorId, pageId, projectId
|
|
|
266
293
|
uniform: compositionData || {}
|
|
267
294
|
});
|
|
268
295
|
|
|
296
|
+
// src/events/segment.ts
|
|
297
|
+
var buildSegmentUpdatedMessage = ({
|
|
298
|
+
sessionId,
|
|
299
|
+
visitorId,
|
|
300
|
+
pageId,
|
|
301
|
+
projectId,
|
|
302
|
+
segmentId,
|
|
303
|
+
value,
|
|
304
|
+
compositionData
|
|
305
|
+
}) => ({
|
|
306
|
+
action: "segment_updated",
|
|
307
|
+
version: "2",
|
|
308
|
+
session_id: sessionId,
|
|
309
|
+
visitor_id: visitorId,
|
|
310
|
+
page_view_id: pageId,
|
|
311
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
312
|
+
project_id: projectId,
|
|
313
|
+
payload: {
|
|
314
|
+
id: segmentId,
|
|
315
|
+
value
|
|
316
|
+
},
|
|
317
|
+
web_metadata: getWebMetadata(),
|
|
318
|
+
uniform: compositionData || {}
|
|
319
|
+
});
|
|
320
|
+
|
|
269
321
|
// src/events/session.ts
|
|
270
322
|
var buildSessionStartMessage = (sessionId, visitorId, pageId, projectId, previousSessionId, compositionData) => ({
|
|
271
323
|
action: "session_start",
|
|
@@ -364,10 +416,19 @@ var createMemoryStorage = () => {
|
|
|
364
416
|
|
|
365
417
|
// src/plugin.ts
|
|
366
418
|
var createInsightsCore = (options) => {
|
|
419
|
+
if (options.endpoint.type === "api" && !options.endpoint.host) {
|
|
420
|
+
throw new Error("Insights context plugin requires API host");
|
|
421
|
+
}
|
|
422
|
+
if (options.endpoint.type === "api" && !options.endpoint.apiKey) {
|
|
423
|
+
throw new Error("Insights context plugin requires API key");
|
|
424
|
+
}
|
|
425
|
+
if (!options.endpoint.projectId) {
|
|
426
|
+
throw new Error("Insights context plugin requires project ID");
|
|
427
|
+
}
|
|
367
428
|
const {
|
|
368
429
|
endpoint,
|
|
369
430
|
storage: customStorage,
|
|
370
|
-
batchConfig
|
|
431
|
+
batchConfig,
|
|
371
432
|
sessionDurationSeconds = 30 * 60,
|
|
372
433
|
getVisitorId = generateVisitorId,
|
|
373
434
|
getSessionId = generateSessionId
|
|
@@ -511,6 +572,37 @@ var createInsightsCore = (options) => {
|
|
|
511
572
|
);
|
|
512
573
|
addEvent(message);
|
|
513
574
|
},
|
|
575
|
+
segmentUpdated: (segmentId, value, compositionData) => {
|
|
576
|
+
if (!storageData) {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const message = buildSegmentUpdatedMessage({
|
|
580
|
+
sessionId: storageData.sessionId,
|
|
581
|
+
visitorId: storageData.visitorId,
|
|
582
|
+
pageId,
|
|
583
|
+
projectId: endpoint.projectId,
|
|
584
|
+
segmentId,
|
|
585
|
+
value,
|
|
586
|
+
compositionData
|
|
587
|
+
});
|
|
588
|
+
addEvent(message);
|
|
589
|
+
},
|
|
590
|
+
enrichmentUpdated: (enrichmentId, key, strength, compositionData) => {
|
|
591
|
+
if (!storageData) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const message = buildEnrichmentUpdatedMessage({
|
|
595
|
+
sessionId: storageData.sessionId,
|
|
596
|
+
visitorId: storageData.visitorId,
|
|
597
|
+
pageId,
|
|
598
|
+
projectId: endpoint.projectId,
|
|
599
|
+
enrichmentId,
|
|
600
|
+
key,
|
|
601
|
+
strength,
|
|
602
|
+
compositionData
|
|
603
|
+
});
|
|
604
|
+
addEvent(message);
|
|
605
|
+
},
|
|
514
606
|
forget: () => {
|
|
515
607
|
storage.clear();
|
|
516
608
|
storageData = void 0;
|
|
@@ -527,6 +619,7 @@ var createInsightsPlugin = (options) => {
|
|
|
527
619
|
let previousUrl = void 0;
|
|
528
620
|
let isInitialized = false;
|
|
529
621
|
let eventQueue = [];
|
|
622
|
+
let contextInstance = void 0;
|
|
530
623
|
const processQueuedEvents = () => {
|
|
531
624
|
if (isInitialized && eventQueue.length > 0) {
|
|
532
625
|
eventQueue.forEach((event) => event());
|
|
@@ -540,12 +633,31 @@ var createInsightsPlugin = (options) => {
|
|
|
540
633
|
eventQueue.push(eventFn);
|
|
541
634
|
}
|
|
542
635
|
};
|
|
636
|
+
const previousScores = {};
|
|
637
|
+
const handleScoreUpdates = (updatedScores, compositionData) => {
|
|
638
|
+
if (!contextInstance) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
Object.entries(updatedScores).forEach(([scoreKey, value]) => {
|
|
642
|
+
var _a, _b;
|
|
643
|
+
if (previousScores[scoreKey] === value) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const aggregateDimension = contextInstance.manifest.getAggregateDimensionByKey(scoreKey);
|
|
647
|
+
const signalDimension = (_b = (_a = contextInstance.manifest.data.project.pz) == null ? void 0 : _a.sig) == null ? void 0 : _b[scoreKey];
|
|
648
|
+
if (aggregateDimension || signalDimension) {
|
|
649
|
+
insights.segmentUpdated(scoreKey, value, compositionData);
|
|
650
|
+
previousScores[scoreKey] = value;
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
};
|
|
543
654
|
return {
|
|
544
655
|
init: (context) => {
|
|
545
656
|
if (typeof window === "undefined") {
|
|
546
657
|
return () => {
|
|
547
658
|
};
|
|
548
659
|
}
|
|
660
|
+
contextInstance = context;
|
|
549
661
|
const consentChanged = () => {
|
|
550
662
|
if (context.storage.data.consent) {
|
|
551
663
|
insights.init(context).then(() => {
|
|
@@ -599,11 +711,32 @@ var createInsightsPlugin = (options) => {
|
|
|
599
711
|
context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
|
|
600
712
|
};
|
|
601
713
|
},
|
|
602
|
-
update: (
|
|
603
|
-
|
|
604
|
-
|
|
714
|
+
update: (updatedData, recalculatedScores) => {
|
|
715
|
+
var _a;
|
|
716
|
+
const compositionMetadata = convertUniformMetadataToInsightsMetadata(
|
|
717
|
+
(_a = updatedData.compositionMetadata) != null ? _a : contextInstance == null ? void 0 : contextInstance.getCompositionMetadata()
|
|
718
|
+
);
|
|
719
|
+
if (updatedData.url && updatedData.url.toString() !== previousUrl) {
|
|
720
|
+
previousUrl = updatedData.url.toString();
|
|
721
|
+
queueEvent(() => {
|
|
722
|
+
insights.pageHit(compositionMetadata);
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
if (updatedData.enrichments && updatedData.enrichments.length > 0) {
|
|
726
|
+
queueEvent(() => {
|
|
727
|
+
updatedData.enrichments.forEach((enrichmentData) => {
|
|
728
|
+
insights.enrichmentUpdated(
|
|
729
|
+
enrichmentData.cat,
|
|
730
|
+
enrichmentData.key,
|
|
731
|
+
enrichmentData.str,
|
|
732
|
+
compositionMetadata
|
|
733
|
+
);
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
if (recalculatedScores) {
|
|
605
738
|
queueEvent(() => {
|
|
606
|
-
|
|
739
|
+
handleScoreUpdates(recalculatedScores, compositionMetadata);
|
|
607
740
|
});
|
|
608
741
|
}
|
|
609
742
|
},
|
package/dist/index.js
CHANGED
|
@@ -253,6 +253,33 @@ var convertUniformMetadataToInsightsMetadata = (uniformMetadata) => {
|
|
|
253
253
|
} : void 0;
|
|
254
254
|
};
|
|
255
255
|
|
|
256
|
+
// src/events/enrichment.ts
|
|
257
|
+
var buildEnrichmentUpdatedMessage = ({
|
|
258
|
+
sessionId,
|
|
259
|
+
visitorId,
|
|
260
|
+
pageId,
|
|
261
|
+
projectId,
|
|
262
|
+
enrichmentId,
|
|
263
|
+
key,
|
|
264
|
+
strength,
|
|
265
|
+
compositionData
|
|
266
|
+
}) => ({
|
|
267
|
+
action: "enrichment_updated",
|
|
268
|
+
version: "2",
|
|
269
|
+
session_id: sessionId,
|
|
270
|
+
visitor_id: visitorId,
|
|
271
|
+
page_view_id: pageId,
|
|
272
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
273
|
+
project_id: projectId,
|
|
274
|
+
payload: {
|
|
275
|
+
id: enrichmentId,
|
|
276
|
+
key,
|
|
277
|
+
strength
|
|
278
|
+
},
|
|
279
|
+
web_metadata: getWebMetadata(),
|
|
280
|
+
uniform: compositionData || {}
|
|
281
|
+
});
|
|
282
|
+
|
|
256
283
|
// src/events/goal.ts
|
|
257
284
|
var buildGoalConvertMessage = (sessionId, visitorId, pageId, projectId, goalId, compositionData) => ({
|
|
258
285
|
action: "goal_convert",
|
|
@@ -302,6 +329,31 @@ var buildPersonalizationResultMessage = (sessionId, visitorId, pageId, projectId
|
|
|
302
329
|
uniform: compositionData || {}
|
|
303
330
|
});
|
|
304
331
|
|
|
332
|
+
// src/events/segment.ts
|
|
333
|
+
var buildSegmentUpdatedMessage = ({
|
|
334
|
+
sessionId,
|
|
335
|
+
visitorId,
|
|
336
|
+
pageId,
|
|
337
|
+
projectId,
|
|
338
|
+
segmentId,
|
|
339
|
+
value,
|
|
340
|
+
compositionData
|
|
341
|
+
}) => ({
|
|
342
|
+
action: "segment_updated",
|
|
343
|
+
version: "2",
|
|
344
|
+
session_id: sessionId,
|
|
345
|
+
visitor_id: visitorId,
|
|
346
|
+
page_view_id: pageId,
|
|
347
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
348
|
+
project_id: projectId,
|
|
349
|
+
payload: {
|
|
350
|
+
id: segmentId,
|
|
351
|
+
value
|
|
352
|
+
},
|
|
353
|
+
web_metadata: getWebMetadata(),
|
|
354
|
+
uniform: compositionData || {}
|
|
355
|
+
});
|
|
356
|
+
|
|
305
357
|
// src/events/session.ts
|
|
306
358
|
var buildSessionStartMessage = (sessionId, visitorId, pageId, projectId, previousSessionId, compositionData) => ({
|
|
307
359
|
action: "session_start",
|
|
@@ -400,10 +452,19 @@ var createMemoryStorage = () => {
|
|
|
400
452
|
|
|
401
453
|
// src/plugin.ts
|
|
402
454
|
var createInsightsCore = (options) => {
|
|
455
|
+
if (options.endpoint.type === "api" && !options.endpoint.host) {
|
|
456
|
+
throw new Error("Insights context plugin requires API host");
|
|
457
|
+
}
|
|
458
|
+
if (options.endpoint.type === "api" && !options.endpoint.apiKey) {
|
|
459
|
+
throw new Error("Insights context plugin requires API key");
|
|
460
|
+
}
|
|
461
|
+
if (!options.endpoint.projectId) {
|
|
462
|
+
throw new Error("Insights context plugin requires project ID");
|
|
463
|
+
}
|
|
403
464
|
const {
|
|
404
465
|
endpoint,
|
|
405
466
|
storage: customStorage,
|
|
406
|
-
batchConfig
|
|
467
|
+
batchConfig,
|
|
407
468
|
sessionDurationSeconds = 30 * 60,
|
|
408
469
|
getVisitorId = generateVisitorId,
|
|
409
470
|
getSessionId = generateSessionId
|
|
@@ -547,6 +608,37 @@ var createInsightsCore = (options) => {
|
|
|
547
608
|
);
|
|
548
609
|
addEvent(message);
|
|
549
610
|
},
|
|
611
|
+
segmentUpdated: (segmentId, value, compositionData) => {
|
|
612
|
+
if (!storageData) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const message = buildSegmentUpdatedMessage({
|
|
616
|
+
sessionId: storageData.sessionId,
|
|
617
|
+
visitorId: storageData.visitorId,
|
|
618
|
+
pageId,
|
|
619
|
+
projectId: endpoint.projectId,
|
|
620
|
+
segmentId,
|
|
621
|
+
value,
|
|
622
|
+
compositionData
|
|
623
|
+
});
|
|
624
|
+
addEvent(message);
|
|
625
|
+
},
|
|
626
|
+
enrichmentUpdated: (enrichmentId, key, strength, compositionData) => {
|
|
627
|
+
if (!storageData) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
const message = buildEnrichmentUpdatedMessage({
|
|
631
|
+
sessionId: storageData.sessionId,
|
|
632
|
+
visitorId: storageData.visitorId,
|
|
633
|
+
pageId,
|
|
634
|
+
projectId: endpoint.projectId,
|
|
635
|
+
enrichmentId,
|
|
636
|
+
key,
|
|
637
|
+
strength,
|
|
638
|
+
compositionData
|
|
639
|
+
});
|
|
640
|
+
addEvent(message);
|
|
641
|
+
},
|
|
550
642
|
forget: () => {
|
|
551
643
|
storage.clear();
|
|
552
644
|
storageData = void 0;
|
|
@@ -563,6 +655,7 @@ var createInsightsPlugin = (options) => {
|
|
|
563
655
|
let previousUrl = void 0;
|
|
564
656
|
let isInitialized = false;
|
|
565
657
|
let eventQueue = [];
|
|
658
|
+
let contextInstance = void 0;
|
|
566
659
|
const processQueuedEvents = () => {
|
|
567
660
|
if (isInitialized && eventQueue.length > 0) {
|
|
568
661
|
eventQueue.forEach((event) => event());
|
|
@@ -576,12 +669,31 @@ var createInsightsPlugin = (options) => {
|
|
|
576
669
|
eventQueue.push(eventFn);
|
|
577
670
|
}
|
|
578
671
|
};
|
|
672
|
+
const previousScores = {};
|
|
673
|
+
const handleScoreUpdates = (updatedScores, compositionData) => {
|
|
674
|
+
if (!contextInstance) {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
Object.entries(updatedScores).forEach(([scoreKey, value]) => {
|
|
678
|
+
var _a, _b;
|
|
679
|
+
if (previousScores[scoreKey] === value) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
const aggregateDimension = contextInstance.manifest.getAggregateDimensionByKey(scoreKey);
|
|
683
|
+
const signalDimension = (_b = (_a = contextInstance.manifest.data.project.pz) == null ? void 0 : _a.sig) == null ? void 0 : _b[scoreKey];
|
|
684
|
+
if (aggregateDimension || signalDimension) {
|
|
685
|
+
insights.segmentUpdated(scoreKey, value, compositionData);
|
|
686
|
+
previousScores[scoreKey] = value;
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
};
|
|
579
690
|
return {
|
|
580
691
|
init: (context) => {
|
|
581
692
|
if (typeof window === "undefined") {
|
|
582
693
|
return () => {
|
|
583
694
|
};
|
|
584
695
|
}
|
|
696
|
+
contextInstance = context;
|
|
585
697
|
const consentChanged = () => {
|
|
586
698
|
if (context.storage.data.consent) {
|
|
587
699
|
insights.init(context).then(() => {
|
|
@@ -635,11 +747,32 @@ var createInsightsPlugin = (options) => {
|
|
|
635
747
|
context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
|
|
636
748
|
};
|
|
637
749
|
},
|
|
638
|
-
update: (
|
|
639
|
-
|
|
640
|
-
|
|
750
|
+
update: (updatedData, recalculatedScores) => {
|
|
751
|
+
var _a;
|
|
752
|
+
const compositionMetadata = convertUniformMetadataToInsightsMetadata(
|
|
753
|
+
(_a = updatedData.compositionMetadata) != null ? _a : contextInstance == null ? void 0 : contextInstance.getCompositionMetadata()
|
|
754
|
+
);
|
|
755
|
+
if (updatedData.url && updatedData.url.toString() !== previousUrl) {
|
|
756
|
+
previousUrl = updatedData.url.toString();
|
|
757
|
+
queueEvent(() => {
|
|
758
|
+
insights.pageHit(compositionMetadata);
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
if (updatedData.enrichments && updatedData.enrichments.length > 0) {
|
|
762
|
+
queueEvent(() => {
|
|
763
|
+
updatedData.enrichments.forEach((enrichmentData) => {
|
|
764
|
+
insights.enrichmentUpdated(
|
|
765
|
+
enrichmentData.cat,
|
|
766
|
+
enrichmentData.key,
|
|
767
|
+
enrichmentData.str,
|
|
768
|
+
compositionMetadata
|
|
769
|
+
);
|
|
770
|
+
});
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
if (recalculatedScores) {
|
|
641
774
|
queueEvent(() => {
|
|
642
|
-
|
|
775
|
+
handleScoreUpdates(recalculatedScores, compositionMetadata);
|
|
643
776
|
});
|
|
644
777
|
}
|
|
645
778
|
},
|
package/dist/index.mjs
CHANGED
|
@@ -217,6 +217,33 @@ var convertUniformMetadataToInsightsMetadata = (uniformMetadata) => {
|
|
|
217
217
|
} : void 0;
|
|
218
218
|
};
|
|
219
219
|
|
|
220
|
+
// src/events/enrichment.ts
|
|
221
|
+
var buildEnrichmentUpdatedMessage = ({
|
|
222
|
+
sessionId,
|
|
223
|
+
visitorId,
|
|
224
|
+
pageId,
|
|
225
|
+
projectId,
|
|
226
|
+
enrichmentId,
|
|
227
|
+
key,
|
|
228
|
+
strength,
|
|
229
|
+
compositionData
|
|
230
|
+
}) => ({
|
|
231
|
+
action: "enrichment_updated",
|
|
232
|
+
version: "2",
|
|
233
|
+
session_id: sessionId,
|
|
234
|
+
visitor_id: visitorId,
|
|
235
|
+
page_view_id: pageId,
|
|
236
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
237
|
+
project_id: projectId,
|
|
238
|
+
payload: {
|
|
239
|
+
id: enrichmentId,
|
|
240
|
+
key,
|
|
241
|
+
strength
|
|
242
|
+
},
|
|
243
|
+
web_metadata: getWebMetadata(),
|
|
244
|
+
uniform: compositionData || {}
|
|
245
|
+
});
|
|
246
|
+
|
|
220
247
|
// src/events/goal.ts
|
|
221
248
|
var buildGoalConvertMessage = (sessionId, visitorId, pageId, projectId, goalId, compositionData) => ({
|
|
222
249
|
action: "goal_convert",
|
|
@@ -266,6 +293,31 @@ var buildPersonalizationResultMessage = (sessionId, visitorId, pageId, projectId
|
|
|
266
293
|
uniform: compositionData || {}
|
|
267
294
|
});
|
|
268
295
|
|
|
296
|
+
// src/events/segment.ts
|
|
297
|
+
var buildSegmentUpdatedMessage = ({
|
|
298
|
+
sessionId,
|
|
299
|
+
visitorId,
|
|
300
|
+
pageId,
|
|
301
|
+
projectId,
|
|
302
|
+
segmentId,
|
|
303
|
+
value,
|
|
304
|
+
compositionData
|
|
305
|
+
}) => ({
|
|
306
|
+
action: "segment_updated",
|
|
307
|
+
version: "2",
|
|
308
|
+
session_id: sessionId,
|
|
309
|
+
visitor_id: visitorId,
|
|
310
|
+
page_view_id: pageId,
|
|
311
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
312
|
+
project_id: projectId,
|
|
313
|
+
payload: {
|
|
314
|
+
id: segmentId,
|
|
315
|
+
value
|
|
316
|
+
},
|
|
317
|
+
web_metadata: getWebMetadata(),
|
|
318
|
+
uniform: compositionData || {}
|
|
319
|
+
});
|
|
320
|
+
|
|
269
321
|
// src/events/session.ts
|
|
270
322
|
var buildSessionStartMessage = (sessionId, visitorId, pageId, projectId, previousSessionId, compositionData) => ({
|
|
271
323
|
action: "session_start",
|
|
@@ -364,10 +416,19 @@ var createMemoryStorage = () => {
|
|
|
364
416
|
|
|
365
417
|
// src/plugin.ts
|
|
366
418
|
var createInsightsCore = (options) => {
|
|
419
|
+
if (options.endpoint.type === "api" && !options.endpoint.host) {
|
|
420
|
+
throw new Error("Insights context plugin requires API host");
|
|
421
|
+
}
|
|
422
|
+
if (options.endpoint.type === "api" && !options.endpoint.apiKey) {
|
|
423
|
+
throw new Error("Insights context plugin requires API key");
|
|
424
|
+
}
|
|
425
|
+
if (!options.endpoint.projectId) {
|
|
426
|
+
throw new Error("Insights context plugin requires project ID");
|
|
427
|
+
}
|
|
367
428
|
const {
|
|
368
429
|
endpoint,
|
|
369
430
|
storage: customStorage,
|
|
370
|
-
batchConfig
|
|
431
|
+
batchConfig,
|
|
371
432
|
sessionDurationSeconds = 30 * 60,
|
|
372
433
|
getVisitorId = generateVisitorId,
|
|
373
434
|
getSessionId = generateSessionId
|
|
@@ -511,6 +572,37 @@ var createInsightsCore = (options) => {
|
|
|
511
572
|
);
|
|
512
573
|
addEvent(message);
|
|
513
574
|
},
|
|
575
|
+
segmentUpdated: (segmentId, value, compositionData) => {
|
|
576
|
+
if (!storageData) {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const message = buildSegmentUpdatedMessage({
|
|
580
|
+
sessionId: storageData.sessionId,
|
|
581
|
+
visitorId: storageData.visitorId,
|
|
582
|
+
pageId,
|
|
583
|
+
projectId: endpoint.projectId,
|
|
584
|
+
segmentId,
|
|
585
|
+
value,
|
|
586
|
+
compositionData
|
|
587
|
+
});
|
|
588
|
+
addEvent(message);
|
|
589
|
+
},
|
|
590
|
+
enrichmentUpdated: (enrichmentId, key, strength, compositionData) => {
|
|
591
|
+
if (!storageData) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const message = buildEnrichmentUpdatedMessage({
|
|
595
|
+
sessionId: storageData.sessionId,
|
|
596
|
+
visitorId: storageData.visitorId,
|
|
597
|
+
pageId,
|
|
598
|
+
projectId: endpoint.projectId,
|
|
599
|
+
enrichmentId,
|
|
600
|
+
key,
|
|
601
|
+
strength,
|
|
602
|
+
compositionData
|
|
603
|
+
});
|
|
604
|
+
addEvent(message);
|
|
605
|
+
},
|
|
514
606
|
forget: () => {
|
|
515
607
|
storage.clear();
|
|
516
608
|
storageData = void 0;
|
|
@@ -527,6 +619,7 @@ var createInsightsPlugin = (options) => {
|
|
|
527
619
|
let previousUrl = void 0;
|
|
528
620
|
let isInitialized = false;
|
|
529
621
|
let eventQueue = [];
|
|
622
|
+
let contextInstance = void 0;
|
|
530
623
|
const processQueuedEvents = () => {
|
|
531
624
|
if (isInitialized && eventQueue.length > 0) {
|
|
532
625
|
eventQueue.forEach((event) => event());
|
|
@@ -540,12 +633,31 @@ var createInsightsPlugin = (options) => {
|
|
|
540
633
|
eventQueue.push(eventFn);
|
|
541
634
|
}
|
|
542
635
|
};
|
|
636
|
+
const previousScores = {};
|
|
637
|
+
const handleScoreUpdates = (updatedScores, compositionData) => {
|
|
638
|
+
if (!contextInstance) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
Object.entries(updatedScores).forEach(([scoreKey, value]) => {
|
|
642
|
+
var _a, _b;
|
|
643
|
+
if (previousScores[scoreKey] === value) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const aggregateDimension = contextInstance.manifest.getAggregateDimensionByKey(scoreKey);
|
|
647
|
+
const signalDimension = (_b = (_a = contextInstance.manifest.data.project.pz) == null ? void 0 : _a.sig) == null ? void 0 : _b[scoreKey];
|
|
648
|
+
if (aggregateDimension || signalDimension) {
|
|
649
|
+
insights.segmentUpdated(scoreKey, value, compositionData);
|
|
650
|
+
previousScores[scoreKey] = value;
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
};
|
|
543
654
|
return {
|
|
544
655
|
init: (context) => {
|
|
545
656
|
if (typeof window === "undefined") {
|
|
546
657
|
return () => {
|
|
547
658
|
};
|
|
548
659
|
}
|
|
660
|
+
contextInstance = context;
|
|
549
661
|
const consentChanged = () => {
|
|
550
662
|
if (context.storage.data.consent) {
|
|
551
663
|
insights.init(context).then(() => {
|
|
@@ -599,11 +711,32 @@ var createInsightsPlugin = (options) => {
|
|
|
599
711
|
context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
|
|
600
712
|
};
|
|
601
713
|
},
|
|
602
|
-
update: (
|
|
603
|
-
|
|
604
|
-
|
|
714
|
+
update: (updatedData, recalculatedScores) => {
|
|
715
|
+
var _a;
|
|
716
|
+
const compositionMetadata = convertUniformMetadataToInsightsMetadata(
|
|
717
|
+
(_a = updatedData.compositionMetadata) != null ? _a : contextInstance == null ? void 0 : contextInstance.getCompositionMetadata()
|
|
718
|
+
);
|
|
719
|
+
if (updatedData.url && updatedData.url.toString() !== previousUrl) {
|
|
720
|
+
previousUrl = updatedData.url.toString();
|
|
721
|
+
queueEvent(() => {
|
|
722
|
+
insights.pageHit(compositionMetadata);
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
if (updatedData.enrichments && updatedData.enrichments.length > 0) {
|
|
726
|
+
queueEvent(() => {
|
|
727
|
+
updatedData.enrichments.forEach((enrichmentData) => {
|
|
728
|
+
insights.enrichmentUpdated(
|
|
729
|
+
enrichmentData.cat,
|
|
730
|
+
enrichmentData.key,
|
|
731
|
+
enrichmentData.str,
|
|
732
|
+
compositionMetadata
|
|
733
|
+
);
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
if (recalculatedScores) {
|
|
605
738
|
queueEvent(() => {
|
|
606
|
-
|
|
739
|
+
handleScoreUpdates(recalculatedScores, compositionMetadata);
|
|
607
740
|
});
|
|
608
741
|
}
|
|
609
742
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/insights",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.35.1-alpha.210+4fa236da76",
|
|
4
4
|
"description": "Uniform Context Insights package",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,14 +43,12 @@
|
|
|
43
43
|
"@types/js-cookie": "3.0.6",
|
|
44
44
|
"@types/node": "^20.0.0",
|
|
45
45
|
"@types/uuid": "9.0.4",
|
|
46
|
-
"@vitest/coverage-v8": "3.2.4",
|
|
47
46
|
"benny": "3.7.1",
|
|
48
47
|
"vite": "^7.0.6",
|
|
49
|
-
"vite-tsconfig-paths": "^5.1.4"
|
|
50
|
-
"vitest": "3.2.4"
|
|
48
|
+
"vite-tsconfig-paths": "^5.1.4"
|
|
51
49
|
},
|
|
52
50
|
"dependencies": {
|
|
53
|
-
"@uniformdev/context": "20.
|
|
51
|
+
"@uniformdev/context": "20.35.1-alpha.210+4fa236da76",
|
|
54
52
|
"p-limit": "3.1.0"
|
|
55
53
|
},
|
|
56
54
|
"files": [
|
|
@@ -59,5 +57,5 @@
|
|
|
59
57
|
"publishConfig": {
|
|
60
58
|
"access": "public"
|
|
61
59
|
},
|
|
62
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "4fa236da76e057582eae6c2595a2fa763fda886a"
|
|
63
61
|
}
|