@uniformdev/insights 20.37.1-alpha.11 → 20.37.1-alpha.15
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 +124 -1
- package/dist/index.js +124 -1
- package/dist/index.mjs +124 -1
- package/package.json +3 -3
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,13 +704,31 @@ var createInsightsPlugin = (options) => {
|
|
|
599
704
|
context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
|
|
600
705
|
};
|
|
601
706
|
},
|
|
602
|
-
update: (updatedData) => {
|
|
707
|
+
update: (updatedData, recalculatedScores) => {
|
|
708
|
+
const compositionMetadata = updatedData.compositionMetadata ? convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata) : contextInstance ? convertUniformMetadataToInsightsMetadata(contextInstance.getCompositionMetadata()) : void 0;
|
|
603
709
|
if (updatedData.url && updatedData.url.toString() !== previousUrl) {
|
|
604
710
|
previousUrl = updatedData.url.toString();
|
|
605
711
|
queueEvent(() => {
|
|
606
712
|
insights.pageHit(convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata));
|
|
607
713
|
});
|
|
608
714
|
}
|
|
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
|
+
}
|
|
609
732
|
},
|
|
610
733
|
forget: () => {
|
|
611
734
|
insights.forget();
|
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,13 +740,31 @@ var createInsightsPlugin = (options) => {
|
|
|
635
740
|
context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
|
|
636
741
|
};
|
|
637
742
|
},
|
|
638
|
-
update: (updatedData) => {
|
|
743
|
+
update: (updatedData, recalculatedScores) => {
|
|
744
|
+
const compositionMetadata = updatedData.compositionMetadata ? convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata) : contextInstance ? convertUniformMetadataToInsightsMetadata(contextInstance.getCompositionMetadata()) : void 0;
|
|
639
745
|
if (updatedData.url && updatedData.url.toString() !== previousUrl) {
|
|
640
746
|
previousUrl = updatedData.url.toString();
|
|
641
747
|
queueEvent(() => {
|
|
642
748
|
insights.pageHit(convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata));
|
|
643
749
|
});
|
|
644
750
|
}
|
|
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
|
+
}
|
|
645
768
|
},
|
|
646
769
|
forget: () => {
|
|
647
770
|
insights.forget();
|
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,13 +704,31 @@ var createInsightsPlugin = (options) => {
|
|
|
599
704
|
context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
|
|
600
705
|
};
|
|
601
706
|
},
|
|
602
|
-
update: (updatedData) => {
|
|
707
|
+
update: (updatedData, recalculatedScores) => {
|
|
708
|
+
const compositionMetadata = updatedData.compositionMetadata ? convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata) : contextInstance ? convertUniformMetadataToInsightsMetadata(contextInstance.getCompositionMetadata()) : void 0;
|
|
603
709
|
if (updatedData.url && updatedData.url.toString() !== previousUrl) {
|
|
604
710
|
previousUrl = updatedData.url.toString();
|
|
605
711
|
queueEvent(() => {
|
|
606
712
|
insights.pageHit(convertUniformMetadataToInsightsMetadata(updatedData.compositionMetadata));
|
|
607
713
|
});
|
|
608
714
|
}
|
|
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
|
+
}
|
|
609
732
|
},
|
|
610
733
|
forget: () => {
|
|
611
734
|
insights.forget();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/insights",
|
|
3
|
-
"version": "20.37.1-alpha.
|
|
3
|
+
"version": "20.37.1-alpha.15+2338ab9fcc",
|
|
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.
|
|
53
|
+
"@uniformdev/context": "20.37.1-alpha.15+2338ab9fcc",
|
|
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": "
|
|
62
|
+
"gitHead": "2338ab9fcc327bb23c4addbfedcd84dfb2ec257c"
|
|
63
63
|
}
|