@coframe/sdk 1.1.7 → 1.1.8
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/pkg/cf.cjs.js +38 -32
- package/dist/pkg/cf.esm.mjs +38 -32
- package/package.json +1 -1
package/dist/pkg/cf.cjs.js
CHANGED
|
@@ -1028,20 +1028,9 @@ function queueVariantViewEvent(coframe, { projectId, sessionId, orgId, userToken
|
|
|
1028
1028
|
user_token: userToken,
|
|
1029
1029
|
});
|
|
1030
1030
|
}
|
|
1031
|
-
function sendPageEngagementEvent(coframe, eventType, event, {
|
|
1031
|
+
function sendPageEngagementEvent(coframe, eventType, event, { projectId, sessionId, duration = 0, userToken, personalizationHeaders, }) {
|
|
1032
1032
|
var _a;
|
|
1033
1033
|
const startTime = performance.now();
|
|
1034
|
-
if (!isEngaged && eventType === 'click') {
|
|
1035
|
-
isEngaged = true;
|
|
1036
|
-
queueEvent(coframe, {
|
|
1037
|
-
projectId,
|
|
1038
|
-
sessionId,
|
|
1039
|
-
eventType: 'session_start',
|
|
1040
|
-
orgId,
|
|
1041
|
-
userToken: userToken || '',
|
|
1042
|
-
personalizationHeaders,
|
|
1043
|
-
});
|
|
1044
|
-
}
|
|
1045
1034
|
const x = event.clientX + window.scrollX;
|
|
1046
1035
|
const y = event.clientY + window.scrollY;
|
|
1047
1036
|
const screenWidth = window.innerWidth;
|
|
@@ -3026,22 +3015,39 @@ const ENGAGED_SESSION_THRESHOLD = 10000;
|
|
|
3026
3015
|
function setupListeners(Coframe, executionStartTime) {
|
|
3027
3016
|
const experiencedCoframeIds = new Set();
|
|
3028
3017
|
let isEngaged = false;
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
if (
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
orgId: Coframe.orgId,
|
|
3038
|
-
userToken: Coframe.userToken,
|
|
3039
|
-
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3040
|
-
});
|
|
3018
|
+
let engagementTimer = null;
|
|
3019
|
+
function markEngaged() {
|
|
3020
|
+
if (isEngaged)
|
|
3021
|
+
return;
|
|
3022
|
+
isEngaged = true;
|
|
3023
|
+
if (engagementTimer !== null) {
|
|
3024
|
+
clearTimeout(engagementTimer);
|
|
3025
|
+
engagementTimer = null;
|
|
3041
3026
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
3027
|
+
queueEvent(Coframe, {
|
|
3028
|
+
projectId: Coframe.projectId,
|
|
3029
|
+
sessionId: Coframe.sessionId,
|
|
3030
|
+
eventType: 'session_start',
|
|
3031
|
+
orgId: Coframe.orgId,
|
|
3032
|
+
userToken: Coframe.userToken,
|
|
3033
|
+
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3034
|
+
});
|
|
3035
|
+
}
|
|
3036
|
+
function scheduleEngagementMeasurement() {
|
|
3037
|
+
if (isEngaged)
|
|
3038
|
+
return;
|
|
3039
|
+
const timeSpent = Date.now() - (executionStartTime ? executionStartTime.getTime() : 0);
|
|
3040
|
+
const remaining = ENGAGED_SESSION_THRESHOLD - timeSpent;
|
|
3041
|
+
if (remaining <= 0) {
|
|
3042
|
+
markEngaged();
|
|
3043
|
+
return;
|
|
3044
3044
|
}
|
|
3045
|
+
if (engagementTimer !== null)
|
|
3046
|
+
return;
|
|
3047
|
+
engagementTimer = setTimeout(() => {
|
|
3048
|
+
engagementTimer = null;
|
|
3049
|
+
scheduleEngagementMeasurement();
|
|
3050
|
+
}, remaining);
|
|
3045
3051
|
}
|
|
3046
3052
|
function updateViewedVariants() {
|
|
3047
3053
|
for (const variantElement of Coframe.variantsAndElements || []) {
|
|
@@ -3065,21 +3071,21 @@ function setupListeners(Coframe, executionStartTime) {
|
|
|
3065
3071
|
}
|
|
3066
3072
|
}
|
|
3067
3073
|
}
|
|
3068
|
-
document.addEventListener('visibilitychange',
|
|
3069
|
-
|
|
3074
|
+
document.addEventListener('visibilitychange', scheduleEngagementMeasurement);
|
|
3075
|
+
scheduleEngagementMeasurement();
|
|
3070
3076
|
document.addEventListener('coframe:dom-renderer:complete', updateViewedVariants);
|
|
3071
3077
|
document.addEventListener('scroll', updateViewedVariants);
|
|
3072
3078
|
document.dispatchEvent(new CustomEvent('coframe:dom-renderer:complete', {}));
|
|
3073
|
-
|
|
3079
|
+
const handleClick = (event) => {
|
|
3080
|
+
markEngaged();
|
|
3074
3081
|
sendPageEngagementEvent(Coframe, 'click', event, {
|
|
3075
3082
|
projectId: Coframe.projectId,
|
|
3076
|
-
isEngaged,
|
|
3077
3083
|
sessionId: Coframe.sessionId,
|
|
3078
|
-
orgId: Coframe.orgId,
|
|
3079
3084
|
userToken: Coframe.userToken,
|
|
3080
3085
|
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3081
3086
|
});
|
|
3082
|
-
}
|
|
3087
|
+
};
|
|
3088
|
+
document.addEventListener('click', handleClick, true);
|
|
3083
3089
|
const handleEventFlush = debounce((eventType) => {
|
|
3084
3090
|
queueEvent(Coframe, {
|
|
3085
3091
|
projectId: Coframe.projectId,
|
package/dist/pkg/cf.esm.mjs
CHANGED
|
@@ -1026,20 +1026,9 @@ function queueVariantViewEvent(coframe, { projectId, sessionId, orgId, userToken
|
|
|
1026
1026
|
user_token: userToken,
|
|
1027
1027
|
});
|
|
1028
1028
|
}
|
|
1029
|
-
function sendPageEngagementEvent(coframe, eventType, event, {
|
|
1029
|
+
function sendPageEngagementEvent(coframe, eventType, event, { projectId, sessionId, duration = 0, userToken, personalizationHeaders, }) {
|
|
1030
1030
|
var _a;
|
|
1031
1031
|
const startTime = performance.now();
|
|
1032
|
-
if (!isEngaged && eventType === 'click') {
|
|
1033
|
-
isEngaged = true;
|
|
1034
|
-
queueEvent(coframe, {
|
|
1035
|
-
projectId,
|
|
1036
|
-
sessionId,
|
|
1037
|
-
eventType: 'session_start',
|
|
1038
|
-
orgId,
|
|
1039
|
-
userToken: userToken || '',
|
|
1040
|
-
personalizationHeaders,
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
1032
|
const x = event.clientX + window.scrollX;
|
|
1044
1033
|
const y = event.clientY + window.scrollY;
|
|
1045
1034
|
const screenWidth = window.innerWidth;
|
|
@@ -3024,22 +3013,39 @@ const ENGAGED_SESSION_THRESHOLD = 10000;
|
|
|
3024
3013
|
function setupListeners(Coframe, executionStartTime) {
|
|
3025
3014
|
const experiencedCoframeIds = new Set();
|
|
3026
3015
|
let isEngaged = false;
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
if (
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
orgId: Coframe.orgId,
|
|
3036
|
-
userToken: Coframe.userToken,
|
|
3037
|
-
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3038
|
-
});
|
|
3016
|
+
let engagementTimer = null;
|
|
3017
|
+
function markEngaged() {
|
|
3018
|
+
if (isEngaged)
|
|
3019
|
+
return;
|
|
3020
|
+
isEngaged = true;
|
|
3021
|
+
if (engagementTimer !== null) {
|
|
3022
|
+
clearTimeout(engagementTimer);
|
|
3023
|
+
engagementTimer = null;
|
|
3039
3024
|
}
|
|
3040
|
-
|
|
3041
|
-
|
|
3025
|
+
queueEvent(Coframe, {
|
|
3026
|
+
projectId: Coframe.projectId,
|
|
3027
|
+
sessionId: Coframe.sessionId,
|
|
3028
|
+
eventType: 'session_start',
|
|
3029
|
+
orgId: Coframe.orgId,
|
|
3030
|
+
userToken: Coframe.userToken,
|
|
3031
|
+
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3032
|
+
});
|
|
3033
|
+
}
|
|
3034
|
+
function scheduleEngagementMeasurement() {
|
|
3035
|
+
if (isEngaged)
|
|
3036
|
+
return;
|
|
3037
|
+
const timeSpent = Date.now() - (executionStartTime ? executionStartTime.getTime() : 0);
|
|
3038
|
+
const remaining = ENGAGED_SESSION_THRESHOLD - timeSpent;
|
|
3039
|
+
if (remaining <= 0) {
|
|
3040
|
+
markEngaged();
|
|
3041
|
+
return;
|
|
3042
3042
|
}
|
|
3043
|
+
if (engagementTimer !== null)
|
|
3044
|
+
return;
|
|
3045
|
+
engagementTimer = setTimeout(() => {
|
|
3046
|
+
engagementTimer = null;
|
|
3047
|
+
scheduleEngagementMeasurement();
|
|
3048
|
+
}, remaining);
|
|
3043
3049
|
}
|
|
3044
3050
|
function updateViewedVariants() {
|
|
3045
3051
|
for (const variantElement of Coframe.variantsAndElements || []) {
|
|
@@ -3063,21 +3069,21 @@ function setupListeners(Coframe, executionStartTime) {
|
|
|
3063
3069
|
}
|
|
3064
3070
|
}
|
|
3065
3071
|
}
|
|
3066
|
-
document.addEventListener('visibilitychange',
|
|
3067
|
-
|
|
3072
|
+
document.addEventListener('visibilitychange', scheduleEngagementMeasurement);
|
|
3073
|
+
scheduleEngagementMeasurement();
|
|
3068
3074
|
document.addEventListener('coframe:dom-renderer:complete', updateViewedVariants);
|
|
3069
3075
|
document.addEventListener('scroll', updateViewedVariants);
|
|
3070
3076
|
document.dispatchEvent(new CustomEvent('coframe:dom-renderer:complete', {}));
|
|
3071
|
-
|
|
3077
|
+
const handleClick = (event) => {
|
|
3078
|
+
markEngaged();
|
|
3072
3079
|
sendPageEngagementEvent(Coframe, 'click', event, {
|
|
3073
3080
|
projectId: Coframe.projectId,
|
|
3074
|
-
isEngaged,
|
|
3075
3081
|
sessionId: Coframe.sessionId,
|
|
3076
|
-
orgId: Coframe.orgId,
|
|
3077
3082
|
userToken: Coframe.userToken,
|
|
3078
3083
|
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3079
3084
|
});
|
|
3080
|
-
}
|
|
3085
|
+
};
|
|
3086
|
+
document.addEventListener('click', handleClick, true);
|
|
3081
3087
|
const handleEventFlush = debounce((eventType) => {
|
|
3082
3088
|
queueEvent(Coframe, {
|
|
3083
3089
|
projectId: Coframe.projectId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coframe/sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Coframe optimizes your website using generative AI to deliver maximum impact to your audience and allow your site to improve itself as you sleep. Learn more at coframe.com.",
|
|
5
5
|
"main": "dist/pkg/cf.cjs.js",
|
|
6
6
|
"module": "dist/pkg/cf.esm.mjs",
|