@coframe/sdk 1.1.48 → 1.1.50

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.
@@ -2123,7 +2123,13 @@ const applyVariantChanges = (variantElements, currentUrl, logger, nonce, lifecyc
2123
2123
  });
2124
2124
  }
2125
2125
  else if (selectedElement instanceof HTMLElement) {
2126
- selectedElement.setAttribute('coframe-exp-id', variant.experiment_id);
2126
+ const listAttribute = 'coframe-experiment-ids';
2127
+ const listed = selectedElement.getAttribute(listAttribute);
2128
+ const experimentIds = listed ? listed.split(',') : [];
2129
+ if (experimentIds.indexOf(variant.experiment_id) === -1) {
2130
+ experimentIds.push(variant.experiment_id);
2131
+ selectedElement.setAttribute(listAttribute, experimentIds.join(','));
2132
+ }
2127
2133
  }
2128
2134
  }
2129
2135
  return true;
@@ -4200,8 +4206,11 @@ function setupListeners(Coframe, executionStartTime) {
4200
4206
  for (const variantElement of Coframe.variantsAndElements || []) {
4201
4207
  const variant = variantElement.variant;
4202
4208
  if (!experiencedCoframeIds.has(variant.id)) {
4203
- const elements = document.querySelectorAll(`[coframe-exp-id="${variant.experiment_id}"]`);
4209
+ const elements = document.querySelectorAll('[coframe-experiment-ids]');
4204
4210
  for (const el of Array.from(elements)) {
4211
+ const experimentIds = (el.getAttribute('coframe-experiment-ids') || '').split(',');
4212
+ if (experimentIds.indexOf(variant.experiment_id) === -1)
4213
+ continue;
4205
4214
  if (isElementVisible(el)) {
4206
4215
  el.setAttribute('coframe-experienced', 'true');
4207
4216
  experiencedCoframeIds.add(variant.id);
@@ -4656,6 +4665,16 @@ async function modifyPage(Coframe, configResult, projectResult, analytics, lifec
4656
4665
  setupFlushInterval(Coframe);
4657
4666
  }
4658
4667
 
4668
+ function readCookie(name) {
4669
+ const prefix = `${name}=`;
4670
+ const cookies = document.cookie.split(';');
4671
+ for (let i = 0; i < cookies.length; i++) {
4672
+ const cookie = cookies[i].trim();
4673
+ if (cookie.indexOf(prefix) === 0)
4674
+ return decodeURIComponent(cookie.slice(prefix.length));
4675
+ }
4676
+ return undefined;
4677
+ }
4659
4678
  function readClientCommand() {
4660
4679
  try {
4661
4680
  const cmd = findLastCmd((c) => typeof c.cookiesEnabled === 'boolean');
@@ -4695,6 +4714,37 @@ function readCookiebot() {
4695
4714
  return undefined;
4696
4715
  }
4697
4716
  }
4717
+ function readTrueVault() {
4718
+ try {
4719
+ const cookie = readCookie('polaris_consent_settings');
4720
+ if (cookie === undefined)
4721
+ return undefined;
4722
+ const parsed = JSON.parse(cookie);
4723
+ if (parsed.analyticsPermitted === false || parsed.notOptedOut === false) {
4724
+ return 'denied';
4725
+ }
4726
+ if (parsed.implicit === false && parsed.analyticsPermitted === true)
4727
+ return 'granted';
4728
+ return 'pending';
4729
+ }
4730
+ catch (_a) {
4731
+ return undefined;
4732
+ }
4733
+ }
4734
+ function readUsPrivacy() {
4735
+ try {
4736
+ const cookie = readCookie('us_privacy');
4737
+ if (cookie !== undefined &&
4738
+ /^1[YN-]{3}$/i.test(cookie) &&
4739
+ (cookie[2] === 'Y' || cookie[2] === 'y')) {
4740
+ return 'denied';
4741
+ }
4742
+ return undefined;
4743
+ }
4744
+ catch (_a) {
4745
+ return undefined;
4746
+ }
4747
+ }
4698
4748
  function readConsentMode() {
4699
4749
  var _a;
4700
4750
  try {
@@ -4743,6 +4793,11 @@ const EXPLICIT_CONSENT_WAIT_MS = 60000;
4743
4793
  function configureReplayScriptUrl(url) {
4744
4794
  replayScriptUrl = (url === null || url === void 0 ? void 0 : url.trim()) || undefined;
4745
4795
  }
4796
+ function isOptOut(settings) {
4797
+ return (settings.consent_model === 'opt_out' ||
4798
+ (settings.consent_model === undefined &&
4799
+ settings.consent_required === false));
4800
+ }
4746
4801
  function readReplayConsent(settings) {
4747
4802
  try {
4748
4803
  if (navigator
@@ -4751,10 +4806,13 @@ function readReplayConsent(settings) {
4751
4806
  }
4752
4807
  const shopify = window.Shopify;
4753
4808
  if (shopify === undefined) {
4809
+ if (readUsPrivacy() === 'denied')
4810
+ return { state: 'denied', reason: 'consent_denied' };
4754
4811
  const readers = [
4755
4812
  [readClientCommand, 'client'],
4756
4813
  [readOneTrust, 'onetrust'],
4757
4814
  [readCookiebot, 'cookiebot'],
4815
+ [readTrueVault, 'truevault'],
4758
4816
  [readConsentMode, 'consent_mode'],
4759
4817
  ];
4760
4818
  for (let i = 0; i < readers.length; i++) {
@@ -4765,13 +4823,13 @@ function readReplayConsent(settings) {
4765
4823
  if (signal === 'denied')
4766
4824
  return { state: 'denied', reason: 'consent_denied' };
4767
4825
  if (signal === 'pending') {
4768
- if (settings.consent_required === false)
4826
+ if (isOptOut(settings))
4769
4827
  continue;
4770
4828
  return { state: 'pending', detected: true };
4771
4829
  }
4772
4830
  }
4773
- if (settings.consent_required === false)
4774
- return { state: 'allowed', source: 'not_required' };
4831
+ if (isOptOut(settings))
4832
+ return { state: 'allowed', source: 'opt_out' };
4775
4833
  return { state: 'pending', detected: isWaitingForCookies() };
4776
4834
  }
4777
4835
  const customerPrivacy = shopify.customerPrivacy;
@@ -2121,7 +2121,13 @@ const applyVariantChanges = (variantElements, currentUrl, logger, nonce, lifecyc
2121
2121
  });
2122
2122
  }
2123
2123
  else if (selectedElement instanceof HTMLElement) {
2124
- selectedElement.setAttribute('coframe-exp-id', variant.experiment_id);
2124
+ const listAttribute = 'coframe-experiment-ids';
2125
+ const listed = selectedElement.getAttribute(listAttribute);
2126
+ const experimentIds = listed ? listed.split(',') : [];
2127
+ if (experimentIds.indexOf(variant.experiment_id) === -1) {
2128
+ experimentIds.push(variant.experiment_id);
2129
+ selectedElement.setAttribute(listAttribute, experimentIds.join(','));
2130
+ }
2125
2131
  }
2126
2132
  }
2127
2133
  return true;
@@ -4198,8 +4204,11 @@ function setupListeners(Coframe, executionStartTime) {
4198
4204
  for (const variantElement of Coframe.variantsAndElements || []) {
4199
4205
  const variant = variantElement.variant;
4200
4206
  if (!experiencedCoframeIds.has(variant.id)) {
4201
- const elements = document.querySelectorAll(`[coframe-exp-id="${variant.experiment_id}"]`);
4207
+ const elements = document.querySelectorAll('[coframe-experiment-ids]');
4202
4208
  for (const el of Array.from(elements)) {
4209
+ const experimentIds = (el.getAttribute('coframe-experiment-ids') || '').split(',');
4210
+ if (experimentIds.indexOf(variant.experiment_id) === -1)
4211
+ continue;
4203
4212
  if (isElementVisible(el)) {
4204
4213
  el.setAttribute('coframe-experienced', 'true');
4205
4214
  experiencedCoframeIds.add(variant.id);
@@ -4654,6 +4663,16 @@ async function modifyPage(Coframe, configResult, projectResult, analytics, lifec
4654
4663
  setupFlushInterval(Coframe);
4655
4664
  }
4656
4665
 
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
+ }
4657
4676
  function readClientCommand() {
4658
4677
  try {
4659
4678
  const cmd = findLastCmd((c) => typeof c.cookiesEnabled === 'boolean');
@@ -4693,6 +4712,37 @@ function readCookiebot() {
4693
4712
  return undefined;
4694
4713
  }
4695
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
+ }
4696
4746
  function readConsentMode() {
4697
4747
  var _a;
4698
4748
  try {
@@ -4741,6 +4791,11 @@ const EXPLICIT_CONSENT_WAIT_MS = 60000;
4741
4791
  function configureReplayScriptUrl(url) {
4742
4792
  replayScriptUrl = (url === null || url === void 0 ? void 0 : url.trim()) || undefined;
4743
4793
  }
4794
+ function isOptOut(settings) {
4795
+ return (settings.consent_model === 'opt_out' ||
4796
+ (settings.consent_model === undefined &&
4797
+ settings.consent_required === false));
4798
+ }
4744
4799
  function readReplayConsent(settings) {
4745
4800
  try {
4746
4801
  if (navigator
@@ -4749,10 +4804,13 @@ function readReplayConsent(settings) {
4749
4804
  }
4750
4805
  const shopify = window.Shopify;
4751
4806
  if (shopify === undefined) {
4807
+ if (readUsPrivacy() === 'denied')
4808
+ return { state: 'denied', reason: 'consent_denied' };
4752
4809
  const readers = [
4753
4810
  [readClientCommand, 'client'],
4754
4811
  [readOneTrust, 'onetrust'],
4755
4812
  [readCookiebot, 'cookiebot'],
4813
+ [readTrueVault, 'truevault'],
4756
4814
  [readConsentMode, 'consent_mode'],
4757
4815
  ];
4758
4816
  for (let i = 0; i < readers.length; i++) {
@@ -4763,13 +4821,13 @@ function readReplayConsent(settings) {
4763
4821
  if (signal === 'denied')
4764
4822
  return { state: 'denied', reason: 'consent_denied' };
4765
4823
  if (signal === 'pending') {
4766
- if (settings.consent_required === false)
4824
+ if (isOptOut(settings))
4767
4825
  continue;
4768
4826
  return { state: 'pending', detected: true };
4769
4827
  }
4770
4828
  }
4771
- if (settings.consent_required === false)
4772
- return { state: 'allowed', source: 'not_required' };
4829
+ if (isOptOut(settings))
4830
+ return { state: 'allowed', source: 'opt_out' };
4773
4831
  return { state: 'pending', detected: isWaitingForCookies() };
4774
4832
  }
4775
4833
  const customerPrivacy = shopify.customerPrivacy;
@@ -81,6 +81,7 @@ interface SessionReplaySettings {
81
81
  block_selector: string;
82
82
  url_deny_patterns: string[];
83
83
  url_allow_patterns?: string[];
84
+ consent_model?: 'opt_in' | 'opt_out';
84
85
  consent_required?: boolean;
85
86
  max_session_minutes: number;
86
87
  max_session_bytes: number;
@@ -101,6 +101,7 @@ interface SessionReplaySettings {
101
101
  block_selector: string;
102
102
  url_deny_patterns: string[];
103
103
  url_allow_patterns?: string[];
104
+ consent_model?: 'opt_in' | 'opt_out';
104
105
  consent_required?: boolean;
105
106
  max_session_minutes: number;
106
107
  max_session_bytes: number;
@@ -81,6 +81,7 @@ interface SessionReplaySettings {
81
81
  block_selector: string;
82
82
  url_deny_patterns: string[];
83
83
  url_allow_patterns?: string[];
84
+ consent_model?: 'opt_in' | 'opt_out';
84
85
  consent_required?: boolean;
85
86
  max_session_minutes: number;
86
87
  max_session_bytes: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coframe/sdk",
3
- "version": "1.1.48",
3
+ "version": "1.1.50",
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",