@coframe/sdk 1.1.52 → 1.1.54
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 +405 -194
- package/dist/pkg/cf.esm.mjs +405 -194
- package/dist/pkg/types/index.d.ts +1 -0
- package/dist/pkg/types/react.d.ts +1 -0
- package/dist/pkg/types/server.d.ts +1 -0
- package/package.json +1 -1
package/dist/pkg/cf.esm.mjs
CHANGED
|
@@ -1162,6 +1162,11 @@ const SDK_VERSION = '2.10.0';
|
|
|
1162
1162
|
const queuedEvents = [];
|
|
1163
1163
|
const queuedMonitoringEvents = [];
|
|
1164
1164
|
const queuedSessions = [];
|
|
1165
|
+
const heatmapContentKeys = new WeakMap();
|
|
1166
|
+
let beforeFlush;
|
|
1167
|
+
function setBeforeFlush(hook) {
|
|
1168
|
+
beforeFlush = hook;
|
|
1169
|
+
}
|
|
1165
1170
|
let ingestUrl;
|
|
1166
1171
|
const COMPILED_INGEST_BASE = "https://ingest.app.coframe.com/ingest/v2";
|
|
1167
1172
|
function configureIngestUrl(url) {
|
|
@@ -1193,6 +1198,18 @@ function chunkEventsByByteLimit(events) {
|
|
|
1193
1198
|
}
|
|
1194
1199
|
return chunks;
|
|
1195
1200
|
}
|
|
1201
|
+
function createMonitoringPayload(coframe, monitoringType, metadata) {
|
|
1202
|
+
return {
|
|
1203
|
+
event_id: generateUUID(),
|
|
1204
|
+
monitoring_type: monitoringType,
|
|
1205
|
+
local_time: new Date().toISOString(),
|
|
1206
|
+
project_id: coframe.projectId,
|
|
1207
|
+
session_id: coframe.sessionId,
|
|
1208
|
+
url: location.href,
|
|
1209
|
+
org_id: coframe.orgId,
|
|
1210
|
+
metadata,
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1196
1213
|
function queueMonitoringEvent(coframe, data) {
|
|
1197
1214
|
queuedMonitoringEvents.push(data);
|
|
1198
1215
|
if (queuedMonitoringEvents.length >= coframe.batchSize) {
|
|
@@ -1244,6 +1261,7 @@ function flushQueuedEvents(projectId) {
|
|
|
1244
1261
|
if (!shouldSendEvents()) {
|
|
1245
1262
|
return;
|
|
1246
1263
|
}
|
|
1264
|
+
beforeFlush === null || beforeFlush === void 0 ? void 0 : beforeFlush();
|
|
1247
1265
|
if (queuedEvents.length > 0) {
|
|
1248
1266
|
for (const chunk of chunkEventsByByteLimit(queuedEvents)) {
|
|
1249
1267
|
sendEventToBackend(projectId, chunk, 'batched_events');
|
|
@@ -1288,6 +1306,8 @@ function queueEvent(coframe, sessionInfo, heatmap) {
|
|
|
1288
1306
|
screen_size: { width: window.innerWidth, height: window.innerHeight },
|
|
1289
1307
|
}
|
|
1290
1308
|
: { metadata, ...heatmap === null || heatmap === void 0 ? void 0 : heatmap.content };
|
|
1309
|
+
if (heatmap === null || heatmap === void 0 ? void 0 : heatmap.content)
|
|
1310
|
+
heatmapContentKeys.set(data, Object.keys(heatmap.content));
|
|
1291
1311
|
queueEventForBatchedSending(coframe, data);
|
|
1292
1312
|
}
|
|
1293
1313
|
function queueVariantViewEvent(coframe, { projectId, sessionId, orgId, userToken, experimentId, variantId, }) {
|
|
@@ -3744,6 +3764,241 @@ function notifyEventsFlushed() {
|
|
|
3744
3764
|
}
|
|
3745
3765
|
}
|
|
3746
3766
|
|
|
3767
|
+
function isRecord(value) {
|
|
3768
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
3769
|
+
}
|
|
3770
|
+
|
|
3771
|
+
const OPT_IN_COUNTRIES = new Set(('AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE ' +
|
|
3772
|
+
'AX GF GP MF MQ RE YT ' +
|
|
3773
|
+
'IS LI NO ' +
|
|
3774
|
+
'GB GI GG IM JE ' +
|
|
3775
|
+
'CH').split(' '));
|
|
3776
|
+
function collectsWithoutChoice(model, country) {
|
|
3777
|
+
if (model === 'opt_out')
|
|
3778
|
+
return true;
|
|
3779
|
+
if (model === 'opt_in')
|
|
3780
|
+
return false;
|
|
3781
|
+
const code = (country || '').trim().toUpperCase();
|
|
3782
|
+
if (!/^[A-Z]{2}$/.test(code) || code === 'XX' || code === 'T1')
|
|
3783
|
+
return false;
|
|
3784
|
+
return !OPT_IN_COUNTRIES.has(code);
|
|
3785
|
+
}
|
|
3786
|
+
function readRawCookie(name) {
|
|
3787
|
+
const prefix = `${name}=`;
|
|
3788
|
+
const cookies = document.cookie.split(';');
|
|
3789
|
+
for (let i = 0; i < cookies.length; i++) {
|
|
3790
|
+
const cookie = cookies[i].trim();
|
|
3791
|
+
if (cookie.indexOf(prefix) === 0)
|
|
3792
|
+
return cookie.slice(prefix.length);
|
|
3793
|
+
}
|
|
3794
|
+
return undefined;
|
|
3795
|
+
}
|
|
3796
|
+
function readCookie(name) {
|
|
3797
|
+
const raw = readRawCookie(name);
|
|
3798
|
+
return raw === undefined ? undefined : decodeURIComponent(raw);
|
|
3799
|
+
}
|
|
3800
|
+
function readClientCommand() {
|
|
3801
|
+
try {
|
|
3802
|
+
const cmd = findLastCmd((c) => typeof c.cookiesEnabled === 'boolean');
|
|
3803
|
+
if (!cmd)
|
|
3804
|
+
return undefined;
|
|
3805
|
+
return cmd.cookiesEnabled === true ? 'granted' : 'denied';
|
|
3806
|
+
}
|
|
3807
|
+
catch (_a) {
|
|
3808
|
+
return undefined;
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
function readOneTrustCookie() {
|
|
3812
|
+
const cookie = readRawCookie('OptanonConsent');
|
|
3813
|
+
if (cookie === undefined)
|
|
3814
|
+
return undefined;
|
|
3815
|
+
const fields = cookie.split('&');
|
|
3816
|
+
let groups = '';
|
|
3817
|
+
for (let i = 0; i < fields.length; i++) {
|
|
3818
|
+
if (fields[i].indexOf('groups=') === 0)
|
|
3819
|
+
groups = decodeURIComponent(fields[i].slice('groups='.length));
|
|
3820
|
+
}
|
|
3821
|
+
if (groups.split(',').indexOf('C0002:1') !== -1)
|
|
3822
|
+
return 'granted';
|
|
3823
|
+
return readCookie('OptanonAlertBoxClosed') !== undefined
|
|
3824
|
+
? 'denied'
|
|
3825
|
+
: 'pending';
|
|
3826
|
+
}
|
|
3827
|
+
function readOneTrust() {
|
|
3828
|
+
var _a;
|
|
3829
|
+
try {
|
|
3830
|
+
const { OnetrustActiveGroups: groups, OneTrust } = window;
|
|
3831
|
+
if (typeof groups !== 'string' && OneTrust === undefined) {
|
|
3832
|
+
if (window.Cookiebot !== undefined)
|
|
3833
|
+
return undefined;
|
|
3834
|
+
return readOneTrustCookie();
|
|
3835
|
+
}
|
|
3836
|
+
if (typeof groups === 'string' && groups.split(',').indexOf('C0002') !== -1)
|
|
3837
|
+
return 'granted';
|
|
3838
|
+
return ((_a = OneTrust === null || OneTrust === void 0 ? void 0 : OneTrust.IsAlertBoxClosed) === null || _a === void 0 ? void 0 : _a.call(OneTrust)) === true ? 'denied' : 'pending';
|
|
3839
|
+
}
|
|
3840
|
+
catch (_b) {
|
|
3841
|
+
return undefined;
|
|
3842
|
+
}
|
|
3843
|
+
}
|
|
3844
|
+
function readCookiebotCookie() {
|
|
3845
|
+
const cookie = readCookie('CookieConsent');
|
|
3846
|
+
if (cookie === undefined)
|
|
3847
|
+
return undefined;
|
|
3848
|
+
if (cookie === '-1')
|
|
3849
|
+
return 'granted';
|
|
3850
|
+
const statistics = /[{,]statistics:(true|false)[,}]/.exec(cookie);
|
|
3851
|
+
if (!statistics)
|
|
3852
|
+
return undefined;
|
|
3853
|
+
return statistics[1] === 'true' ? 'granted' : 'denied';
|
|
3854
|
+
}
|
|
3855
|
+
function readCookiebot() {
|
|
3856
|
+
var _a;
|
|
3857
|
+
try {
|
|
3858
|
+
const { Cookiebot, OnetrustActiveGroups, OneTrust } = window;
|
|
3859
|
+
if (Cookiebot === undefined) {
|
|
3860
|
+
if (typeof OnetrustActiveGroups === 'string' || OneTrust !== undefined)
|
|
3861
|
+
return undefined;
|
|
3862
|
+
return readCookiebotCookie();
|
|
3863
|
+
}
|
|
3864
|
+
if (((_a = Cookiebot.consent) === null || _a === void 0 ? void 0 : _a.statistics) === true)
|
|
3865
|
+
return 'granted';
|
|
3866
|
+
return Cookiebot.hasResponse === true ? 'denied' : 'pending';
|
|
3867
|
+
}
|
|
3868
|
+
catch (_b) {
|
|
3869
|
+
return undefined;
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3872
|
+
function readTrueVault() {
|
|
3873
|
+
try {
|
|
3874
|
+
const cookie = readCookie('polaris_consent_settings');
|
|
3875
|
+
if (cookie === undefined)
|
|
3876
|
+
return undefined;
|
|
3877
|
+
const parsed = JSON.parse(cookie);
|
|
3878
|
+
if (parsed.analyticsPermitted === false || parsed.notOptedOut === false) {
|
|
3879
|
+
return 'denied';
|
|
3880
|
+
}
|
|
3881
|
+
if (parsed.implicit === false && parsed.analyticsPermitted === true)
|
|
3882
|
+
return 'granted';
|
|
3883
|
+
return 'pending';
|
|
3884
|
+
}
|
|
3885
|
+
catch (_a) {
|
|
3886
|
+
return undefined;
|
|
3887
|
+
}
|
|
3888
|
+
}
|
|
3889
|
+
function readUsPrivacy() {
|
|
3890
|
+
try {
|
|
3891
|
+
const cookie = readCookie('us_privacy');
|
|
3892
|
+
if (cookie !== undefined &&
|
|
3893
|
+
/^1[YN-]{3}$/i.test(cookie) &&
|
|
3894
|
+
(cookie[2] === 'Y' || cookie[2] === 'y')) {
|
|
3895
|
+
return 'denied';
|
|
3896
|
+
}
|
|
3897
|
+
return undefined;
|
|
3898
|
+
}
|
|
3899
|
+
catch (_a) {
|
|
3900
|
+
return undefined;
|
|
3901
|
+
}
|
|
3902
|
+
}
|
|
3903
|
+
function readConsentMode() {
|
|
3904
|
+
var _a;
|
|
3905
|
+
try {
|
|
3906
|
+
const { dataLayer } = window;
|
|
3907
|
+
if (!Array.isArray(dataLayer))
|
|
3908
|
+
return undefined;
|
|
3909
|
+
let update;
|
|
3910
|
+
let defaultGranted = false;
|
|
3911
|
+
let defaultDenied = false;
|
|
3912
|
+
for (let i = 0; i < dataLayer.length; i++) {
|
|
3913
|
+
const entry = dataLayer[i];
|
|
3914
|
+
if (entry === null ||
|
|
3915
|
+
typeof entry !== 'object' ||
|
|
3916
|
+
entry[0] !== 'consent' ||
|
|
3917
|
+
(entry[1] !== 'default' && entry[1] !== 'update')) {
|
|
3918
|
+
continue;
|
|
3919
|
+
}
|
|
3920
|
+
const storage = (_a = entry[2]) === null || _a === void 0 ? void 0 : _a.analytics_storage;
|
|
3921
|
+
if (storage !== 'granted' && storage !== 'denied')
|
|
3922
|
+
continue;
|
|
3923
|
+
if (entry[1] === 'update')
|
|
3924
|
+
update = storage;
|
|
3925
|
+
else if (storage === 'denied')
|
|
3926
|
+
defaultDenied = true;
|
|
3927
|
+
else
|
|
3928
|
+
defaultGranted = true;
|
|
3929
|
+
}
|
|
3930
|
+
if (update !== undefined)
|
|
3931
|
+
return update;
|
|
3932
|
+
if (defaultDenied)
|
|
3933
|
+
return 'pending';
|
|
3934
|
+
return defaultGranted ? 'granted' : undefined;
|
|
3935
|
+
}
|
|
3936
|
+
catch (_b) {
|
|
3937
|
+
return undefined;
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
const CONSENT_WAIT_MS = 5000;
|
|
3941
|
+
const CONSENT_DETECT_WAIT_MS = 10000;
|
|
3942
|
+
const EXPLICIT_CONSENT_WAIT_MS = 60000;
|
|
3943
|
+
function readVisitorConsent(optOut) {
|
|
3944
|
+
try {
|
|
3945
|
+
if (navigator
|
|
3946
|
+
.globalPrivacyControl === true) {
|
|
3947
|
+
return { state: 'denied', reason: 'gpc' };
|
|
3948
|
+
}
|
|
3949
|
+
const shopify = window.Shopify;
|
|
3950
|
+
if (shopify === undefined) {
|
|
3951
|
+
if (readUsPrivacy() === 'denied')
|
|
3952
|
+
return { state: 'denied', reason: 'consent_denied' };
|
|
3953
|
+
if (isWaitingForCookies()) {
|
|
3954
|
+
const signal = readClientCommand();
|
|
3955
|
+
if (signal === 'granted')
|
|
3956
|
+
return { state: 'allowed', source: 'client' };
|
|
3957
|
+
if (signal === 'denied')
|
|
3958
|
+
return { state: 'denied', reason: 'consent_denied' };
|
|
3959
|
+
return { state: 'pending', detected: true };
|
|
3960
|
+
}
|
|
3961
|
+
const readers = [
|
|
3962
|
+
[readClientCommand, 'client'],
|
|
3963
|
+
[readOneTrust, 'onetrust'],
|
|
3964
|
+
[readCookiebot, 'cookiebot'],
|
|
3965
|
+
[readTrueVault, 'truevault'],
|
|
3966
|
+
[readConsentMode, 'consent_mode'],
|
|
3967
|
+
];
|
|
3968
|
+
let granted;
|
|
3969
|
+
for (let i = 0; i < readers.length; i++) {
|
|
3970
|
+
const [read, source] = readers[i];
|
|
3971
|
+
const signal = read();
|
|
3972
|
+
if (signal === 'granted') {
|
|
3973
|
+
if (source === 'client')
|
|
3974
|
+
return { state: 'allowed', source };
|
|
3975
|
+
granted = granted || source;
|
|
3976
|
+
}
|
|
3977
|
+
else if (signal === 'denied')
|
|
3978
|
+
return { state: 'denied', reason: 'consent_denied' };
|
|
3979
|
+
else if (signal === 'pending' && !optOut && !granted)
|
|
3980
|
+
return { state: 'pending', detected: true };
|
|
3981
|
+
}
|
|
3982
|
+
if (granted)
|
|
3983
|
+
return { state: 'allowed', source: granted };
|
|
3984
|
+
if (optOut)
|
|
3985
|
+
return { state: 'allowed', source: 'opt_out' };
|
|
3986
|
+
return { state: 'pending', detected: isWaitingForCookies() };
|
|
3987
|
+
}
|
|
3988
|
+
const customerPrivacy = shopify.customerPrivacy;
|
|
3989
|
+
const analyticsProcessingAllowed = customerPrivacy === null || customerPrivacy === void 0 ? void 0 : customerPrivacy.analyticsProcessingAllowed;
|
|
3990
|
+
if (typeof analyticsProcessingAllowed === 'function') {
|
|
3991
|
+
return analyticsProcessingAllowed.call(customerPrivacy) === true
|
|
3992
|
+
? { state: 'allowed', source: 'shopify' }
|
|
3993
|
+
: { state: 'denied', reason: 'consent_denied' };
|
|
3994
|
+
}
|
|
3995
|
+
return { state: 'pending' };
|
|
3996
|
+
}
|
|
3997
|
+
catch (_a) {
|
|
3998
|
+
return { state: 'denied', reason: 'consent_unavailable' };
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
|
|
3747
4002
|
const DEFAULT_BLOCK_SELECTOR = '[data-cf-block],.cf-block';
|
|
3748
4003
|
const INTERACTIVE_SELECTOR = 'a,button,input,select,textarea,label,summary,[href],[onclick],[contenteditable],[tabindex]:not([tabindex="-1"]),[role=button],[role=link],[role=tab],[role=checkbox],[role=menuitem]';
|
|
3749
4004
|
const HOLD_MS = 1000;
|
|
@@ -3752,6 +4007,7 @@ const RAGE_RADIUS_PX = 30;
|
|
|
3752
4007
|
const RAGE_CLICKS = 3;
|
|
3753
4008
|
let enabled = false;
|
|
3754
4009
|
let allPages = false;
|
|
4010
|
+
let optOut = false;
|
|
3755
4011
|
let coframe = null;
|
|
3756
4012
|
let blockSelector = DEFAULT_BLOCK_SELECTOR;
|
|
3757
4013
|
const held = [];
|
|
@@ -3762,13 +4018,26 @@ let pageView = '';
|
|
|
3762
4018
|
let maxDepth = 0;
|
|
3763
4019
|
let engagedMs = 0;
|
|
3764
4020
|
let visibleSince = null;
|
|
4021
|
+
let measuring = false;
|
|
4022
|
+
let consentCmdSubscribed = false;
|
|
4023
|
+
const CONSENT_EVENTS = [
|
|
4024
|
+
'OneTrustGroupsUpdated',
|
|
4025
|
+
'CookiebotOnAccept',
|
|
4026
|
+
'CookiebotOnDecline',
|
|
4027
|
+
];
|
|
3765
4028
|
let navigated = false;
|
|
4029
|
+
let consentView = '';
|
|
4030
|
+
let consentSince = 0;
|
|
4031
|
+
let consentDone = false;
|
|
4032
|
+
let consentTimer;
|
|
3766
4033
|
function meta(name) {
|
|
3767
4034
|
const tag = document.querySelector(`meta[name="coframe:${name}"]`);
|
|
3768
4035
|
return (tag === null || tag === void 0 ? void 0 : tag.getAttribute('content')) || undefined;
|
|
3769
4036
|
}
|
|
3770
4037
|
function heatmapActive() {
|
|
3771
|
-
return enabled &&
|
|
4038
|
+
return (enabled &&
|
|
4039
|
+
(allPages || !!meta('page')) &&
|
|
4040
|
+
readVisitorConsent(optOut).state === 'allowed');
|
|
3772
4041
|
}
|
|
3773
4042
|
function pageFields(withHeight) {
|
|
3774
4043
|
const fields = {
|
|
@@ -3795,6 +4064,84 @@ function restartCounters(depth) {
|
|
|
3795
4064
|
engagedMs = 0;
|
|
3796
4065
|
visibleSince = document.hidden ? null : Date.now();
|
|
3797
4066
|
}
|
|
4067
|
+
function syncConsent() {
|
|
4068
|
+
const consent = readVisitorConsent(optOut);
|
|
4069
|
+
reportConsent(consent);
|
|
4070
|
+
const allowed = consent.state === 'allowed';
|
|
4071
|
+
if (allowed && !measuring)
|
|
4072
|
+
restartCounters(viewportBottom());
|
|
4073
|
+
else if (!allowed && measuring) {
|
|
4074
|
+
stripQueued();
|
|
4075
|
+
maxDepth = 0;
|
|
4076
|
+
engagedMs = 0;
|
|
4077
|
+
visibleSince = null;
|
|
4078
|
+
}
|
|
4079
|
+
measuring = allowed;
|
|
4080
|
+
return allowed;
|
|
4081
|
+
}
|
|
4082
|
+
function reportConsent(consent) {
|
|
4083
|
+
if (!coframe)
|
|
4084
|
+
return;
|
|
4085
|
+
if (consentView !== coframe.sessionId) {
|
|
4086
|
+
clearTimeout(consentTimer);
|
|
4087
|
+
consentTimer = undefined;
|
|
4088
|
+
consentView = coframe.sessionId;
|
|
4089
|
+
consentSince = Date.now();
|
|
4090
|
+
consentDone = !allPages && !meta('page');
|
|
4091
|
+
}
|
|
4092
|
+
if (consentDone)
|
|
4093
|
+
return;
|
|
4094
|
+
let type = 'heatmap_skipped';
|
|
4095
|
+
let metadata;
|
|
4096
|
+
if (consent.state === 'allowed') {
|
|
4097
|
+
type = 'heatmap_consent_allowed';
|
|
4098
|
+
metadata = { source: consent.source };
|
|
4099
|
+
}
|
|
4100
|
+
else if (consent.state === 'denied') {
|
|
4101
|
+
metadata = { reason: consent.reason };
|
|
4102
|
+
}
|
|
4103
|
+
else {
|
|
4104
|
+
const shopify = window.Shopify !== undefined;
|
|
4105
|
+
const left = consentSince +
|
|
4106
|
+
(shopify
|
|
4107
|
+
? CONSENT_WAIT_MS
|
|
4108
|
+
: consent.detected
|
|
4109
|
+
? EXPLICIT_CONSENT_WAIT_MS
|
|
4110
|
+
: CONSENT_DETECT_WAIT_MS) -
|
|
4111
|
+
Date.now();
|
|
4112
|
+
if (left > 0) {
|
|
4113
|
+
if (!consentTimer)
|
|
4114
|
+
consentTimer = setTimeout(() => {
|
|
4115
|
+
consentTimer = undefined;
|
|
4116
|
+
syncConsent();
|
|
4117
|
+
}, left);
|
|
4118
|
+
return;
|
|
4119
|
+
}
|
|
4120
|
+
metadata = {
|
|
4121
|
+
reason: shopify || consent.detected
|
|
4122
|
+
? 'consent_unavailable'
|
|
4123
|
+
: 'consent_not_configured',
|
|
4124
|
+
};
|
|
4125
|
+
}
|
|
4126
|
+
consentDone = true;
|
|
4127
|
+
clearTimeout(consentTimer);
|
|
4128
|
+
consentTimer = undefined;
|
|
4129
|
+
try {
|
|
4130
|
+
queueMonitoringEvent(coframe, createMonitoringPayload(coframe, type, metadata));
|
|
4131
|
+
}
|
|
4132
|
+
catch (_a) { }
|
|
4133
|
+
}
|
|
4134
|
+
function syncConsentBeforeFlush() {
|
|
4135
|
+
if (!syncConsent())
|
|
4136
|
+
stripQueued();
|
|
4137
|
+
}
|
|
4138
|
+
function heatmapPageView() {
|
|
4139
|
+
if (enabled)
|
|
4140
|
+
syncConsent();
|
|
4141
|
+
}
|
|
4142
|
+
function syncConsentSoon() {
|
|
4143
|
+
setTimeout(syncConsent, 0);
|
|
4144
|
+
}
|
|
3798
4145
|
function syncPageView() {
|
|
3799
4146
|
if (!coframe || coframe.sessionId === pageView)
|
|
3800
4147
|
return;
|
|
@@ -3807,9 +4154,15 @@ function syncPageView() {
|
|
|
3807
4154
|
function onScroll() {
|
|
3808
4155
|
markActivity();
|
|
3809
4156
|
syncPageView();
|
|
3810
|
-
|
|
4157
|
+
if (syncConsent())
|
|
4158
|
+
maxDepth = Math.max(maxDepth, viewportBottom());
|
|
3811
4159
|
}
|
|
3812
4160
|
function onVisibility() {
|
|
4161
|
+
if (!syncConsent()) {
|
|
4162
|
+
if (document.hidden)
|
|
4163
|
+
releaseHeldClicks();
|
|
4164
|
+
return;
|
|
4165
|
+
}
|
|
3813
4166
|
if (document.hidden) {
|
|
3814
4167
|
if (visibleSince !== null)
|
|
3815
4168
|
engagedMs += Date.now() - visibleSince;
|
|
@@ -3832,15 +4185,18 @@ function readBlockSelector(selector) {
|
|
|
3832
4185
|
}
|
|
3833
4186
|
}
|
|
3834
4187
|
function startHeatmaps(target, project) {
|
|
3835
|
-
var _a, _b;
|
|
4188
|
+
var _a, _b, _c;
|
|
3836
4189
|
const settings = (_a = project === null || project === void 0 ? void 0 : project.settings) === null || _a === void 0 ? void 0 : _a.heatmaps;
|
|
3837
4190
|
if (enabled || !(settings === null || settings === void 0 ? void 0 : settings.enabled))
|
|
3838
4191
|
return;
|
|
3839
4192
|
enabled = true;
|
|
3840
4193
|
allPages = !!settings.all_pages;
|
|
3841
|
-
|
|
4194
|
+
optOut = collectsWithoutChoice(settings.consent_model, (_b = target.personalizationHeaders) === null || _b === void 0 ? void 0 : _b['x-viewer-country']);
|
|
4195
|
+
blockSelector = readBlockSelector((_c = project.settings.session_replay) === null || _c === void 0 ? void 0 : _c.block_selector);
|
|
3842
4196
|
coframe = target;
|
|
3843
4197
|
syncPageView();
|
|
4198
|
+
syncConsent();
|
|
4199
|
+
setBeforeFlush(syncConsentBeforeFlush);
|
|
3844
4200
|
document.addEventListener('scroll', onScroll, {
|
|
3845
4201
|
capture: true,
|
|
3846
4202
|
passive: true,
|
|
@@ -3848,11 +4204,19 @@ function startHeatmaps(target, project) {
|
|
|
3848
4204
|
document.addEventListener('visibilitychange', onVisibility);
|
|
3849
4205
|
window.addEventListener('pagehide', releaseHeldClicks);
|
|
3850
4206
|
window.addEventListener('beforeunload', releaseHeldClicks);
|
|
4207
|
+
document.addEventListener('click', syncConsentSoon, true);
|
|
4208
|
+
for (const name of CONSENT_EVENTS)
|
|
4209
|
+
window.addEventListener(name, syncConsentSoon);
|
|
4210
|
+
if (!consentCmdSubscribed) {
|
|
4211
|
+
consentCmdSubscribed = true;
|
|
4212
|
+
subscribeToCmd((cmd) => typeof cmd.cookiesEnabled === 'boolean', () => enabled && syncConsentSoon());
|
|
4213
|
+
}
|
|
3851
4214
|
}
|
|
3852
4215
|
function leaveFields() {
|
|
3853
4216
|
if (!heatmapActive())
|
|
3854
4217
|
return undefined;
|
|
3855
4218
|
syncPageView();
|
|
4219
|
+
syncConsent();
|
|
3856
4220
|
if (navigated)
|
|
3857
4221
|
return undefined;
|
|
3858
4222
|
return {
|
|
@@ -3868,6 +4232,8 @@ function pageLeaveFields() {
|
|
|
3868
4232
|
return undefined;
|
|
3869
4233
|
const fields = leaveFields();
|
|
3870
4234
|
restartCounters(0);
|
|
4235
|
+
if (!measuring)
|
|
4236
|
+
visibleSince = null;
|
|
3871
4237
|
navigated = true;
|
|
3872
4238
|
return fields;
|
|
3873
4239
|
}
|
|
@@ -3882,6 +4248,37 @@ function watchMutations() {
|
|
|
3882
4248
|
subtree: true,
|
|
3883
4249
|
});
|
|
3884
4250
|
}
|
|
4251
|
+
function stripFields(event) {
|
|
4252
|
+
var _a;
|
|
4253
|
+
if (!isRecord(event) || !isRecord(event.content))
|
|
4254
|
+
return;
|
|
4255
|
+
const content = event.content;
|
|
4256
|
+
for (const key of (_a = heatmapContentKeys.get(event)) !== null && _a !== void 0 ? _a : [])
|
|
4257
|
+
delete content[key];
|
|
4258
|
+
heatmapContentKeys.delete(event);
|
|
4259
|
+
const metadata = content.metadata;
|
|
4260
|
+
if (!isRecord(metadata) || !('hm' in metadata))
|
|
4261
|
+
return;
|
|
4262
|
+
delete metadata.hm;
|
|
4263
|
+
if (Object.keys(metadata).length === 0)
|
|
4264
|
+
delete content.metadata;
|
|
4265
|
+
}
|
|
4266
|
+
function stripQueued() {
|
|
4267
|
+
for (let i = queuedEvents.length - 1; i >= 0; i--) {
|
|
4268
|
+
const event = queuedEvents[i];
|
|
4269
|
+
if (isRecord(event) && event.type === 'page_leave')
|
|
4270
|
+
queuedEvents.splice(i, 1);
|
|
4271
|
+
else
|
|
4272
|
+
stripFields(event);
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
function queueHeld(click) {
|
|
4276
|
+
if (!coframe)
|
|
4277
|
+
return;
|
|
4278
|
+
if (readVisitorConsent(optOut).state !== 'allowed')
|
|
4279
|
+
stripFields(click.data);
|
|
4280
|
+
queueEventForBatchedSending(coframe, click.data);
|
|
4281
|
+
}
|
|
3885
4282
|
function settle(click) {
|
|
3886
4283
|
const index = held.indexOf(click);
|
|
3887
4284
|
if (index < 0)
|
|
@@ -3894,8 +4291,7 @@ function settle(click) {
|
|
|
3894
4291
|
location.href === click.href;
|
|
3895
4292
|
click.hm.kind = dead ? 'dead' : 'click';
|
|
3896
4293
|
}
|
|
3897
|
-
|
|
3898
|
-
queueEventForBatchedSending(coframe, click.data);
|
|
4294
|
+
queueHeld(click);
|
|
3899
4295
|
if (observer && !held.some((h) => h.candidate)) {
|
|
3900
4296
|
observer.disconnect();
|
|
3901
4297
|
observer = null;
|
|
@@ -3905,8 +4301,7 @@ function releaseHeldClicks() {
|
|
|
3905
4301
|
for (const click of held.splice(0)) {
|
|
3906
4302
|
if (click.hm.kind === undefined)
|
|
3907
4303
|
click.hm.kind = null;
|
|
3908
|
-
|
|
3909
|
-
queueEventForBatchedSending(coframe, click.data);
|
|
4304
|
+
queueHeld(click);
|
|
3910
4305
|
}
|
|
3911
4306
|
if (observer) {
|
|
3912
4307
|
observer.disconnect();
|
|
@@ -3992,6 +4387,7 @@ function startSession(Coframe, cookiesEnabled, executionStartTime, personalizati
|
|
|
3992
4387
|
{
|
|
3993
4388
|
queueCreateSession(...sessionPayload, undefined, undefined, personalizationHeaders, sessionContext);
|
|
3994
4389
|
}
|
|
4390
|
+
heatmapPageView();
|
|
3995
4391
|
queueEvent(Coframe, {
|
|
3996
4392
|
projectId: Coframe.projectId,
|
|
3997
4393
|
sessionId: Coframe.sessionId,
|
|
@@ -4663,131 +5059,10 @@ async function modifyPage(Coframe, configResult, projectResult, analytics, lifec
|
|
|
4663
5059
|
setupFlushInterval(Coframe);
|
|
4664
5060
|
}
|
|
4665
5061
|
|
|
4666
|
-
function readCookie(name) {
|
|
4667
|
-
const prefix = `${name}=`;
|
|
4668
|
-
const cookies = document.cookie.split(';');
|
|
4669
|
-
for (let i = 0; i < cookies.length; i++) {
|
|
4670
|
-
const cookie = cookies[i].trim();
|
|
4671
|
-
if (cookie.indexOf(prefix) === 0)
|
|
4672
|
-
return decodeURIComponent(cookie.slice(prefix.length));
|
|
4673
|
-
}
|
|
4674
|
-
return undefined;
|
|
4675
|
-
}
|
|
4676
|
-
function readClientCommand() {
|
|
4677
|
-
try {
|
|
4678
|
-
const cmd = findLastCmd((c) => typeof c.cookiesEnabled === 'boolean');
|
|
4679
|
-
if (!cmd)
|
|
4680
|
-
return undefined;
|
|
4681
|
-
return cmd.cookiesEnabled === true ? 'granted' : 'denied';
|
|
4682
|
-
}
|
|
4683
|
-
catch (_a) {
|
|
4684
|
-
return undefined;
|
|
4685
|
-
}
|
|
4686
|
-
}
|
|
4687
|
-
function readOneTrust() {
|
|
4688
|
-
var _a;
|
|
4689
|
-
try {
|
|
4690
|
-
const { OnetrustActiveGroups: groups, OneTrust } = window;
|
|
4691
|
-
if (typeof groups !== 'string' && OneTrust === undefined)
|
|
4692
|
-
return undefined;
|
|
4693
|
-
if (typeof groups === 'string' && groups.split(',').indexOf('C0002') !== -1)
|
|
4694
|
-
return 'granted';
|
|
4695
|
-
return ((_a = OneTrust === null || OneTrust === void 0 ? void 0 : OneTrust.IsAlertBoxClosed) === null || _a === void 0 ? void 0 : _a.call(OneTrust)) === true ? 'denied' : 'pending';
|
|
4696
|
-
}
|
|
4697
|
-
catch (_b) {
|
|
4698
|
-
return undefined;
|
|
4699
|
-
}
|
|
4700
|
-
}
|
|
4701
|
-
function readCookiebot() {
|
|
4702
|
-
var _a;
|
|
4703
|
-
try {
|
|
4704
|
-
const { Cookiebot } = window;
|
|
4705
|
-
if (Cookiebot === undefined)
|
|
4706
|
-
return undefined;
|
|
4707
|
-
if (((_a = Cookiebot.consent) === null || _a === void 0 ? void 0 : _a.statistics) === true)
|
|
4708
|
-
return 'granted';
|
|
4709
|
-
return Cookiebot.hasResponse === true ? 'denied' : 'pending';
|
|
4710
|
-
}
|
|
4711
|
-
catch (_b) {
|
|
4712
|
-
return undefined;
|
|
4713
|
-
}
|
|
4714
|
-
}
|
|
4715
|
-
function readTrueVault() {
|
|
4716
|
-
try {
|
|
4717
|
-
const cookie = readCookie('polaris_consent_settings');
|
|
4718
|
-
if (cookie === undefined)
|
|
4719
|
-
return undefined;
|
|
4720
|
-
const parsed = JSON.parse(cookie);
|
|
4721
|
-
if (parsed.analyticsPermitted === false || parsed.notOptedOut === false) {
|
|
4722
|
-
return 'denied';
|
|
4723
|
-
}
|
|
4724
|
-
if (parsed.implicit === false && parsed.analyticsPermitted === true)
|
|
4725
|
-
return 'granted';
|
|
4726
|
-
return 'pending';
|
|
4727
|
-
}
|
|
4728
|
-
catch (_a) {
|
|
4729
|
-
return undefined;
|
|
4730
|
-
}
|
|
4731
|
-
}
|
|
4732
|
-
function readUsPrivacy() {
|
|
4733
|
-
try {
|
|
4734
|
-
const cookie = readCookie('us_privacy');
|
|
4735
|
-
if (cookie !== undefined &&
|
|
4736
|
-
/^1[YN-]{3}$/i.test(cookie) &&
|
|
4737
|
-
(cookie[2] === 'Y' || cookie[2] === 'y')) {
|
|
4738
|
-
return 'denied';
|
|
4739
|
-
}
|
|
4740
|
-
return undefined;
|
|
4741
|
-
}
|
|
4742
|
-
catch (_a) {
|
|
4743
|
-
return undefined;
|
|
4744
|
-
}
|
|
4745
|
-
}
|
|
4746
|
-
function readConsentMode() {
|
|
4747
|
-
var _a;
|
|
4748
|
-
try {
|
|
4749
|
-
const { dataLayer } = window;
|
|
4750
|
-
if (!Array.isArray(dataLayer))
|
|
4751
|
-
return undefined;
|
|
4752
|
-
let update;
|
|
4753
|
-
let defaultGranted = false;
|
|
4754
|
-
let defaultDenied = false;
|
|
4755
|
-
for (let i = 0; i < dataLayer.length; i++) {
|
|
4756
|
-
const entry = dataLayer[i];
|
|
4757
|
-
if (entry === null ||
|
|
4758
|
-
typeof entry !== 'object' ||
|
|
4759
|
-
entry[0] !== 'consent' ||
|
|
4760
|
-
(entry[1] !== 'default' && entry[1] !== 'update')) {
|
|
4761
|
-
continue;
|
|
4762
|
-
}
|
|
4763
|
-
const storage = (_a = entry[2]) === null || _a === void 0 ? void 0 : _a.analytics_storage;
|
|
4764
|
-
if (storage !== 'granted' && storage !== 'denied')
|
|
4765
|
-
continue;
|
|
4766
|
-
if (entry[1] === 'update')
|
|
4767
|
-
update = storage;
|
|
4768
|
-
else if (storage === 'denied')
|
|
4769
|
-
defaultDenied = true;
|
|
4770
|
-
else
|
|
4771
|
-
defaultGranted = true;
|
|
4772
|
-
}
|
|
4773
|
-
if (update !== undefined)
|
|
4774
|
-
return update;
|
|
4775
|
-
if (defaultDenied)
|
|
4776
|
-
return 'pending';
|
|
4777
|
-
return defaultGranted ? 'granted' : undefined;
|
|
4778
|
-
}
|
|
4779
|
-
catch (_b) {
|
|
4780
|
-
return undefined;
|
|
4781
|
-
}
|
|
4782
|
-
}
|
|
4783
|
-
|
|
4784
5062
|
let startRequested = false;
|
|
4785
5063
|
let replayScriptUrl;
|
|
4786
5064
|
const COMPILED_REPLAY_SCRIPT_URL = `${"https://edge.cofra.me"}/replay/latest.js`;
|
|
4787
5065
|
const CONSENT_POLL_MS = 100;
|
|
4788
|
-
const CONSENT_WAIT_MS = 5000;
|
|
4789
|
-
const CONSENT_DETECT_WAIT_MS = 10000;
|
|
4790
|
-
const EXPLICIT_CONSENT_WAIT_MS = 60000;
|
|
4791
5066
|
function configureReplayScriptUrl(url) {
|
|
4792
5067
|
replayScriptUrl = (url === null || url === void 0 ? void 0 : url.trim()) || undefined;
|
|
4793
5068
|
}
|
|
@@ -4795,71 +5070,7 @@ function isOptOut(settings) {
|
|
|
4795
5070
|
return settings.consent_model === 'opt_out';
|
|
4796
5071
|
}
|
|
4797
5072
|
function readReplayConsent(settings) {
|
|
4798
|
-
|
|
4799
|
-
if (navigator
|
|
4800
|
-
.globalPrivacyControl === true) {
|
|
4801
|
-
return { state: 'denied', reason: 'gpc' };
|
|
4802
|
-
}
|
|
4803
|
-
const shopify = window.Shopify;
|
|
4804
|
-
if (shopify === undefined) {
|
|
4805
|
-
if (readUsPrivacy() === 'denied')
|
|
4806
|
-
return { state: 'denied', reason: 'consent_denied' };
|
|
4807
|
-
if (isWaitingForCookies()) {
|
|
4808
|
-
const signal = readClientCommand();
|
|
4809
|
-
if (signal === 'granted')
|
|
4810
|
-
return { state: 'allowed', source: 'client' };
|
|
4811
|
-
if (signal === 'denied')
|
|
4812
|
-
return { state: 'denied', reason: 'consent_denied' };
|
|
4813
|
-
return { state: 'pending', detected: true };
|
|
4814
|
-
}
|
|
4815
|
-
const readers = [
|
|
4816
|
-
[readClientCommand, 'client'],
|
|
4817
|
-
[readOneTrust, 'onetrust'],
|
|
4818
|
-
[readCookiebot, 'cookiebot'],
|
|
4819
|
-
[readTrueVault, 'truevault'],
|
|
4820
|
-
[readConsentMode, 'consent_mode'],
|
|
4821
|
-
];
|
|
4822
|
-
for (let i = 0; i < readers.length; i++) {
|
|
4823
|
-
const [read, source] = readers[i];
|
|
4824
|
-
const signal = read();
|
|
4825
|
-
if (signal === 'granted')
|
|
4826
|
-
return { state: 'allowed', source };
|
|
4827
|
-
if (signal === 'denied')
|
|
4828
|
-
return { state: 'denied', reason: 'consent_denied' };
|
|
4829
|
-
if (signal === 'pending') {
|
|
4830
|
-
if (isOptOut(settings))
|
|
4831
|
-
continue;
|
|
4832
|
-
return { state: 'pending', detected: true };
|
|
4833
|
-
}
|
|
4834
|
-
}
|
|
4835
|
-
if (isOptOut(settings))
|
|
4836
|
-
return { state: 'allowed', source: 'opt_out' };
|
|
4837
|
-
return { state: 'pending', detected: isWaitingForCookies() };
|
|
4838
|
-
}
|
|
4839
|
-
const customerPrivacy = shopify.customerPrivacy;
|
|
4840
|
-
const analyticsProcessingAllowed = customerPrivacy === null || customerPrivacy === void 0 ? void 0 : customerPrivacy.analyticsProcessingAllowed;
|
|
4841
|
-
if (typeof analyticsProcessingAllowed === 'function') {
|
|
4842
|
-
return analyticsProcessingAllowed.call(customerPrivacy) === true
|
|
4843
|
-
? { state: 'allowed', source: 'shopify' }
|
|
4844
|
-
: { state: 'denied', reason: 'consent_denied' };
|
|
4845
|
-
}
|
|
4846
|
-
return { state: 'pending' };
|
|
4847
|
-
}
|
|
4848
|
-
catch (_a) {
|
|
4849
|
-
return { state: 'denied', reason: 'consent_unavailable' };
|
|
4850
|
-
}
|
|
4851
|
-
}
|
|
4852
|
-
function createMonitoringPayload(coframe, monitoringType, metadata) {
|
|
4853
|
-
return {
|
|
4854
|
-
event_id: generateUUID(),
|
|
4855
|
-
monitoring_type: monitoringType,
|
|
4856
|
-
local_time: new Date().toISOString(),
|
|
4857
|
-
project_id: coframe.projectId,
|
|
4858
|
-
session_id: coframe.sessionId,
|
|
4859
|
-
url: location.href,
|
|
4860
|
-
org_id: coframe.orgId,
|
|
4861
|
-
metadata,
|
|
4862
|
-
};
|
|
5073
|
+
return readVisitorConsent(isOptOut(settings));
|
|
4863
5074
|
}
|
|
4864
5075
|
function reportStartFailure(coframe, reason) {
|
|
4865
5076
|
try {
|