@coframe/sdk 1.1.41 → 1.1.42

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.
@@ -1105,6 +1105,9 @@ let waitingForCookies = false;
1105
1105
  const setWaitingForCookies = (value) => {
1106
1106
  waitingForCookies = value;
1107
1107
  };
1108
+ function isWaitingForCookies() {
1109
+ return waitingForCookies;
1110
+ }
1108
1111
  let frameActivated = false;
1109
1112
  const setFrameActivated = (value) => {
1110
1113
  frameActivated = value;
@@ -4185,11 +4188,90 @@ async function modifyPage(Coframe, configResult, projectResult, analytics) {
4185
4188
  setupFlushInterval(Coframe);
4186
4189
  }
4187
4190
 
4191
+ function readClientCommand() {
4192
+ try {
4193
+ const cmd = findLastCmd((c) => typeof c.cookiesEnabled === 'boolean');
4194
+ if (!cmd)
4195
+ return undefined;
4196
+ return cmd.cookiesEnabled === true ? 'granted' : 'denied';
4197
+ }
4198
+ catch (_a) {
4199
+ return undefined;
4200
+ }
4201
+ }
4202
+ function readOneTrust() {
4203
+ var _a;
4204
+ try {
4205
+ const { OnetrustActiveGroups: groups, OneTrust } = window;
4206
+ if (typeof groups !== 'string' && OneTrust === undefined)
4207
+ return undefined;
4208
+ if (typeof groups === 'string' && groups.split(',').indexOf('C0002') !== -1)
4209
+ return 'granted';
4210
+ return ((_a = OneTrust === null || OneTrust === void 0 ? void 0 : OneTrust.IsAlertBoxClosed) === null || _a === void 0 ? void 0 : _a.call(OneTrust)) === true ? 'denied' : 'pending';
4211
+ }
4212
+ catch (_b) {
4213
+ return undefined;
4214
+ }
4215
+ }
4216
+ function readCookiebot() {
4217
+ var _a;
4218
+ try {
4219
+ const { Cookiebot } = window;
4220
+ if (Cookiebot === undefined)
4221
+ return undefined;
4222
+ if (((_a = Cookiebot.consent) === null || _a === void 0 ? void 0 : _a.statistics) === true)
4223
+ return 'granted';
4224
+ return Cookiebot.hasResponse === true ? 'denied' : 'pending';
4225
+ }
4226
+ catch (_b) {
4227
+ return undefined;
4228
+ }
4229
+ }
4230
+ function readConsentMode() {
4231
+ var _a;
4232
+ try {
4233
+ const { dataLayer } = window;
4234
+ if (!Array.isArray(dataLayer))
4235
+ return undefined;
4236
+ let update;
4237
+ let defaultGranted = false;
4238
+ let defaultDenied = false;
4239
+ for (let i = 0; i < dataLayer.length; i++) {
4240
+ const entry = dataLayer[i];
4241
+ if (entry === null ||
4242
+ typeof entry !== 'object' ||
4243
+ entry[0] !== 'consent' ||
4244
+ (entry[1] !== 'default' && entry[1] !== 'update')) {
4245
+ continue;
4246
+ }
4247
+ const storage = (_a = entry[2]) === null || _a === void 0 ? void 0 : _a.analytics_storage;
4248
+ if (storage !== 'granted' && storage !== 'denied')
4249
+ continue;
4250
+ if (entry[1] === 'update')
4251
+ update = storage;
4252
+ else if (storage === 'denied')
4253
+ defaultDenied = true;
4254
+ else
4255
+ defaultGranted = true;
4256
+ }
4257
+ if (update !== undefined)
4258
+ return update;
4259
+ if (defaultDenied)
4260
+ return 'pending';
4261
+ return defaultGranted ? 'granted' : undefined;
4262
+ }
4263
+ catch (_b) {
4264
+ return undefined;
4265
+ }
4266
+ }
4267
+
4188
4268
  let startRequested = false;
4189
4269
  let replayScriptUrl;
4190
4270
  const COMPILED_REPLAY_SCRIPT_URL = `${"https://edge.cofra.me"}/replay/latest.js`;
4191
4271
  const CONSENT_POLL_MS = 100;
4192
4272
  const CONSENT_WAIT_MS = 5000;
4273
+ const CONSENT_DETECT_WAIT_MS = 10000;
4274
+ const EXPLICIT_CONSENT_WAIT_MS = 60000;
4193
4275
  function configureReplayScriptUrl(url) {
4194
4276
  replayScriptUrl = (url === null || url === void 0 ? void 0 : url.trim()) || undefined;
4195
4277
  }
@@ -4200,8 +4282,25 @@ function readReplayConsent() {
4200
4282
  return { state: 'denied', reason: 'gpc' };
4201
4283
  }
4202
4284
  const shopify = window.Shopify;
4203
- if (shopify === undefined)
4204
- return { state: 'allowed', source: 'none' };
4285
+ if (shopify === undefined) {
4286
+ const readers = [
4287
+ [readClientCommand, 'client'],
4288
+ [readOneTrust, 'onetrust'],
4289
+ [readCookiebot, 'cookiebot'],
4290
+ [readConsentMode, 'consent_mode'],
4291
+ ];
4292
+ for (let i = 0; i < readers.length; i++) {
4293
+ const [read, source] = readers[i];
4294
+ const signal = read();
4295
+ if (signal === 'granted')
4296
+ return { state: 'allowed', source };
4297
+ if (signal === 'denied')
4298
+ return { state: 'denied', reason: 'consent_denied' };
4299
+ if (signal === 'pending')
4300
+ return { state: 'pending', detected: true };
4301
+ }
4302
+ return { state: 'pending', detected: isWaitingForCookies() };
4303
+ }
4205
4304
  const customerPrivacy = shopify.customerPrivacy;
4206
4305
  const analyticsProcessingAllowed = customerPrivacy === null || customerPrivacy === void 0 ? void 0 : customerPrivacy.analyticsProcessingAllowed;
4207
4306
  if (typeof analyticsProcessingAllowed === 'function') {
@@ -4303,11 +4402,14 @@ function startReplayIfEnabled(coframe, project, nonce) {
4303
4402
  const settings = (_a = project.settings) === null || _a === void 0 ? void 0 : _a.session_replay;
4304
4403
  if ((settings === null || settings === void 0 ? void 0 : settings.enabled) !== true ||
4305
4404
  typeof CompressionStream !== 'function' ||
4306
- !shouldSendEvents() ||
4405
+ !shouldSendEvents({
4406
+ ignoreConsent: window.Shopify === undefined,
4407
+ }) ||
4307
4408
  startRequested) {
4308
4409
  return;
4309
4410
  }
4310
4411
  startRequested = true;
4412
+ const isShopify = window.Shopify !== undefined;
4311
4413
  let waited = 0;
4312
4414
  const decide = () => {
4313
4415
  var _a;
@@ -4318,7 +4420,12 @@ function startReplayIfEnabled(coframe, project, nonce) {
4318
4420
  else if (consent.state === 'denied') {
4319
4421
  reportReplaySkipped(coframe, consent.reason);
4320
4422
  }
4321
- else if (waited >= CONSENT_WAIT_MS) {
4423
+ else if (!isShopify &&
4424
+ consent.detected !== true &&
4425
+ waited >= CONSENT_DETECT_WAIT_MS) {
4426
+ reportReplaySkipped(coframe, 'consent_not_configured');
4427
+ }
4428
+ else if (waited >= (isShopify ? CONSENT_WAIT_MS : EXPLICIT_CONSENT_WAIT_MS)) {
4322
4429
  reportReplaySkipped(coframe, 'consent_unavailable');
4323
4430
  }
4324
4431
  else {
@@ -1103,6 +1103,9 @@ let waitingForCookies = false;
1103
1103
  const setWaitingForCookies = (value) => {
1104
1104
  waitingForCookies = value;
1105
1105
  };
1106
+ function isWaitingForCookies() {
1107
+ return waitingForCookies;
1108
+ }
1106
1109
  let frameActivated = false;
1107
1110
  const setFrameActivated = (value) => {
1108
1111
  frameActivated = value;
@@ -4183,11 +4186,90 @@ async function modifyPage(Coframe, configResult, projectResult, analytics) {
4183
4186
  setupFlushInterval(Coframe);
4184
4187
  }
4185
4188
 
4189
+ function readClientCommand() {
4190
+ try {
4191
+ const cmd = findLastCmd((c) => typeof c.cookiesEnabled === 'boolean');
4192
+ if (!cmd)
4193
+ return undefined;
4194
+ return cmd.cookiesEnabled === true ? 'granted' : 'denied';
4195
+ }
4196
+ catch (_a) {
4197
+ return undefined;
4198
+ }
4199
+ }
4200
+ function readOneTrust() {
4201
+ var _a;
4202
+ try {
4203
+ const { OnetrustActiveGroups: groups, OneTrust } = window;
4204
+ if (typeof groups !== 'string' && OneTrust === undefined)
4205
+ return undefined;
4206
+ if (typeof groups === 'string' && groups.split(',').indexOf('C0002') !== -1)
4207
+ return 'granted';
4208
+ return ((_a = OneTrust === null || OneTrust === void 0 ? void 0 : OneTrust.IsAlertBoxClosed) === null || _a === void 0 ? void 0 : _a.call(OneTrust)) === true ? 'denied' : 'pending';
4209
+ }
4210
+ catch (_b) {
4211
+ return undefined;
4212
+ }
4213
+ }
4214
+ function readCookiebot() {
4215
+ var _a;
4216
+ try {
4217
+ const { Cookiebot } = window;
4218
+ if (Cookiebot === undefined)
4219
+ return undefined;
4220
+ if (((_a = Cookiebot.consent) === null || _a === void 0 ? void 0 : _a.statistics) === true)
4221
+ return 'granted';
4222
+ return Cookiebot.hasResponse === true ? 'denied' : 'pending';
4223
+ }
4224
+ catch (_b) {
4225
+ return undefined;
4226
+ }
4227
+ }
4228
+ function readConsentMode() {
4229
+ var _a;
4230
+ try {
4231
+ const { dataLayer } = window;
4232
+ if (!Array.isArray(dataLayer))
4233
+ return undefined;
4234
+ let update;
4235
+ let defaultGranted = false;
4236
+ let defaultDenied = false;
4237
+ for (let i = 0; i < dataLayer.length; i++) {
4238
+ const entry = dataLayer[i];
4239
+ if (entry === null ||
4240
+ typeof entry !== 'object' ||
4241
+ entry[0] !== 'consent' ||
4242
+ (entry[1] !== 'default' && entry[1] !== 'update')) {
4243
+ continue;
4244
+ }
4245
+ const storage = (_a = entry[2]) === null || _a === void 0 ? void 0 : _a.analytics_storage;
4246
+ if (storage !== 'granted' && storage !== 'denied')
4247
+ continue;
4248
+ if (entry[1] === 'update')
4249
+ update = storage;
4250
+ else if (storage === 'denied')
4251
+ defaultDenied = true;
4252
+ else
4253
+ defaultGranted = true;
4254
+ }
4255
+ if (update !== undefined)
4256
+ return update;
4257
+ if (defaultDenied)
4258
+ return 'pending';
4259
+ return defaultGranted ? 'granted' : undefined;
4260
+ }
4261
+ catch (_b) {
4262
+ return undefined;
4263
+ }
4264
+ }
4265
+
4186
4266
  let startRequested = false;
4187
4267
  let replayScriptUrl;
4188
4268
  const COMPILED_REPLAY_SCRIPT_URL = `${"https://edge.cofra.me"}/replay/latest.js`;
4189
4269
  const CONSENT_POLL_MS = 100;
4190
4270
  const CONSENT_WAIT_MS = 5000;
4271
+ const CONSENT_DETECT_WAIT_MS = 10000;
4272
+ const EXPLICIT_CONSENT_WAIT_MS = 60000;
4191
4273
  function configureReplayScriptUrl(url) {
4192
4274
  replayScriptUrl = (url === null || url === void 0 ? void 0 : url.trim()) || undefined;
4193
4275
  }
@@ -4198,8 +4280,25 @@ function readReplayConsent() {
4198
4280
  return { state: 'denied', reason: 'gpc' };
4199
4281
  }
4200
4282
  const shopify = window.Shopify;
4201
- if (shopify === undefined)
4202
- return { state: 'allowed', source: 'none' };
4283
+ if (shopify === undefined) {
4284
+ const readers = [
4285
+ [readClientCommand, 'client'],
4286
+ [readOneTrust, 'onetrust'],
4287
+ [readCookiebot, 'cookiebot'],
4288
+ [readConsentMode, 'consent_mode'],
4289
+ ];
4290
+ for (let i = 0; i < readers.length; i++) {
4291
+ const [read, source] = readers[i];
4292
+ const signal = read();
4293
+ if (signal === 'granted')
4294
+ return { state: 'allowed', source };
4295
+ if (signal === 'denied')
4296
+ return { state: 'denied', reason: 'consent_denied' };
4297
+ if (signal === 'pending')
4298
+ return { state: 'pending', detected: true };
4299
+ }
4300
+ return { state: 'pending', detected: isWaitingForCookies() };
4301
+ }
4203
4302
  const customerPrivacy = shopify.customerPrivacy;
4204
4303
  const analyticsProcessingAllowed = customerPrivacy === null || customerPrivacy === void 0 ? void 0 : customerPrivacy.analyticsProcessingAllowed;
4205
4304
  if (typeof analyticsProcessingAllowed === 'function') {
@@ -4301,11 +4400,14 @@ function startReplayIfEnabled(coframe, project, nonce) {
4301
4400
  const settings = (_a = project.settings) === null || _a === void 0 ? void 0 : _a.session_replay;
4302
4401
  if ((settings === null || settings === void 0 ? void 0 : settings.enabled) !== true ||
4303
4402
  typeof CompressionStream !== 'function' ||
4304
- !shouldSendEvents() ||
4403
+ !shouldSendEvents({
4404
+ ignoreConsent: window.Shopify === undefined,
4405
+ }) ||
4305
4406
  startRequested) {
4306
4407
  return;
4307
4408
  }
4308
4409
  startRequested = true;
4410
+ const isShopify = window.Shopify !== undefined;
4309
4411
  let waited = 0;
4310
4412
  const decide = () => {
4311
4413
  var _a;
@@ -4316,7 +4418,12 @@ function startReplayIfEnabled(coframe, project, nonce) {
4316
4418
  else if (consent.state === 'denied') {
4317
4419
  reportReplaySkipped(coframe, consent.reason);
4318
4420
  }
4319
- else if (waited >= CONSENT_WAIT_MS) {
4421
+ else if (!isShopify &&
4422
+ consent.detected !== true &&
4423
+ waited >= CONSENT_DETECT_WAIT_MS) {
4424
+ reportReplaySkipped(coframe, 'consent_not_configured');
4425
+ }
4426
+ else if (waited >= (isShopify ? CONSENT_WAIT_MS : EXPLICIT_CONSENT_WAIT_MS)) {
4320
4427
  reportReplaySkipped(coframe, 'consent_unavailable');
4321
4428
  }
4322
4429
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coframe/sdk",
3
- "version": "1.1.41",
3
+ "version": "1.1.42",
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",