@coframe/sdk 1.1.6 → 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 +57 -40
- package/dist/pkg/cf.esm.mjs +57 -40
- package/package.json +1 -1
package/dist/pkg/cf.cjs.js
CHANGED
|
@@ -926,7 +926,7 @@ function warnEventsNotSent() {
|
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
928
|
|
|
929
|
-
const SDK_VERSION = '2.
|
|
929
|
+
const SDK_VERSION = '2.5.0';
|
|
930
930
|
const queuedEvents = [];
|
|
931
931
|
const queuedMonitoringEvents = [];
|
|
932
932
|
const queuedSessions = [];
|
|
@@ -1016,20 +1016,21 @@ function queueEvent(coframe, sessionInfo) {
|
|
|
1016
1016
|
}
|
|
1017
1017
|
queueEventForBatchedSending(coframe, data);
|
|
1018
1018
|
}
|
|
1019
|
-
function
|
|
1019
|
+
function queueVariantViewEvent(coframe, { projectId, sessionId, orgId, userToken, experimentId, variantId, }) {
|
|
1020
|
+
queueEventForBatchedSending(coframe, {
|
|
1021
|
+
type: 'view',
|
|
1022
|
+
project_id: projectId,
|
|
1023
|
+
session_id: sessionId,
|
|
1024
|
+
experiment_id: experimentId,
|
|
1025
|
+
variant_id: variantId,
|
|
1026
|
+
time: new Date(),
|
|
1027
|
+
org_id: orgId,
|
|
1028
|
+
user_token: userToken,
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
function sendPageEngagementEvent(coframe, eventType, event, { projectId, sessionId, duration = 0, userToken, personalizationHeaders, }) {
|
|
1020
1032
|
var _a;
|
|
1021
1033
|
const startTime = performance.now();
|
|
1022
|
-
if (!isEngaged && eventType === 'click') {
|
|
1023
|
-
isEngaged = true;
|
|
1024
|
-
queueEvent(coframe, {
|
|
1025
|
-
projectId,
|
|
1026
|
-
sessionId,
|
|
1027
|
-
eventType: 'session_start',
|
|
1028
|
-
orgId,
|
|
1029
|
-
userToken: userToken || '',
|
|
1030
|
-
personalizationHeaders,
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
1034
|
const x = event.clientX + window.scrollX;
|
|
1034
1035
|
const y = event.clientY + window.scrollY;
|
|
1035
1036
|
const screenWidth = window.innerWidth;
|
|
@@ -3014,22 +3015,39 @@ const ENGAGED_SESSION_THRESHOLD = 10000;
|
|
|
3014
3015
|
function setupListeners(Coframe, executionStartTime) {
|
|
3015
3016
|
const experiencedCoframeIds = new Set();
|
|
3016
3017
|
let isEngaged = false;
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
if (
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
orgId: Coframe.orgId,
|
|
3026
|
-
userToken: Coframe.userToken,
|
|
3027
|
-
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3028
|
-
});
|
|
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;
|
|
3029
3026
|
}
|
|
3030
|
-
|
|
3031
|
-
|
|
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;
|
|
3032
3044
|
}
|
|
3045
|
+
if (engagementTimer !== null)
|
|
3046
|
+
return;
|
|
3047
|
+
engagementTimer = setTimeout(() => {
|
|
3048
|
+
engagementTimer = null;
|
|
3049
|
+
scheduleEngagementMeasurement();
|
|
3050
|
+
}, remaining);
|
|
3033
3051
|
}
|
|
3034
3052
|
function updateViewedVariants() {
|
|
3035
3053
|
for (const variantElement of Coframe.variantsAndElements || []) {
|
|
@@ -3040,35 +3058,34 @@ function setupListeners(Coframe, executionStartTime) {
|
|
|
3040
3058
|
if (isElementVisible(el)) {
|
|
3041
3059
|
el.setAttribute('coframe-experienced', 'true');
|
|
3042
3060
|
experiencedCoframeIds.add(variant.id);
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
session_id: Coframe.sessionId,
|
|
3047
|
-
experiment_id: variant.experiment_id,
|
|
3048
|
-
variant_id: variant.id,
|
|
3049
|
-
time: new Date(),
|
|
3061
|
+
queueVariantViewEvent(Coframe, {
|
|
3062
|
+
projectId: Coframe.projectId,
|
|
3063
|
+
sessionId: Coframe.sessionId,
|
|
3050
3064
|
orgId: Coframe.orgId,
|
|
3065
|
+
userToken: Coframe.userToken,
|
|
3066
|
+
experimentId: variant.experiment_id,
|
|
3067
|
+
variantId: variant.id,
|
|
3051
3068
|
});
|
|
3052
3069
|
}
|
|
3053
3070
|
}
|
|
3054
3071
|
}
|
|
3055
3072
|
}
|
|
3056
3073
|
}
|
|
3057
|
-
document.addEventListener('visibilitychange',
|
|
3058
|
-
|
|
3074
|
+
document.addEventListener('visibilitychange', scheduleEngagementMeasurement);
|
|
3075
|
+
scheduleEngagementMeasurement();
|
|
3059
3076
|
document.addEventListener('coframe:dom-renderer:complete', updateViewedVariants);
|
|
3060
3077
|
document.addEventListener('scroll', updateViewedVariants);
|
|
3061
3078
|
document.dispatchEvent(new CustomEvent('coframe:dom-renderer:complete', {}));
|
|
3062
|
-
|
|
3079
|
+
const handleClick = (event) => {
|
|
3080
|
+
markEngaged();
|
|
3063
3081
|
sendPageEngagementEvent(Coframe, 'click', event, {
|
|
3064
3082
|
projectId: Coframe.projectId,
|
|
3065
|
-
isEngaged,
|
|
3066
3083
|
sessionId: Coframe.sessionId,
|
|
3067
|
-
orgId: Coframe.orgId,
|
|
3068
3084
|
userToken: Coframe.userToken,
|
|
3069
3085
|
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3070
3086
|
});
|
|
3071
|
-
}
|
|
3087
|
+
};
|
|
3088
|
+
document.addEventListener('click', handleClick, true);
|
|
3072
3089
|
const handleEventFlush = debounce((eventType) => {
|
|
3073
3090
|
queueEvent(Coframe, {
|
|
3074
3091
|
projectId: Coframe.projectId,
|
package/dist/pkg/cf.esm.mjs
CHANGED
|
@@ -924,7 +924,7 @@ function warnEventsNotSent() {
|
|
|
924
924
|
}
|
|
925
925
|
}
|
|
926
926
|
|
|
927
|
-
const SDK_VERSION = '2.
|
|
927
|
+
const SDK_VERSION = '2.5.0';
|
|
928
928
|
const queuedEvents = [];
|
|
929
929
|
const queuedMonitoringEvents = [];
|
|
930
930
|
const queuedSessions = [];
|
|
@@ -1014,20 +1014,21 @@ function queueEvent(coframe, sessionInfo) {
|
|
|
1014
1014
|
}
|
|
1015
1015
|
queueEventForBatchedSending(coframe, data);
|
|
1016
1016
|
}
|
|
1017
|
-
function
|
|
1017
|
+
function queueVariantViewEvent(coframe, { projectId, sessionId, orgId, userToken, experimentId, variantId, }) {
|
|
1018
|
+
queueEventForBatchedSending(coframe, {
|
|
1019
|
+
type: 'view',
|
|
1020
|
+
project_id: projectId,
|
|
1021
|
+
session_id: sessionId,
|
|
1022
|
+
experiment_id: experimentId,
|
|
1023
|
+
variant_id: variantId,
|
|
1024
|
+
time: new Date(),
|
|
1025
|
+
org_id: orgId,
|
|
1026
|
+
user_token: userToken,
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
function sendPageEngagementEvent(coframe, eventType, event, { projectId, sessionId, duration = 0, userToken, personalizationHeaders, }) {
|
|
1018
1030
|
var _a;
|
|
1019
1031
|
const startTime = performance.now();
|
|
1020
|
-
if (!isEngaged && eventType === 'click') {
|
|
1021
|
-
isEngaged = true;
|
|
1022
|
-
queueEvent(coframe, {
|
|
1023
|
-
projectId,
|
|
1024
|
-
sessionId,
|
|
1025
|
-
eventType: 'session_start',
|
|
1026
|
-
orgId,
|
|
1027
|
-
userToken: userToken || '',
|
|
1028
|
-
personalizationHeaders,
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
1032
|
const x = event.clientX + window.scrollX;
|
|
1032
1033
|
const y = event.clientY + window.scrollY;
|
|
1033
1034
|
const screenWidth = window.innerWidth;
|
|
@@ -3012,22 +3013,39 @@ const ENGAGED_SESSION_THRESHOLD = 10000;
|
|
|
3012
3013
|
function setupListeners(Coframe, executionStartTime) {
|
|
3013
3014
|
const experiencedCoframeIds = new Set();
|
|
3014
3015
|
let isEngaged = false;
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
if (
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
orgId: Coframe.orgId,
|
|
3024
|
-
userToken: Coframe.userToken,
|
|
3025
|
-
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3026
|
-
});
|
|
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;
|
|
3027
3024
|
}
|
|
3028
|
-
|
|
3029
|
-
|
|
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;
|
|
3030
3042
|
}
|
|
3043
|
+
if (engagementTimer !== null)
|
|
3044
|
+
return;
|
|
3045
|
+
engagementTimer = setTimeout(() => {
|
|
3046
|
+
engagementTimer = null;
|
|
3047
|
+
scheduleEngagementMeasurement();
|
|
3048
|
+
}, remaining);
|
|
3031
3049
|
}
|
|
3032
3050
|
function updateViewedVariants() {
|
|
3033
3051
|
for (const variantElement of Coframe.variantsAndElements || []) {
|
|
@@ -3038,35 +3056,34 @@ function setupListeners(Coframe, executionStartTime) {
|
|
|
3038
3056
|
if (isElementVisible(el)) {
|
|
3039
3057
|
el.setAttribute('coframe-experienced', 'true');
|
|
3040
3058
|
experiencedCoframeIds.add(variant.id);
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
session_id: Coframe.sessionId,
|
|
3045
|
-
experiment_id: variant.experiment_id,
|
|
3046
|
-
variant_id: variant.id,
|
|
3047
|
-
time: new Date(),
|
|
3059
|
+
queueVariantViewEvent(Coframe, {
|
|
3060
|
+
projectId: Coframe.projectId,
|
|
3061
|
+
sessionId: Coframe.sessionId,
|
|
3048
3062
|
orgId: Coframe.orgId,
|
|
3063
|
+
userToken: Coframe.userToken,
|
|
3064
|
+
experimentId: variant.experiment_id,
|
|
3065
|
+
variantId: variant.id,
|
|
3049
3066
|
});
|
|
3050
3067
|
}
|
|
3051
3068
|
}
|
|
3052
3069
|
}
|
|
3053
3070
|
}
|
|
3054
3071
|
}
|
|
3055
|
-
document.addEventListener('visibilitychange',
|
|
3056
|
-
|
|
3072
|
+
document.addEventListener('visibilitychange', scheduleEngagementMeasurement);
|
|
3073
|
+
scheduleEngagementMeasurement();
|
|
3057
3074
|
document.addEventListener('coframe:dom-renderer:complete', updateViewedVariants);
|
|
3058
3075
|
document.addEventListener('scroll', updateViewedVariants);
|
|
3059
3076
|
document.dispatchEvent(new CustomEvent('coframe:dom-renderer:complete', {}));
|
|
3060
|
-
|
|
3077
|
+
const handleClick = (event) => {
|
|
3078
|
+
markEngaged();
|
|
3061
3079
|
sendPageEngagementEvent(Coframe, 'click', event, {
|
|
3062
3080
|
projectId: Coframe.projectId,
|
|
3063
|
-
isEngaged,
|
|
3064
3081
|
sessionId: Coframe.sessionId,
|
|
3065
|
-
orgId: Coframe.orgId,
|
|
3066
3082
|
userToken: Coframe.userToken,
|
|
3067
3083
|
personalizationHeaders: Coframe.personalizationHeaders,
|
|
3068
3084
|
});
|
|
3069
|
-
}
|
|
3085
|
+
};
|
|
3086
|
+
document.addEventListener('click', handleClick, true);
|
|
3070
3087
|
const handleEventFlush = debounce((eventType) => {
|
|
3071
3088
|
queueEvent(Coframe, {
|
|
3072
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",
|