@uniformdev/insights 20.37.1-alpha.7 → 20.38.2-alpha.9

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 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,6 +416,15 @@ 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,
@@ -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,24 @@ var createInsightsPlugin = (options) => {
540
633
  eventQueue.push(eventFn);
541
634
  }
542
635
  };
636
+ const handleSegmentUpdates = (updatedScores, compositionData) => {
637
+ if (!contextInstance) {
638
+ return;
639
+ }
640
+ Object.entries(updatedScores).forEach(([scoreKey, value]) => {
641
+ const aggregateDimension = contextInstance.manifest.getAggregateDimensionByKey(scoreKey);
642
+ if (aggregateDimension) {
643
+ insights.segmentUpdated(scoreKey, value, compositionData);
644
+ }
645
+ });
646
+ };
543
647
  return {
544
648
  init: (context) => {
545
649
  if (typeof window === "undefined") {
546
650
  return () => {
547
651
  };
548
652
  }
653
+ contextInstance = context;
549
654
  const consentChanged = () => {
550
655
  if (context.storage.data.consent) {
551
656
  insights.init(context).then(() => {
@@ -599,11 +704,32 @@ var createInsightsPlugin = (options) => {
599
704
  context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
600
705
  };
601
706
  },
602
- update: (updatedData) => {
707
+ update: (updatedData, recalculatedScores) => {
708
+ var _a;
709
+ const compositionMetadata = convertUniformMetadataToInsightsMetadata(
710
+ (_a = updatedData.compositionMetadata) != null ? _a : contextInstance == null ? void 0 : contextInstance.getCompositionMetadata()
711
+ );
603
712
  if (updatedData.url && updatedData.url.toString() !== previousUrl) {
604
713
  previousUrl = updatedData.url.toString();
605
714
  queueEvent(() => {
606
- insights.pageHit(convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata));
715
+ insights.pageHit(compositionMetadata);
716
+ });
717
+ }
718
+ if (updatedData.enrichments && updatedData.enrichments.length > 0) {
719
+ queueEvent(() => {
720
+ updatedData.enrichments.forEach((enrichmentData) => {
721
+ insights.enrichmentUpdated(
722
+ enrichmentData.cat,
723
+ enrichmentData.key,
724
+ enrichmentData.str,
725
+ compositionMetadata
726
+ );
727
+ });
728
+ });
729
+ }
730
+ if (recalculatedScores) {
731
+ queueEvent(() => {
732
+ handleSegmentUpdates(recalculatedScores, compositionMetadata);
607
733
  });
608
734
  }
609
735
  },
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,6 +452,15 @@ 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,
@@ -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,24 @@ var createInsightsPlugin = (options) => {
576
669
  eventQueue.push(eventFn);
577
670
  }
578
671
  };
672
+ const handleSegmentUpdates = (updatedScores, compositionData) => {
673
+ if (!contextInstance) {
674
+ return;
675
+ }
676
+ Object.entries(updatedScores).forEach(([scoreKey, value]) => {
677
+ const aggregateDimension = contextInstance.manifest.getAggregateDimensionByKey(scoreKey);
678
+ if (aggregateDimension) {
679
+ insights.segmentUpdated(scoreKey, value, compositionData);
680
+ }
681
+ });
682
+ };
579
683
  return {
580
684
  init: (context) => {
581
685
  if (typeof window === "undefined") {
582
686
  return () => {
583
687
  };
584
688
  }
689
+ contextInstance = context;
585
690
  const consentChanged = () => {
586
691
  if (context.storage.data.consent) {
587
692
  insights.init(context).then(() => {
@@ -635,11 +740,32 @@ var createInsightsPlugin = (options) => {
635
740
  context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
636
741
  };
637
742
  },
638
- update: (updatedData) => {
743
+ update: (updatedData, recalculatedScores) => {
744
+ var _a;
745
+ const compositionMetadata = convertUniformMetadataToInsightsMetadata(
746
+ (_a = updatedData.compositionMetadata) != null ? _a : contextInstance == null ? void 0 : contextInstance.getCompositionMetadata()
747
+ );
639
748
  if (updatedData.url && updatedData.url.toString() !== previousUrl) {
640
749
  previousUrl = updatedData.url.toString();
641
750
  queueEvent(() => {
642
- insights.pageHit(convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata));
751
+ insights.pageHit(compositionMetadata);
752
+ });
753
+ }
754
+ if (updatedData.enrichments && updatedData.enrichments.length > 0) {
755
+ queueEvent(() => {
756
+ updatedData.enrichments.forEach((enrichmentData) => {
757
+ insights.enrichmentUpdated(
758
+ enrichmentData.cat,
759
+ enrichmentData.key,
760
+ enrichmentData.str,
761
+ compositionMetadata
762
+ );
763
+ });
764
+ });
765
+ }
766
+ if (recalculatedScores) {
767
+ queueEvent(() => {
768
+ handleSegmentUpdates(recalculatedScores, compositionMetadata);
643
769
  });
644
770
  }
645
771
  },
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,6 +416,15 @@ 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,
@@ -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,24 @@ var createInsightsPlugin = (options) => {
540
633
  eventQueue.push(eventFn);
541
634
  }
542
635
  };
636
+ const handleSegmentUpdates = (updatedScores, compositionData) => {
637
+ if (!contextInstance) {
638
+ return;
639
+ }
640
+ Object.entries(updatedScores).forEach(([scoreKey, value]) => {
641
+ const aggregateDimension = contextInstance.manifest.getAggregateDimensionByKey(scoreKey);
642
+ if (aggregateDimension) {
643
+ insights.segmentUpdated(scoreKey, value, compositionData);
644
+ }
645
+ });
646
+ };
543
647
  return {
544
648
  init: (context) => {
545
649
  if (typeof window === "undefined") {
546
650
  return () => {
547
651
  };
548
652
  }
653
+ contextInstance = context;
549
654
  const consentChanged = () => {
550
655
  if (context.storage.data.consent) {
551
656
  insights.init(context).then(() => {
@@ -599,11 +704,32 @@ var createInsightsPlugin = (options) => {
599
704
  context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
600
705
  };
601
706
  },
602
- update: (updatedData) => {
707
+ update: (updatedData, recalculatedScores) => {
708
+ var _a;
709
+ const compositionMetadata = convertUniformMetadataToInsightsMetadata(
710
+ (_a = updatedData.compositionMetadata) != null ? _a : contextInstance == null ? void 0 : contextInstance.getCompositionMetadata()
711
+ );
603
712
  if (updatedData.url && updatedData.url.toString() !== previousUrl) {
604
713
  previousUrl = updatedData.url.toString();
605
714
  queueEvent(() => {
606
- insights.pageHit(convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata));
715
+ insights.pageHit(compositionMetadata);
716
+ });
717
+ }
718
+ if (updatedData.enrichments && updatedData.enrichments.length > 0) {
719
+ queueEvent(() => {
720
+ updatedData.enrichments.forEach((enrichmentData) => {
721
+ insights.enrichmentUpdated(
722
+ enrichmentData.cat,
723
+ enrichmentData.key,
724
+ enrichmentData.str,
725
+ compositionMetadata
726
+ );
727
+ });
728
+ });
729
+ }
730
+ if (recalculatedScores) {
731
+ queueEvent(() => {
732
+ handleSegmentUpdates(recalculatedScores, compositionMetadata);
607
733
  });
608
734
  }
609
735
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/insights",
3
- "version": "20.37.1-alpha.7+a17ec25ff2",
3
+ "version": "20.38.2-alpha.9+de3aa3f1aa",
4
4
  "description": "Uniform Context Insights package",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -50,7 +50,7 @@
50
50
  "vitest": "3.2.4"
51
51
  },
52
52
  "dependencies": {
53
- "@uniformdev/context": "20.37.1-alpha.7+a17ec25ff2",
53
+ "@uniformdev/context": "20.38.2-alpha.9+de3aa3f1aa",
54
54
  "p-limit": "3.1.0"
55
55
  },
56
56
  "files": [
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "gitHead": "a17ec25ff2021e850ee810f166345b086daa4224"
62
+ "gitHead": "de3aa3f1aa5fc604edb758087e3ab5cf81e71c43"
63
63
  }