@coframe/sdk 1.1.45 → 1.1.47
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 +32 -7
- package/dist/pkg/cf.esm.mjs +32 -7
- package/package.json +1 -1
package/dist/pkg/cf.cjs.js
CHANGED
|
@@ -2069,6 +2069,7 @@ const applyVariantChanges = (variantElements, currentUrl, logger, nonce, lifecyc
|
|
|
2069
2069
|
? lifecycleContext.runtime.createVariantSession({
|
|
2070
2070
|
batchId: lifecycleContext.batchId,
|
|
2071
2071
|
variantId: variant.id,
|
|
2072
|
+
experimentId: variant.experiment_id,
|
|
2072
2073
|
})
|
|
2073
2074
|
: null;
|
|
2074
2075
|
if (!variant.modifications ||
|
|
@@ -2106,7 +2107,7 @@ const applyVariantChanges = (variantElements, currentUrl, logger, nonce, lifecyc
|
|
|
2106
2107
|
});
|
|
2107
2108
|
}
|
|
2108
2109
|
else if (selectedElement instanceof HTMLElement) {
|
|
2109
|
-
selectedElement.setAttribute('coframe-exp-id', variant.
|
|
2110
|
+
selectedElement.setAttribute('coframe-exp-id', variant.experiment_id);
|
|
2110
2111
|
}
|
|
2111
2112
|
}
|
|
2112
2113
|
return true;
|
|
@@ -4159,7 +4160,7 @@ function setupListeners(Coframe, executionStartTime) {
|
|
|
4159
4160
|
for (const variantElement of Coframe.variantsAndElements || []) {
|
|
4160
4161
|
const variant = variantElement.variant;
|
|
4161
4162
|
if (!experiencedCoframeIds.has(variant.id)) {
|
|
4162
|
-
const elements = document.querySelectorAll(`[coframe-exp-id="${variant.
|
|
4163
|
+
const elements = document.querySelectorAll(`[coframe-exp-id="${variant.experiment_id}"]`);
|
|
4163
4164
|
for (const el of Array.from(elements)) {
|
|
4164
4165
|
if (isElementVisible(el)) {
|
|
4165
4166
|
el.setAttribute('coframe-experienced', 'true');
|
|
@@ -4194,17 +4195,39 @@ function setupListeners(Coframe, executionStartTime) {
|
|
|
4194
4195
|
});
|
|
4195
4196
|
};
|
|
4196
4197
|
document.addEventListener('click', handleClick, true);
|
|
4197
|
-
|
|
4198
|
+
let scheduledEventFlush = null;
|
|
4199
|
+
const flushEvent = (eventType) => {
|
|
4198
4200
|
queueLeaveEvent(Coframe, eventType, eventType === 'tab_show' ? undefined : leaveFields());
|
|
4199
4201
|
flushQueuedEvents(Coframe.projectId);
|
|
4200
4202
|
notifyEventsFlushed();
|
|
4201
|
-
}
|
|
4202
|
-
|
|
4203
|
-
|
|
4203
|
+
};
|
|
4204
|
+
const scheduleEventFlush = (eventType) => {
|
|
4205
|
+
if (scheduledEventFlush !== null) {
|
|
4206
|
+
clearTimeout(scheduledEventFlush);
|
|
4207
|
+
}
|
|
4208
|
+
scheduledEventFlush = setTimeout(() => {
|
|
4209
|
+
scheduledEventFlush = null;
|
|
4210
|
+
flushEvent(eventType);
|
|
4211
|
+
}, 1);
|
|
4212
|
+
};
|
|
4213
|
+
const flushEventImmediately = (eventType) => {
|
|
4214
|
+
if (scheduledEventFlush !== null) {
|
|
4215
|
+
clearTimeout(scheduledEventFlush);
|
|
4216
|
+
scheduledEventFlush = null;
|
|
4217
|
+
}
|
|
4218
|
+
flushEvent(eventType);
|
|
4219
|
+
};
|
|
4220
|
+
window.addEventListener('beforeunload', () => scheduleEventFlush('before_unload'));
|
|
4221
|
+
window.addEventListener('pagehide', () => flushEventImmediately('page_hide'));
|
|
4204
4222
|
window.addEventListener('visibilitychange', () => {
|
|
4205
4223
|
const isPageHidden = document.hidden;
|
|
4206
4224
|
const eventType = isPageHidden ? 'tab_hide' : 'tab_show';
|
|
4207
|
-
|
|
4225
|
+
if (isPageHidden) {
|
|
4226
|
+
flushEventImmediately(eventType);
|
|
4227
|
+
}
|
|
4228
|
+
else {
|
|
4229
|
+
scheduleEventFlush(eventType);
|
|
4230
|
+
}
|
|
4208
4231
|
});
|
|
4209
4232
|
}
|
|
4210
4233
|
function queueLeaveEvent(Coframe, eventType, fields) {
|
|
@@ -5367,6 +5390,7 @@ function createVariantSession(options) {
|
|
|
5367
5390
|
getPageState: () => ({ ...options.getPageState() }),
|
|
5368
5391
|
getState: () => ({ ...state }),
|
|
5369
5392
|
getVariantId: () => state.variantId,
|
|
5393
|
+
getExperimentId: () => options.experimentId,
|
|
5370
5394
|
onPage: (event, handler) => subscribe(event, handler, false),
|
|
5371
5395
|
oncePage: (event, handler) => subscribe(event, handler, true),
|
|
5372
5396
|
ready() {
|
|
@@ -5726,6 +5750,7 @@ function createPageRuntime(options) {
|
|
|
5726
5750
|
const session = createVariantSession({
|
|
5727
5751
|
sessionId: createId(),
|
|
5728
5752
|
variantId: input.variantId,
|
|
5753
|
+
experimentId: input.experimentId,
|
|
5729
5754
|
batchId: batch.batchId,
|
|
5730
5755
|
routeVersion: batch.routeVersion,
|
|
5731
5756
|
getPageState: () => ({ ...state }),
|
package/dist/pkg/cf.esm.mjs
CHANGED
|
@@ -2067,6 +2067,7 @@ const applyVariantChanges = (variantElements, currentUrl, logger, nonce, lifecyc
|
|
|
2067
2067
|
? lifecycleContext.runtime.createVariantSession({
|
|
2068
2068
|
batchId: lifecycleContext.batchId,
|
|
2069
2069
|
variantId: variant.id,
|
|
2070
|
+
experimentId: variant.experiment_id,
|
|
2070
2071
|
})
|
|
2071
2072
|
: null;
|
|
2072
2073
|
if (!variant.modifications ||
|
|
@@ -2104,7 +2105,7 @@ const applyVariantChanges = (variantElements, currentUrl, logger, nonce, lifecyc
|
|
|
2104
2105
|
});
|
|
2105
2106
|
}
|
|
2106
2107
|
else if (selectedElement instanceof HTMLElement) {
|
|
2107
|
-
selectedElement.setAttribute('coframe-exp-id', variant.
|
|
2108
|
+
selectedElement.setAttribute('coframe-exp-id', variant.experiment_id);
|
|
2108
2109
|
}
|
|
2109
2110
|
}
|
|
2110
2111
|
return true;
|
|
@@ -4157,7 +4158,7 @@ function setupListeners(Coframe, executionStartTime) {
|
|
|
4157
4158
|
for (const variantElement of Coframe.variantsAndElements || []) {
|
|
4158
4159
|
const variant = variantElement.variant;
|
|
4159
4160
|
if (!experiencedCoframeIds.has(variant.id)) {
|
|
4160
|
-
const elements = document.querySelectorAll(`[coframe-exp-id="${variant.
|
|
4161
|
+
const elements = document.querySelectorAll(`[coframe-exp-id="${variant.experiment_id}"]`);
|
|
4161
4162
|
for (const el of Array.from(elements)) {
|
|
4162
4163
|
if (isElementVisible(el)) {
|
|
4163
4164
|
el.setAttribute('coframe-experienced', 'true');
|
|
@@ -4192,17 +4193,39 @@ function setupListeners(Coframe, executionStartTime) {
|
|
|
4192
4193
|
});
|
|
4193
4194
|
};
|
|
4194
4195
|
document.addEventListener('click', handleClick, true);
|
|
4195
|
-
|
|
4196
|
+
let scheduledEventFlush = null;
|
|
4197
|
+
const flushEvent = (eventType) => {
|
|
4196
4198
|
queueLeaveEvent(Coframe, eventType, eventType === 'tab_show' ? undefined : leaveFields());
|
|
4197
4199
|
flushQueuedEvents(Coframe.projectId);
|
|
4198
4200
|
notifyEventsFlushed();
|
|
4199
|
-
}
|
|
4200
|
-
|
|
4201
|
-
|
|
4201
|
+
};
|
|
4202
|
+
const scheduleEventFlush = (eventType) => {
|
|
4203
|
+
if (scheduledEventFlush !== null) {
|
|
4204
|
+
clearTimeout(scheduledEventFlush);
|
|
4205
|
+
}
|
|
4206
|
+
scheduledEventFlush = setTimeout(() => {
|
|
4207
|
+
scheduledEventFlush = null;
|
|
4208
|
+
flushEvent(eventType);
|
|
4209
|
+
}, 1);
|
|
4210
|
+
};
|
|
4211
|
+
const flushEventImmediately = (eventType) => {
|
|
4212
|
+
if (scheduledEventFlush !== null) {
|
|
4213
|
+
clearTimeout(scheduledEventFlush);
|
|
4214
|
+
scheduledEventFlush = null;
|
|
4215
|
+
}
|
|
4216
|
+
flushEvent(eventType);
|
|
4217
|
+
};
|
|
4218
|
+
window.addEventListener('beforeunload', () => scheduleEventFlush('before_unload'));
|
|
4219
|
+
window.addEventListener('pagehide', () => flushEventImmediately('page_hide'));
|
|
4202
4220
|
window.addEventListener('visibilitychange', () => {
|
|
4203
4221
|
const isPageHidden = document.hidden;
|
|
4204
4222
|
const eventType = isPageHidden ? 'tab_hide' : 'tab_show';
|
|
4205
|
-
|
|
4223
|
+
if (isPageHidden) {
|
|
4224
|
+
flushEventImmediately(eventType);
|
|
4225
|
+
}
|
|
4226
|
+
else {
|
|
4227
|
+
scheduleEventFlush(eventType);
|
|
4228
|
+
}
|
|
4206
4229
|
});
|
|
4207
4230
|
}
|
|
4208
4231
|
function queueLeaveEvent(Coframe, eventType, fields) {
|
|
@@ -5365,6 +5388,7 @@ function createVariantSession(options) {
|
|
|
5365
5388
|
getPageState: () => ({ ...options.getPageState() }),
|
|
5366
5389
|
getState: () => ({ ...state }),
|
|
5367
5390
|
getVariantId: () => state.variantId,
|
|
5391
|
+
getExperimentId: () => options.experimentId,
|
|
5368
5392
|
onPage: (event, handler) => subscribe(event, handler, false),
|
|
5369
5393
|
oncePage: (event, handler) => subscribe(event, handler, true),
|
|
5370
5394
|
ready() {
|
|
@@ -5724,6 +5748,7 @@ function createPageRuntime(options) {
|
|
|
5724
5748
|
const session = createVariantSession({
|
|
5725
5749
|
sessionId: createId(),
|
|
5726
5750
|
variantId: input.variantId,
|
|
5751
|
+
experimentId: input.experimentId,
|
|
5727
5752
|
batchId: batch.batchId,
|
|
5728
5753
|
routeVersion: batch.routeVersion,
|
|
5729
5754
|
getPageState: () => ({ ...state }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coframe/sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.47",
|
|
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",
|