@coframe/sdk 1.1.8 → 1.1.9
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 +66 -5
- package/dist/pkg/cf.esm.mjs +66 -5
- package/package.json +2 -1
package/dist/pkg/cf.cjs.js
CHANGED
|
@@ -181,6 +181,12 @@ function getBrowserPlatform() {
|
|
|
181
181
|
function getBrowserReferrer() {
|
|
182
182
|
return document.referrer;
|
|
183
183
|
}
|
|
184
|
+
function getScreenSize() {
|
|
185
|
+
return {
|
|
186
|
+
width: window.innerWidth,
|
|
187
|
+
height: window.innerHeight,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
184
190
|
function getBrowserHostname() {
|
|
185
191
|
return window.location.hostname;
|
|
186
192
|
}
|
|
@@ -926,7 +932,7 @@ function warnEventsNotSent() {
|
|
|
926
932
|
}
|
|
927
933
|
}
|
|
928
934
|
|
|
929
|
-
const SDK_VERSION = '2.
|
|
935
|
+
const SDK_VERSION = '2.6.0';
|
|
930
936
|
const queuedEvents = [];
|
|
931
937
|
const queuedMonitoringEvents = [];
|
|
932
938
|
const queuedSessions = [];
|
|
@@ -942,7 +948,7 @@ function queueEventForBatchedSending(coframe, data, flushImmediately = false) {
|
|
|
942
948
|
flushQueuedEvents(coframe.projectId);
|
|
943
949
|
}
|
|
944
950
|
}
|
|
945
|
-
function queueCreateSession(coframe, orgId, projectId, sessionId, userToken, experimentsInfo, startTime, referrer, platform, languages, userAgent, url, storageInfo, gaSessionInfo, cfId, personalizationHeaders) {
|
|
951
|
+
function queueCreateSession(coframe, orgId, projectId, sessionId, userToken, experimentsInfo, startTime, referrer, platform, languages, userAgent, url, storageInfo, gaSessionInfo, cfId, personalizationHeaders, sessionContext) {
|
|
946
952
|
queuedSessions.push({
|
|
947
953
|
org_id: orgId,
|
|
948
954
|
project_id: projectId,
|
|
@@ -960,6 +966,7 @@ function queueCreateSession(coframe, orgId, projectId, sessionId, userToken, exp
|
|
|
960
966
|
session_metadata: JSON.stringify({
|
|
961
967
|
url,
|
|
962
968
|
storage_info: storageInfo,
|
|
969
|
+
...sessionContext,
|
|
963
970
|
}),
|
|
964
971
|
ga_session_id: gaSessionInfo === null || gaSessionInfo === void 0 ? void 0 : gaSessionInfo.ga_session_id,
|
|
965
972
|
ga_session_number: gaSessionInfo === null || gaSessionInfo === void 0 ? void 0 : gaSessionInfo.ga_session_number,
|
|
@@ -2480,6 +2487,59 @@ async function getVariantsAndElements(personalizationHeaders, project, previewVa
|
|
|
2480
2487
|
});
|
|
2481
2488
|
}
|
|
2482
2489
|
|
|
2490
|
+
function buildSessionContext(isInitialApply) {
|
|
2491
|
+
const context = {};
|
|
2492
|
+
const viewport = getScreenSize();
|
|
2493
|
+
if (isReportedSize(viewport.width) && isReportedSize(viewport.height)) {
|
|
2494
|
+
context.viewport_width = viewport.width;
|
|
2495
|
+
context.viewport_height = viewport.height;
|
|
2496
|
+
}
|
|
2497
|
+
const visitCount = getCookie(VISIT_COUNT_COOKIE_KEY);
|
|
2498
|
+
if (/^[1-9]\d{0,14}$/.test(visitCount)) {
|
|
2499
|
+
context.visit_count = Number(visitCount);
|
|
2500
|
+
}
|
|
2501
|
+
try {
|
|
2502
|
+
context.navigation_type = getNavigationType(isInitialApply);
|
|
2503
|
+
}
|
|
2504
|
+
catch (_a) {
|
|
2505
|
+
}
|
|
2506
|
+
try {
|
|
2507
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2508
|
+
if (timezone) {
|
|
2509
|
+
context.timezone = timezone;
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
catch (_b) {
|
|
2513
|
+
}
|
|
2514
|
+
return context;
|
|
2515
|
+
}
|
|
2516
|
+
function isReportedSize(size) {
|
|
2517
|
+
return (typeof size === 'number' && size > 0 && size !== Number.POSITIVE_INFINITY);
|
|
2518
|
+
}
|
|
2519
|
+
function getNavigationType(isInitialApply) {
|
|
2520
|
+
var _a, _b;
|
|
2521
|
+
if (!isInitialApply) {
|
|
2522
|
+
return 'spa_navigation';
|
|
2523
|
+
}
|
|
2524
|
+
const nav = (_b = (_a = performance.getEntriesByType) === null || _a === void 0 ? void 0 : _a.call(performance, 'navigation')) === null || _b === void 0 ? void 0 : _b[0];
|
|
2525
|
+
if (nav) {
|
|
2526
|
+
if (nav.type === 'reload')
|
|
2527
|
+
return 'reload';
|
|
2528
|
+
if (nav.type === 'back_forward')
|
|
2529
|
+
return 'back_forward';
|
|
2530
|
+
return nav.type === 'navigate' ? 'initial_load' : undefined;
|
|
2531
|
+
}
|
|
2532
|
+
const legacy = performance.navigation;
|
|
2533
|
+
if (legacy) {
|
|
2534
|
+
if (legacy.type === 1)
|
|
2535
|
+
return 'reload';
|
|
2536
|
+
if (legacy.type === 2)
|
|
2537
|
+
return 'back_forward';
|
|
2538
|
+
return legacy.type === 0 ? 'initial_load' : undefined;
|
|
2539
|
+
}
|
|
2540
|
+
return undefined;
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2483
2543
|
const CACHE_TTL_MS = 60 * 1000;
|
|
2484
2544
|
const cache = new Map();
|
|
2485
2545
|
function getCachedFrames(url) {
|
|
@@ -2820,7 +2880,7 @@ function observeUrlChanges(baseUrlMatch, onUrlChange) {
|
|
|
2820
2880
|
patchHistoryMethod('replaceState');
|
|
2821
2881
|
}
|
|
2822
2882
|
|
|
2823
|
-
function startSession(Coframe, cookiesEnabled, executionStartTime, personalizationHeaders) {
|
|
2883
|
+
function startSession(Coframe, cookiesEnabled, executionStartTime, personalizationHeaders, sessionContext) {
|
|
2824
2884
|
const sessionPayload = [
|
|
2825
2885
|
Coframe,
|
|
2826
2886
|
Coframe.orgId,
|
|
@@ -2837,7 +2897,7 @@ function startSession(Coframe, cookiesEnabled, executionStartTime, personalizati
|
|
|
2837
2897
|
getBrowserFignerprintInfo(),
|
|
2838
2898
|
];
|
|
2839
2899
|
{
|
|
2840
|
-
queueCreateSession(...sessionPayload, undefined, undefined, personalizationHeaders);
|
|
2900
|
+
queueCreateSession(...sessionPayload, undefined, undefined, personalizationHeaders, sessionContext);
|
|
2841
2901
|
}
|
|
2842
2902
|
queueEvent(Coframe, {
|
|
2843
2903
|
projectId: Coframe.projectId,
|
|
@@ -3284,6 +3344,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
|
|
|
3284
3344
|
let isFirstApply = true;
|
|
3285
3345
|
return async (pageUrl, pageProject) => {
|
|
3286
3346
|
const sessionId = isFirstApply ? Coframe.sessionId : generateUUID();
|
|
3347
|
+
const sessionContext = buildSessionContext(isFirstApply);
|
|
3287
3348
|
isFirstApply = false;
|
|
3288
3349
|
Coframe.sessionId = sessionId;
|
|
3289
3350
|
const preview = resolvePreview(pageUrl, previewVariantId, isSessionVariant);
|
|
@@ -3307,7 +3368,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
|
|
|
3307
3368
|
else {
|
|
3308
3369
|
replaceVariants(variantsAndElements, Coframe.orgId, Coframe.logger, config.nonce);
|
|
3309
3370
|
}
|
|
3310
|
-
startSession(Coframe, isCookiesEnabled, executionStartTime, personalizationHeaders);
|
|
3371
|
+
startSession(Coframe, isCookiesEnabled, executionStartTime, personalizationHeaders, sessionContext);
|
|
3311
3372
|
analytics.resetBroadcasted();
|
|
3312
3373
|
analytics.sendAnalytics();
|
|
3313
3374
|
};
|
package/dist/pkg/cf.esm.mjs
CHANGED
|
@@ -179,6 +179,12 @@ function getBrowserPlatform() {
|
|
|
179
179
|
function getBrowserReferrer() {
|
|
180
180
|
return document.referrer;
|
|
181
181
|
}
|
|
182
|
+
function getScreenSize() {
|
|
183
|
+
return {
|
|
184
|
+
width: window.innerWidth,
|
|
185
|
+
height: window.innerHeight,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
182
188
|
function getBrowserHostname() {
|
|
183
189
|
return window.location.hostname;
|
|
184
190
|
}
|
|
@@ -924,7 +930,7 @@ function warnEventsNotSent() {
|
|
|
924
930
|
}
|
|
925
931
|
}
|
|
926
932
|
|
|
927
|
-
const SDK_VERSION = '2.
|
|
933
|
+
const SDK_VERSION = '2.6.0';
|
|
928
934
|
const queuedEvents = [];
|
|
929
935
|
const queuedMonitoringEvents = [];
|
|
930
936
|
const queuedSessions = [];
|
|
@@ -940,7 +946,7 @@ function queueEventForBatchedSending(coframe, data, flushImmediately = false) {
|
|
|
940
946
|
flushQueuedEvents(coframe.projectId);
|
|
941
947
|
}
|
|
942
948
|
}
|
|
943
|
-
function queueCreateSession(coframe, orgId, projectId, sessionId, userToken, experimentsInfo, startTime, referrer, platform, languages, userAgent, url, storageInfo, gaSessionInfo, cfId, personalizationHeaders) {
|
|
949
|
+
function queueCreateSession(coframe, orgId, projectId, sessionId, userToken, experimentsInfo, startTime, referrer, platform, languages, userAgent, url, storageInfo, gaSessionInfo, cfId, personalizationHeaders, sessionContext) {
|
|
944
950
|
queuedSessions.push({
|
|
945
951
|
org_id: orgId,
|
|
946
952
|
project_id: projectId,
|
|
@@ -958,6 +964,7 @@ function queueCreateSession(coframe, orgId, projectId, sessionId, userToken, exp
|
|
|
958
964
|
session_metadata: JSON.stringify({
|
|
959
965
|
url,
|
|
960
966
|
storage_info: storageInfo,
|
|
967
|
+
...sessionContext,
|
|
961
968
|
}),
|
|
962
969
|
ga_session_id: gaSessionInfo === null || gaSessionInfo === void 0 ? void 0 : gaSessionInfo.ga_session_id,
|
|
963
970
|
ga_session_number: gaSessionInfo === null || gaSessionInfo === void 0 ? void 0 : gaSessionInfo.ga_session_number,
|
|
@@ -2478,6 +2485,59 @@ async function getVariantsAndElements(personalizationHeaders, project, previewVa
|
|
|
2478
2485
|
});
|
|
2479
2486
|
}
|
|
2480
2487
|
|
|
2488
|
+
function buildSessionContext(isInitialApply) {
|
|
2489
|
+
const context = {};
|
|
2490
|
+
const viewport = getScreenSize();
|
|
2491
|
+
if (isReportedSize(viewport.width) && isReportedSize(viewport.height)) {
|
|
2492
|
+
context.viewport_width = viewport.width;
|
|
2493
|
+
context.viewport_height = viewport.height;
|
|
2494
|
+
}
|
|
2495
|
+
const visitCount = getCookie(VISIT_COUNT_COOKIE_KEY);
|
|
2496
|
+
if (/^[1-9]\d{0,14}$/.test(visitCount)) {
|
|
2497
|
+
context.visit_count = Number(visitCount);
|
|
2498
|
+
}
|
|
2499
|
+
try {
|
|
2500
|
+
context.navigation_type = getNavigationType(isInitialApply);
|
|
2501
|
+
}
|
|
2502
|
+
catch (_a) {
|
|
2503
|
+
}
|
|
2504
|
+
try {
|
|
2505
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2506
|
+
if (timezone) {
|
|
2507
|
+
context.timezone = timezone;
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
catch (_b) {
|
|
2511
|
+
}
|
|
2512
|
+
return context;
|
|
2513
|
+
}
|
|
2514
|
+
function isReportedSize(size) {
|
|
2515
|
+
return (typeof size === 'number' && size > 0 && size !== Number.POSITIVE_INFINITY);
|
|
2516
|
+
}
|
|
2517
|
+
function getNavigationType(isInitialApply) {
|
|
2518
|
+
var _a, _b;
|
|
2519
|
+
if (!isInitialApply) {
|
|
2520
|
+
return 'spa_navigation';
|
|
2521
|
+
}
|
|
2522
|
+
const nav = (_b = (_a = performance.getEntriesByType) === null || _a === void 0 ? void 0 : _a.call(performance, 'navigation')) === null || _b === void 0 ? void 0 : _b[0];
|
|
2523
|
+
if (nav) {
|
|
2524
|
+
if (nav.type === 'reload')
|
|
2525
|
+
return 'reload';
|
|
2526
|
+
if (nav.type === 'back_forward')
|
|
2527
|
+
return 'back_forward';
|
|
2528
|
+
return nav.type === 'navigate' ? 'initial_load' : undefined;
|
|
2529
|
+
}
|
|
2530
|
+
const legacy = performance.navigation;
|
|
2531
|
+
if (legacy) {
|
|
2532
|
+
if (legacy.type === 1)
|
|
2533
|
+
return 'reload';
|
|
2534
|
+
if (legacy.type === 2)
|
|
2535
|
+
return 'back_forward';
|
|
2536
|
+
return legacy.type === 0 ? 'initial_load' : undefined;
|
|
2537
|
+
}
|
|
2538
|
+
return undefined;
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2481
2541
|
const CACHE_TTL_MS = 60 * 1000;
|
|
2482
2542
|
const cache = new Map();
|
|
2483
2543
|
function getCachedFrames(url) {
|
|
@@ -2818,7 +2878,7 @@ function observeUrlChanges(baseUrlMatch, onUrlChange) {
|
|
|
2818
2878
|
patchHistoryMethod('replaceState');
|
|
2819
2879
|
}
|
|
2820
2880
|
|
|
2821
|
-
function startSession(Coframe, cookiesEnabled, executionStartTime, personalizationHeaders) {
|
|
2881
|
+
function startSession(Coframe, cookiesEnabled, executionStartTime, personalizationHeaders, sessionContext) {
|
|
2822
2882
|
const sessionPayload = [
|
|
2823
2883
|
Coframe,
|
|
2824
2884
|
Coframe.orgId,
|
|
@@ -2835,7 +2895,7 @@ function startSession(Coframe, cookiesEnabled, executionStartTime, personalizati
|
|
|
2835
2895
|
getBrowserFignerprintInfo(),
|
|
2836
2896
|
];
|
|
2837
2897
|
{
|
|
2838
|
-
queueCreateSession(...sessionPayload, undefined, undefined, personalizationHeaders);
|
|
2898
|
+
queueCreateSession(...sessionPayload, undefined, undefined, personalizationHeaders, sessionContext);
|
|
2839
2899
|
}
|
|
2840
2900
|
queueEvent(Coframe, {
|
|
2841
2901
|
projectId: Coframe.projectId,
|
|
@@ -3282,6 +3342,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
|
|
|
3282
3342
|
let isFirstApply = true;
|
|
3283
3343
|
return async (pageUrl, pageProject) => {
|
|
3284
3344
|
const sessionId = isFirstApply ? Coframe.sessionId : generateUUID();
|
|
3345
|
+
const sessionContext = buildSessionContext(isFirstApply);
|
|
3285
3346
|
isFirstApply = false;
|
|
3286
3347
|
Coframe.sessionId = sessionId;
|
|
3287
3348
|
const preview = resolvePreview(pageUrl, previewVariantId, isSessionVariant);
|
|
@@ -3305,7 +3366,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
|
|
|
3305
3366
|
else {
|
|
3306
3367
|
replaceVariants(variantsAndElements, Coframe.orgId, Coframe.logger, config.nonce);
|
|
3307
3368
|
}
|
|
3308
|
-
startSession(Coframe, isCookiesEnabled, executionStartTime, personalizationHeaders);
|
|
3369
|
+
startSession(Coframe, isCookiesEnabled, executionStartTime, personalizationHeaders, sessionContext);
|
|
3309
3370
|
analytics.resetBroadcasted();
|
|
3310
3371
|
analytics.sendAnalytics();
|
|
3311
3372
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coframe/sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
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",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"test:jest": "jest --maxWorkers=2",
|
|
30
30
|
"test:playwright": "npx playwright test --retries=5 --reporter=list",
|
|
31
|
+
"test:package": "node ./tests/package/scripts/test-package.mjs",
|
|
31
32
|
"test:browserstack:full": "jest --config jest.browserstack.config.js --suite=full",
|
|
32
33
|
"test:browserstack:small": "jest --config jest.browserstack.config.js --suite=small",
|
|
33
34
|
"test": "npm run test:jest && npm run test:playwright",
|