@uniformdev/insights 20.31.1-alpha.184 → 20.35.1-alpha.58
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 +144 -28
- package/dist/index.js +144 -28
- package/dist/index.mjs +144 -28
- 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
|
@@ -209,6 +209,40 @@ var generalRandomId = () => {
|
|
|
209
209
|
}
|
|
210
210
|
return Math.random().toString(32).substring(2);
|
|
211
211
|
};
|
|
212
|
+
var convertUniformMetadataToInsightsMetadata = (uniformMetadata) => {
|
|
213
|
+
return uniformMetadata ? {
|
|
214
|
+
composition_id: uniformMetadata.compositionId,
|
|
215
|
+
pm_node_path: uniformMetadata.matchedRoute,
|
|
216
|
+
dynamic_inputs: uniformMetadata.dynamicInputs
|
|
217
|
+
} : void 0;
|
|
218
|
+
};
|
|
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
|
+
});
|
|
212
246
|
|
|
213
247
|
// src/events/goal.ts
|
|
214
248
|
var buildGoalConvertMessage = (sessionId, visitorId, pageId, projectId, goalId, compositionData) => ({
|
|
@@ -259,6 +293,31 @@ var buildPersonalizationResultMessage = (sessionId, visitorId, pageId, projectId
|
|
|
259
293
|
uniform: compositionData || {}
|
|
260
294
|
});
|
|
261
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
|
+
|
|
262
321
|
// src/events/session.ts
|
|
263
322
|
var buildSessionStartMessage = (sessionId, visitorId, pageId, projectId, previousSessionId, compositionData) => ({
|
|
264
323
|
action: "session_start",
|
|
@@ -357,6 +416,15 @@ var createMemoryStorage = () => {
|
|
|
357
416
|
|
|
358
417
|
// src/plugin.ts
|
|
359
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
|
+
}
|
|
360
428
|
const {
|
|
361
429
|
endpoint,
|
|
362
430
|
storage: customStorage,
|
|
@@ -504,6 +572,37 @@ var createInsightsCore = (options) => {
|
|
|
504
572
|
);
|
|
505
573
|
addEvent(message);
|
|
506
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
|
+
},
|
|
507
606
|
forget: () => {
|
|
508
607
|
storage.clear();
|
|
509
608
|
storageData = void 0;
|
|
@@ -520,6 +619,7 @@ var createInsightsPlugin = (options) => {
|
|
|
520
619
|
let previousUrl = void 0;
|
|
521
620
|
let isInitialized = false;
|
|
522
621
|
let eventQueue = [];
|
|
622
|
+
let contextInstance = void 0;
|
|
523
623
|
const processQueuedEvents = () => {
|
|
524
624
|
if (isInitialized && eventQueue.length > 0) {
|
|
525
625
|
eventQueue.forEach((event) => event());
|
|
@@ -533,12 +633,24 @@ var createInsightsPlugin = (options) => {
|
|
|
533
633
|
eventQueue.push(eventFn);
|
|
534
634
|
}
|
|
535
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
|
+
};
|
|
536
647
|
return {
|
|
537
648
|
init: (context) => {
|
|
538
649
|
if (typeof window === "undefined") {
|
|
539
650
|
return () => {
|
|
540
651
|
};
|
|
541
652
|
}
|
|
653
|
+
contextInstance = context;
|
|
542
654
|
const consentChanged = () => {
|
|
543
655
|
if (context.storage.data.consent) {
|
|
544
656
|
insights.init(context).then(() => {
|
|
@@ -552,44 +664,27 @@ var createInsightsPlugin = (options) => {
|
|
|
552
664
|
};
|
|
553
665
|
const handlePersonalizationResult = (data) => {
|
|
554
666
|
queueEvent(() => {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
dynamic_inputs: (_c = data.compositionMetadata) == null ? void 0 : _c.dynamicInputs
|
|
560
|
-
});
|
|
667
|
+
insights.personalizationResult(
|
|
668
|
+
data,
|
|
669
|
+
convertUniformMetadataToInsightsMetadata(data.compositionMetadata)
|
|
670
|
+
);
|
|
561
671
|
});
|
|
562
672
|
};
|
|
563
673
|
const handleTestResult = (result) => {
|
|
564
674
|
queueEvent(() => {
|
|
565
|
-
insights.testResult(
|
|
566
|
-
result,
|
|
567
|
-
result.compositionMetadata ? {
|
|
568
|
-
composition_id: result.compositionMetadata.compositionId,
|
|
569
|
-
pm_node_path: result.compositionMetadata.matchedRoute,
|
|
570
|
-
dynamic_inputs: result.compositionMetadata.dynamicInputs
|
|
571
|
-
} : void 0
|
|
572
|
-
);
|
|
675
|
+
insights.testResult(result, convertUniformMetadataToInsightsMetadata(result.compositionMetadata));
|
|
573
676
|
});
|
|
574
677
|
};
|
|
575
678
|
const handleGoalConvert = (result) => {
|
|
576
679
|
const compositionMetadata = context.getCompositionMetadata();
|
|
577
680
|
queueEvent(() => {
|
|
578
|
-
insights.goalConvert(result.goalId,
|
|
579
|
-
composition_id: compositionMetadata == null ? void 0 : compositionMetadata.compositionId,
|
|
580
|
-
pm_node_path: compositionMetadata == null ? void 0 : compositionMetadata.matchedRoute,
|
|
581
|
-
dynamic_inputs: compositionMetadata == null ? void 0 : compositionMetadata.dynamicInputs
|
|
582
|
-
});
|
|
681
|
+
insights.goalConvert(result.goalId, convertUniformMetadataToInsightsMetadata(compositionMetadata));
|
|
583
682
|
});
|
|
584
683
|
};
|
|
585
684
|
const handleCanvasDataUpdated = (data) => {
|
|
586
685
|
if (data) {
|
|
587
686
|
queueEvent(() => {
|
|
588
|
-
insights.pageHit(
|
|
589
|
-
composition_id: data.compositionId,
|
|
590
|
-
pm_node_path: data.matchedRoute,
|
|
591
|
-
dynamic_inputs: data.dynamicInputs
|
|
592
|
-
});
|
|
687
|
+
insights.pageHit(convertUniformMetadataToInsightsMetadata(data));
|
|
593
688
|
});
|
|
594
689
|
}
|
|
595
690
|
};
|
|
@@ -609,11 +704,32 @@ var createInsightsPlugin = (options) => {
|
|
|
609
704
|
context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
|
|
610
705
|
};
|
|
611
706
|
},
|
|
612
|
-
update: (
|
|
613
|
-
|
|
614
|
-
|
|
707
|
+
update: (updatedData, recalculatedScores) => {
|
|
708
|
+
var _a;
|
|
709
|
+
const compositionMetadata = convertUniformMetadataToInsightsMetadata(
|
|
710
|
+
(_a = updatedData.compositionMetadata) != null ? _a : contextInstance == null ? void 0 : contextInstance.getCompositionMetadata()
|
|
711
|
+
);
|
|
712
|
+
if (updatedData.url && updatedData.url.toString() !== previousUrl) {
|
|
713
|
+
previousUrl = updatedData.url.toString();
|
|
714
|
+
queueEvent(() => {
|
|
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) {
|
|
615
731
|
queueEvent(() => {
|
|
616
|
-
|
|
732
|
+
handleSegmentUpdates(recalculatedScores, compositionMetadata);
|
|
617
733
|
});
|
|
618
734
|
}
|
|
619
735
|
},
|
package/dist/index.js
CHANGED
|
@@ -245,6 +245,40 @@ var generalRandomId = () => {
|
|
|
245
245
|
}
|
|
246
246
|
return Math.random().toString(32).substring(2);
|
|
247
247
|
};
|
|
248
|
+
var convertUniformMetadataToInsightsMetadata = (uniformMetadata) => {
|
|
249
|
+
return uniformMetadata ? {
|
|
250
|
+
composition_id: uniformMetadata.compositionId,
|
|
251
|
+
pm_node_path: uniformMetadata.matchedRoute,
|
|
252
|
+
dynamic_inputs: uniformMetadata.dynamicInputs
|
|
253
|
+
} : void 0;
|
|
254
|
+
};
|
|
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
|
+
});
|
|
248
282
|
|
|
249
283
|
// src/events/goal.ts
|
|
250
284
|
var buildGoalConvertMessage = (sessionId, visitorId, pageId, projectId, goalId, compositionData) => ({
|
|
@@ -295,6 +329,31 @@ var buildPersonalizationResultMessage = (sessionId, visitorId, pageId, projectId
|
|
|
295
329
|
uniform: compositionData || {}
|
|
296
330
|
});
|
|
297
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
|
+
|
|
298
357
|
// src/events/session.ts
|
|
299
358
|
var buildSessionStartMessage = (sessionId, visitorId, pageId, projectId, previousSessionId, compositionData) => ({
|
|
300
359
|
action: "session_start",
|
|
@@ -393,6 +452,15 @@ var createMemoryStorage = () => {
|
|
|
393
452
|
|
|
394
453
|
// src/plugin.ts
|
|
395
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
|
+
}
|
|
396
464
|
const {
|
|
397
465
|
endpoint,
|
|
398
466
|
storage: customStorage,
|
|
@@ -540,6 +608,37 @@ var createInsightsCore = (options) => {
|
|
|
540
608
|
);
|
|
541
609
|
addEvent(message);
|
|
542
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
|
+
},
|
|
543
642
|
forget: () => {
|
|
544
643
|
storage.clear();
|
|
545
644
|
storageData = void 0;
|
|
@@ -556,6 +655,7 @@ var createInsightsPlugin = (options) => {
|
|
|
556
655
|
let previousUrl = void 0;
|
|
557
656
|
let isInitialized = false;
|
|
558
657
|
let eventQueue = [];
|
|
658
|
+
let contextInstance = void 0;
|
|
559
659
|
const processQueuedEvents = () => {
|
|
560
660
|
if (isInitialized && eventQueue.length > 0) {
|
|
561
661
|
eventQueue.forEach((event) => event());
|
|
@@ -569,12 +669,24 @@ var createInsightsPlugin = (options) => {
|
|
|
569
669
|
eventQueue.push(eventFn);
|
|
570
670
|
}
|
|
571
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
|
+
};
|
|
572
683
|
return {
|
|
573
684
|
init: (context) => {
|
|
574
685
|
if (typeof window === "undefined") {
|
|
575
686
|
return () => {
|
|
576
687
|
};
|
|
577
688
|
}
|
|
689
|
+
contextInstance = context;
|
|
578
690
|
const consentChanged = () => {
|
|
579
691
|
if (context.storage.data.consent) {
|
|
580
692
|
insights.init(context).then(() => {
|
|
@@ -588,44 +700,27 @@ var createInsightsPlugin = (options) => {
|
|
|
588
700
|
};
|
|
589
701
|
const handlePersonalizationResult = (data) => {
|
|
590
702
|
queueEvent(() => {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
dynamic_inputs: (_c = data.compositionMetadata) == null ? void 0 : _c.dynamicInputs
|
|
596
|
-
});
|
|
703
|
+
insights.personalizationResult(
|
|
704
|
+
data,
|
|
705
|
+
convertUniformMetadataToInsightsMetadata(data.compositionMetadata)
|
|
706
|
+
);
|
|
597
707
|
});
|
|
598
708
|
};
|
|
599
709
|
const handleTestResult = (result) => {
|
|
600
710
|
queueEvent(() => {
|
|
601
|
-
insights.testResult(
|
|
602
|
-
result,
|
|
603
|
-
result.compositionMetadata ? {
|
|
604
|
-
composition_id: result.compositionMetadata.compositionId,
|
|
605
|
-
pm_node_path: result.compositionMetadata.matchedRoute,
|
|
606
|
-
dynamic_inputs: result.compositionMetadata.dynamicInputs
|
|
607
|
-
} : void 0
|
|
608
|
-
);
|
|
711
|
+
insights.testResult(result, convertUniformMetadataToInsightsMetadata(result.compositionMetadata));
|
|
609
712
|
});
|
|
610
713
|
};
|
|
611
714
|
const handleGoalConvert = (result) => {
|
|
612
715
|
const compositionMetadata = context.getCompositionMetadata();
|
|
613
716
|
queueEvent(() => {
|
|
614
|
-
insights.goalConvert(result.goalId,
|
|
615
|
-
composition_id: compositionMetadata == null ? void 0 : compositionMetadata.compositionId,
|
|
616
|
-
pm_node_path: compositionMetadata == null ? void 0 : compositionMetadata.matchedRoute,
|
|
617
|
-
dynamic_inputs: compositionMetadata == null ? void 0 : compositionMetadata.dynamicInputs
|
|
618
|
-
});
|
|
717
|
+
insights.goalConvert(result.goalId, convertUniformMetadataToInsightsMetadata(compositionMetadata));
|
|
619
718
|
});
|
|
620
719
|
};
|
|
621
720
|
const handleCanvasDataUpdated = (data) => {
|
|
622
721
|
if (data) {
|
|
623
722
|
queueEvent(() => {
|
|
624
|
-
insights.pageHit(
|
|
625
|
-
composition_id: data.compositionId,
|
|
626
|
-
pm_node_path: data.matchedRoute,
|
|
627
|
-
dynamic_inputs: data.dynamicInputs
|
|
628
|
-
});
|
|
723
|
+
insights.pageHit(convertUniformMetadataToInsightsMetadata(data));
|
|
629
724
|
});
|
|
630
725
|
}
|
|
631
726
|
};
|
|
@@ -645,11 +740,32 @@ var createInsightsPlugin = (options) => {
|
|
|
645
740
|
context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
|
|
646
741
|
};
|
|
647
742
|
},
|
|
648
|
-
update: (
|
|
649
|
-
|
|
650
|
-
|
|
743
|
+
update: (updatedData, recalculatedScores) => {
|
|
744
|
+
var _a;
|
|
745
|
+
const compositionMetadata = convertUniformMetadataToInsightsMetadata(
|
|
746
|
+
(_a = updatedData.compositionMetadata) != null ? _a : contextInstance == null ? void 0 : contextInstance.getCompositionMetadata()
|
|
747
|
+
);
|
|
748
|
+
if (updatedData.url && updatedData.url.toString() !== previousUrl) {
|
|
749
|
+
previousUrl = updatedData.url.toString();
|
|
750
|
+
queueEvent(() => {
|
|
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) {
|
|
651
767
|
queueEvent(() => {
|
|
652
|
-
|
|
768
|
+
handleSegmentUpdates(recalculatedScores, compositionMetadata);
|
|
653
769
|
});
|
|
654
770
|
}
|
|
655
771
|
},
|
package/dist/index.mjs
CHANGED
|
@@ -209,6 +209,40 @@ var generalRandomId = () => {
|
|
|
209
209
|
}
|
|
210
210
|
return Math.random().toString(32).substring(2);
|
|
211
211
|
};
|
|
212
|
+
var convertUniformMetadataToInsightsMetadata = (uniformMetadata) => {
|
|
213
|
+
return uniformMetadata ? {
|
|
214
|
+
composition_id: uniformMetadata.compositionId,
|
|
215
|
+
pm_node_path: uniformMetadata.matchedRoute,
|
|
216
|
+
dynamic_inputs: uniformMetadata.dynamicInputs
|
|
217
|
+
} : void 0;
|
|
218
|
+
};
|
|
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
|
+
});
|
|
212
246
|
|
|
213
247
|
// src/events/goal.ts
|
|
214
248
|
var buildGoalConvertMessage = (sessionId, visitorId, pageId, projectId, goalId, compositionData) => ({
|
|
@@ -259,6 +293,31 @@ var buildPersonalizationResultMessage = (sessionId, visitorId, pageId, projectId
|
|
|
259
293
|
uniform: compositionData || {}
|
|
260
294
|
});
|
|
261
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
|
+
|
|
262
321
|
// src/events/session.ts
|
|
263
322
|
var buildSessionStartMessage = (sessionId, visitorId, pageId, projectId, previousSessionId, compositionData) => ({
|
|
264
323
|
action: "session_start",
|
|
@@ -357,6 +416,15 @@ var createMemoryStorage = () => {
|
|
|
357
416
|
|
|
358
417
|
// src/plugin.ts
|
|
359
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
|
+
}
|
|
360
428
|
const {
|
|
361
429
|
endpoint,
|
|
362
430
|
storage: customStorage,
|
|
@@ -504,6 +572,37 @@ var createInsightsCore = (options) => {
|
|
|
504
572
|
);
|
|
505
573
|
addEvent(message);
|
|
506
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
|
+
},
|
|
507
606
|
forget: () => {
|
|
508
607
|
storage.clear();
|
|
509
608
|
storageData = void 0;
|
|
@@ -520,6 +619,7 @@ var createInsightsPlugin = (options) => {
|
|
|
520
619
|
let previousUrl = void 0;
|
|
521
620
|
let isInitialized = false;
|
|
522
621
|
let eventQueue = [];
|
|
622
|
+
let contextInstance = void 0;
|
|
523
623
|
const processQueuedEvents = () => {
|
|
524
624
|
if (isInitialized && eventQueue.length > 0) {
|
|
525
625
|
eventQueue.forEach((event) => event());
|
|
@@ -533,12 +633,24 @@ var createInsightsPlugin = (options) => {
|
|
|
533
633
|
eventQueue.push(eventFn);
|
|
534
634
|
}
|
|
535
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
|
+
};
|
|
536
647
|
return {
|
|
537
648
|
init: (context) => {
|
|
538
649
|
if (typeof window === "undefined") {
|
|
539
650
|
return () => {
|
|
540
651
|
};
|
|
541
652
|
}
|
|
653
|
+
contextInstance = context;
|
|
542
654
|
const consentChanged = () => {
|
|
543
655
|
if (context.storage.data.consent) {
|
|
544
656
|
insights.init(context).then(() => {
|
|
@@ -552,44 +664,27 @@ var createInsightsPlugin = (options) => {
|
|
|
552
664
|
};
|
|
553
665
|
const handlePersonalizationResult = (data) => {
|
|
554
666
|
queueEvent(() => {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
dynamic_inputs: (_c = data.compositionMetadata) == null ? void 0 : _c.dynamicInputs
|
|
560
|
-
});
|
|
667
|
+
insights.personalizationResult(
|
|
668
|
+
data,
|
|
669
|
+
convertUniformMetadataToInsightsMetadata(data.compositionMetadata)
|
|
670
|
+
);
|
|
561
671
|
});
|
|
562
672
|
};
|
|
563
673
|
const handleTestResult = (result) => {
|
|
564
674
|
queueEvent(() => {
|
|
565
|
-
insights.testResult(
|
|
566
|
-
result,
|
|
567
|
-
result.compositionMetadata ? {
|
|
568
|
-
composition_id: result.compositionMetadata.compositionId,
|
|
569
|
-
pm_node_path: result.compositionMetadata.matchedRoute,
|
|
570
|
-
dynamic_inputs: result.compositionMetadata.dynamicInputs
|
|
571
|
-
} : void 0
|
|
572
|
-
);
|
|
675
|
+
insights.testResult(result, convertUniformMetadataToInsightsMetadata(result.compositionMetadata));
|
|
573
676
|
});
|
|
574
677
|
};
|
|
575
678
|
const handleGoalConvert = (result) => {
|
|
576
679
|
const compositionMetadata = context.getCompositionMetadata();
|
|
577
680
|
queueEvent(() => {
|
|
578
|
-
insights.goalConvert(result.goalId,
|
|
579
|
-
composition_id: compositionMetadata == null ? void 0 : compositionMetadata.compositionId,
|
|
580
|
-
pm_node_path: compositionMetadata == null ? void 0 : compositionMetadata.matchedRoute,
|
|
581
|
-
dynamic_inputs: compositionMetadata == null ? void 0 : compositionMetadata.dynamicInputs
|
|
582
|
-
});
|
|
681
|
+
insights.goalConvert(result.goalId, convertUniformMetadataToInsightsMetadata(compositionMetadata));
|
|
583
682
|
});
|
|
584
683
|
};
|
|
585
684
|
const handleCanvasDataUpdated = (data) => {
|
|
586
685
|
if (data) {
|
|
587
686
|
queueEvent(() => {
|
|
588
|
-
insights.pageHit(
|
|
589
|
-
composition_id: data.compositionId,
|
|
590
|
-
pm_node_path: data.matchedRoute,
|
|
591
|
-
dynamic_inputs: data.dynamicInputs
|
|
592
|
-
});
|
|
687
|
+
insights.pageHit(convertUniformMetadataToInsightsMetadata(data));
|
|
593
688
|
});
|
|
594
689
|
}
|
|
595
690
|
};
|
|
@@ -609,11 +704,32 @@ var createInsightsPlugin = (options) => {
|
|
|
609
704
|
context.events.off("canvasDataUpdated", handleCanvasDataUpdated);
|
|
610
705
|
};
|
|
611
706
|
},
|
|
612
|
-
update: (
|
|
613
|
-
|
|
614
|
-
|
|
707
|
+
update: (updatedData, recalculatedScores) => {
|
|
708
|
+
var _a;
|
|
709
|
+
const compositionMetadata = convertUniformMetadataToInsightsMetadata(
|
|
710
|
+
(_a = updatedData.compositionMetadata) != null ? _a : contextInstance == null ? void 0 : contextInstance.getCompositionMetadata()
|
|
711
|
+
);
|
|
712
|
+
if (updatedData.url && updatedData.url.toString() !== previousUrl) {
|
|
713
|
+
previousUrl = updatedData.url.toString();
|
|
714
|
+
queueEvent(() => {
|
|
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) {
|
|
615
731
|
queueEvent(() => {
|
|
616
|
-
|
|
732
|
+
handleSegmentUpdates(recalculatedScores, compositionMetadata);
|
|
617
733
|
});
|
|
618
734
|
}
|
|
619
735
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/insights",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.35.1-alpha.58+f229d40de4",
|
|
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.
|
|
53
|
+
"@uniformdev/context": "20.35.1-alpha.58+f229d40de4",
|
|
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": "f229d40de49a1a7e2bba9d2e0a36d4aae6251c81"
|
|
63
63
|
}
|