@uniformdev/insights 20.37.1-alpha.15 → 20.37.1-alpha.25

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,8 +84,6 @@ 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;
89
87
  get sessionId(): string | undefined;
90
88
  };
91
89
 
package/dist/index.d.ts CHANGED
@@ -84,8 +84,6 @@ 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;
89
87
  get sessionId(): string | undefined;
90
88
  };
91
89
 
package/dist/index.esm.js CHANGED
@@ -217,33 +217,6 @@ 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
-
247
220
  // src/events/goal.ts
248
221
  var buildGoalConvertMessage = (sessionId, visitorId, pageId, projectId, goalId, compositionData) => ({
249
222
  action: "goal_convert",
@@ -293,31 +266,6 @@ var buildPersonalizationResultMessage = (sessionId, visitorId, pageId, projectId
293
266
  uniform: compositionData || {}
294
267
  });
295
268
 
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
-
321
269
  // src/events/session.ts
322
270
  var buildSessionStartMessage = (sessionId, visitorId, pageId, projectId, previousSessionId, compositionData) => ({
323
271
  action: "session_start",
@@ -416,15 +364,6 @@ var createMemoryStorage = () => {
416
364
 
417
365
  // src/plugin.ts
418
366
  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
- }
428
367
  const {
429
368
  endpoint,
430
369
  storage: customStorage,
@@ -572,37 +511,6 @@ var createInsightsCore = (options) => {
572
511
  );
573
512
  addEvent(message);
574
513
  },
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
- },
606
514
  forget: () => {
607
515
  storage.clear();
608
516
  storageData = void 0;
@@ -619,7 +527,6 @@ var createInsightsPlugin = (options) => {
619
527
  let previousUrl = void 0;
620
528
  let isInitialized = false;
621
529
  let eventQueue = [];
622
- let contextInstance = void 0;
623
530
  const processQueuedEvents = () => {
624
531
  if (isInitialized && eventQueue.length > 0) {
625
532
  eventQueue.forEach((event) => event());
@@ -633,24 +540,12 @@ var createInsightsPlugin = (options) => {
633
540
  eventQueue.push(eventFn);
634
541
  }
635
542
  };
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
- };
647
543
  return {
648
544
  init: (context) => {
649
545
  if (typeof window === "undefined") {
650
546
  return () => {
651
547
  };
652
548
  }
653
- contextInstance = context;
654
549
  const consentChanged = () => {
655
550
  if (context.storage.data.consent) {
656
551
  insights.init(context).then(() => {
@@ -704,31 +599,13 @@ var createInsightsPlugin = (options) => {
704
599
  context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
705
600
  };
706
601
  },
707
- update: (updatedData, recalculatedScores) => {
708
- const compositionMetadata = updatedData.compositionMetadata ? convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata) : contextInstance ? convertUniformMetadataToInsightsMetadata(contextInstance.getCompositionMetadata()) : void 0;
602
+ update: (updatedData) => {
709
603
  if (updatedData.url && updatedData.url.toString() !== previousUrl) {
710
604
  previousUrl = updatedData.url.toString();
711
605
  queueEvent(() => {
712
606
  insights.pageHit(convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata));
713
607
  });
714
608
  }
715
- if (updatedData.enrichments && updatedData.enrichments.length > 0) {
716
- queueEvent(() => {
717
- updatedData.enrichments.forEach((enrichmentData) => {
718
- insights.enrichmentUpdated(
719
- enrichmentData.cat,
720
- enrichmentData.key,
721
- enrichmentData.str,
722
- compositionMetadata
723
- );
724
- });
725
- });
726
- }
727
- if (recalculatedScores) {
728
- queueEvent(() => {
729
- handleSegmentUpdates(recalculatedScores, compositionMetadata);
730
- });
731
- }
732
609
  },
733
610
  forget: () => {
734
611
  insights.forget();
package/dist/index.js CHANGED
@@ -253,33 +253,6 @@ 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
-
283
256
  // src/events/goal.ts
284
257
  var buildGoalConvertMessage = (sessionId, visitorId, pageId, projectId, goalId, compositionData) => ({
285
258
  action: "goal_convert",
@@ -329,31 +302,6 @@ var buildPersonalizationResultMessage = (sessionId, visitorId, pageId, projectId
329
302
  uniform: compositionData || {}
330
303
  });
331
304
 
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
-
357
305
  // src/events/session.ts
358
306
  var buildSessionStartMessage = (sessionId, visitorId, pageId, projectId, previousSessionId, compositionData) => ({
359
307
  action: "session_start",
@@ -452,15 +400,6 @@ var createMemoryStorage = () => {
452
400
 
453
401
  // src/plugin.ts
454
402
  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
- }
464
403
  const {
465
404
  endpoint,
466
405
  storage: customStorage,
@@ -608,37 +547,6 @@ var createInsightsCore = (options) => {
608
547
  );
609
548
  addEvent(message);
610
549
  },
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
- },
642
550
  forget: () => {
643
551
  storage.clear();
644
552
  storageData = void 0;
@@ -655,7 +563,6 @@ var createInsightsPlugin = (options) => {
655
563
  let previousUrl = void 0;
656
564
  let isInitialized = false;
657
565
  let eventQueue = [];
658
- let contextInstance = void 0;
659
566
  const processQueuedEvents = () => {
660
567
  if (isInitialized && eventQueue.length > 0) {
661
568
  eventQueue.forEach((event) => event());
@@ -669,24 +576,12 @@ var createInsightsPlugin = (options) => {
669
576
  eventQueue.push(eventFn);
670
577
  }
671
578
  };
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
- };
683
579
  return {
684
580
  init: (context) => {
685
581
  if (typeof window === "undefined") {
686
582
  return () => {
687
583
  };
688
584
  }
689
- contextInstance = context;
690
585
  const consentChanged = () => {
691
586
  if (context.storage.data.consent) {
692
587
  insights.init(context).then(() => {
@@ -740,31 +635,13 @@ var createInsightsPlugin = (options) => {
740
635
  context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
741
636
  };
742
637
  },
743
- update: (updatedData, recalculatedScores) => {
744
- const compositionMetadata = updatedData.compositionMetadata ? convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata) : contextInstance ? convertUniformMetadataToInsightsMetadata(contextInstance.getCompositionMetadata()) : void 0;
638
+ update: (updatedData) => {
745
639
  if (updatedData.url && updatedData.url.toString() !== previousUrl) {
746
640
  previousUrl = updatedData.url.toString();
747
641
  queueEvent(() => {
748
642
  insights.pageHit(convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata));
749
643
  });
750
644
  }
751
- if (updatedData.enrichments && updatedData.enrichments.length > 0) {
752
- queueEvent(() => {
753
- updatedData.enrichments.forEach((enrichmentData) => {
754
- insights.enrichmentUpdated(
755
- enrichmentData.cat,
756
- enrichmentData.key,
757
- enrichmentData.str,
758
- compositionMetadata
759
- );
760
- });
761
- });
762
- }
763
- if (recalculatedScores) {
764
- queueEvent(() => {
765
- handleSegmentUpdates(recalculatedScores, compositionMetadata);
766
- });
767
- }
768
645
  },
769
646
  forget: () => {
770
647
  insights.forget();
package/dist/index.mjs CHANGED
@@ -217,33 +217,6 @@ 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
-
247
220
  // src/events/goal.ts
248
221
  var buildGoalConvertMessage = (sessionId, visitorId, pageId, projectId, goalId, compositionData) => ({
249
222
  action: "goal_convert",
@@ -293,31 +266,6 @@ var buildPersonalizationResultMessage = (sessionId, visitorId, pageId, projectId
293
266
  uniform: compositionData || {}
294
267
  });
295
268
 
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
-
321
269
  // src/events/session.ts
322
270
  var buildSessionStartMessage = (sessionId, visitorId, pageId, projectId, previousSessionId, compositionData) => ({
323
271
  action: "session_start",
@@ -416,15 +364,6 @@ var createMemoryStorage = () => {
416
364
 
417
365
  // src/plugin.ts
418
366
  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
- }
428
367
  const {
429
368
  endpoint,
430
369
  storage: customStorage,
@@ -572,37 +511,6 @@ var createInsightsCore = (options) => {
572
511
  );
573
512
  addEvent(message);
574
513
  },
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
- },
606
514
  forget: () => {
607
515
  storage.clear();
608
516
  storageData = void 0;
@@ -619,7 +527,6 @@ var createInsightsPlugin = (options) => {
619
527
  let previousUrl = void 0;
620
528
  let isInitialized = false;
621
529
  let eventQueue = [];
622
- let contextInstance = void 0;
623
530
  const processQueuedEvents = () => {
624
531
  if (isInitialized && eventQueue.length > 0) {
625
532
  eventQueue.forEach((event) => event());
@@ -633,24 +540,12 @@ var createInsightsPlugin = (options) => {
633
540
  eventQueue.push(eventFn);
634
541
  }
635
542
  };
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
- };
647
543
  return {
648
544
  init: (context) => {
649
545
  if (typeof window === "undefined") {
650
546
  return () => {
651
547
  };
652
548
  }
653
- contextInstance = context;
654
549
  const consentChanged = () => {
655
550
  if (context.storage.data.consent) {
656
551
  insights.init(context).then(() => {
@@ -704,31 +599,13 @@ var createInsightsPlugin = (options) => {
704
599
  context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
705
600
  };
706
601
  },
707
- update: (updatedData, recalculatedScores) => {
708
- const compositionMetadata = updatedData.compositionMetadata ? convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata) : contextInstance ? convertUniformMetadataToInsightsMetadata(contextInstance.getCompositionMetadata()) : void 0;
602
+ update: (updatedData) => {
709
603
  if (updatedData.url && updatedData.url.toString() !== previousUrl) {
710
604
  previousUrl = updatedData.url.toString();
711
605
  queueEvent(() => {
712
606
  insights.pageHit(convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata));
713
607
  });
714
608
  }
715
- if (updatedData.enrichments && updatedData.enrichments.length > 0) {
716
- queueEvent(() => {
717
- updatedData.enrichments.forEach((enrichmentData) => {
718
- insights.enrichmentUpdated(
719
- enrichmentData.cat,
720
- enrichmentData.key,
721
- enrichmentData.str,
722
- compositionMetadata
723
- );
724
- });
725
- });
726
- }
727
- if (recalculatedScores) {
728
- queueEvent(() => {
729
- handleSegmentUpdates(recalculatedScores, compositionMetadata);
730
- });
731
- }
732
609
  },
733
610
  forget: () => {
734
611
  insights.forget();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/insights",
3
- "version": "20.37.1-alpha.15+2338ab9fcc",
3
+ "version": "20.37.1-alpha.25+475e9928b9",
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.15+2338ab9fcc",
53
+ "@uniformdev/context": "20.37.1-alpha.25+475e9928b9",
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": "2338ab9fcc327bb23c4addbfedcd84dfb2ec257c"
62
+ "gitHead": "475e9928b9b05930fac4d7fa662cc54c4d21d51b"
63
63
  }