@blotoutio/providers-google-analytics-4-sdk 1.20.1 → 1.21.1

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.
Files changed (4) hide show
  1. package/index.cjs.js +25 -15
  2. package/index.js +25 -15
  3. package/index.mjs +25 -15
  4. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -9,17 +9,28 @@ const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
9
9
  * This function validates user consent for a given provider type, not based on tagName.
10
10
  */
11
11
  const hasUserConsentForProvider = (consent, provider) => {
12
- if (!isRecord(consent)) {
13
- return false;
14
- }
15
- let allowed = isBool(consent.all) ? consent.all : false;
16
- if (provider in consent) {
17
- const providerSpecific = consent[provider];
18
- if (isBool(providerSpecific)) {
19
- allowed = providerSpecific;
12
+ var _a, _b;
13
+ let allowed = false;
14
+ if (isRecord(consent === null || consent === void 0 ? void 0 : consent.consent)) {
15
+ allowed = isBool(consent.consent.all) ? consent.consent.all : false;
16
+ if (provider in consent) {
17
+ const providerSpecific = consent.consent[provider];
18
+ if (isBool(providerSpecific)) {
19
+ allowed = providerSpecific;
20
+ }
21
+ else if (isRecord(providerSpecific)) {
22
+ return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
23
+ }
20
24
  }
21
- else if (isRecord(providerSpecific)) {
22
- return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
25
+ }
26
+ if (isRecord(consent.categories) &&
27
+ isRecord((_a = consent.consentSettings) === null || _a === void 0 ? void 0 : _a.channels)) {
28
+ allowed = isBool(consent.categories.all) ? consent.categories.all : false;
29
+ const category = (_b = Object.entries(consent.consentSettings.channels).find(([, value]) => {
30
+ return value.includes(provider);
31
+ })) === null || _b === void 0 ? void 0 : _b[0];
32
+ if (category && consent.categories[category]) {
33
+ allowed = true;
23
34
  }
24
35
  }
25
36
  return allowed;
@@ -431,8 +442,7 @@ const getGoogleConsentFromCategories = (categories) => {
431
442
  analytics_storage: analyticsConsent ? 'granted' : 'denied',
432
443
  };
433
444
  };
434
- // TODO: once categories becomes a stable field, we need to remove this and start using categories data for google consent mode.
435
- const getGoogleConsentFromChannels = (consent) => {
445
+ const getGoogleConsent = (consent) => {
436
446
  const ga4Consent = hasUserConsentForProvider(consent, 'googleAnalytics4');
437
447
  return {
438
448
  analytics_storage: ga4Consent ? 'granted' : 'denied',
@@ -456,7 +466,7 @@ const initGA4 = (ID, advancedConsentMode, consentData, executionContext) => {
456
466
  }
457
467
  const data = advancedConsentMode === '1'
458
468
  ? getGoogleConsentFromCategories(consentData.categories)
459
- : getGoogleConsentFromChannels(consentData.consent);
469
+ : getGoogleConsent(consentData);
460
470
  if (isConsentInitialised) {
461
471
  window.gtag('consent', 'update', data);
462
472
  }
@@ -762,7 +772,7 @@ const tag = ({ data, eventName, manifestVariables, eventId }) => {
762
772
  }
763
773
  return {
764
774
  loaded: isLoaded,
765
- sdkVersion: "1.20.1" ,
775
+ sdkVersion: "1.21.1" ,
766
776
  };
767
777
  };
768
778
 
@@ -773,7 +783,7 @@ const consent = ({ consentData, variables }) => {
773
783
  const isAdvancedConsentModeEnabled = variables.some((variable) => { var _a; return ((_a = variable.variableSet) === null || _a === void 0 ? void 0 : _a['advancedConsentMode']) === '1'; });
774
784
  const data = isAdvancedConsentModeEnabled
775
785
  ? getGoogleConsentFromCategories(consentData.categories)
776
- : getGoogleConsentFromChannels(consentData.consent);
786
+ : getGoogleConsent(consentData);
777
787
  window.gtag('consent', 'update', {
778
788
  ...data,
779
789
  functional_storage: 'granted',
package/index.js CHANGED
@@ -10,17 +10,28 @@ var ProvidersGoogleAnalytics4Sdk = (function () {
10
10
  * This function validates user consent for a given provider type, not based on tagName.
11
11
  */
12
12
  const hasUserConsentForProvider = (consent, provider) => {
13
- if (!isRecord(consent)) {
14
- return false;
15
- }
16
- let allowed = isBool(consent.all) ? consent.all : false;
17
- if (provider in consent) {
18
- const providerSpecific = consent[provider];
19
- if (isBool(providerSpecific)) {
20
- allowed = providerSpecific;
13
+ var _a, _b;
14
+ let allowed = false;
15
+ if (isRecord(consent === null || consent === void 0 ? void 0 : consent.consent)) {
16
+ allowed = isBool(consent.consent.all) ? consent.consent.all : false;
17
+ if (provider in consent) {
18
+ const providerSpecific = consent.consent[provider];
19
+ if (isBool(providerSpecific)) {
20
+ allowed = providerSpecific;
21
+ }
22
+ else if (isRecord(providerSpecific)) {
23
+ return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
24
+ }
21
25
  }
22
- else if (isRecord(providerSpecific)) {
23
- return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
26
+ }
27
+ if (isRecord(consent.categories) &&
28
+ isRecord((_a = consent.consentSettings) === null || _a === void 0 ? void 0 : _a.channels)) {
29
+ allowed = isBool(consent.categories.all) ? consent.categories.all : false;
30
+ const category = (_b = Object.entries(consent.consentSettings.channels).find(([, value]) => {
31
+ return value.includes(provider);
32
+ })) === null || _b === void 0 ? void 0 : _b[0];
33
+ if (category && consent.categories[category]) {
34
+ allowed = true;
24
35
  }
25
36
  }
26
37
  return allowed;
@@ -432,8 +443,7 @@ var ProvidersGoogleAnalytics4Sdk = (function () {
432
443
  analytics_storage: analyticsConsent ? 'granted' : 'denied',
433
444
  };
434
445
  };
435
- // TODO: once categories becomes a stable field, we need to remove this and start using categories data for google consent mode.
436
- const getGoogleConsentFromChannels = (consent) => {
446
+ const getGoogleConsent = (consent) => {
437
447
  const ga4Consent = hasUserConsentForProvider(consent, 'googleAnalytics4');
438
448
  return {
439
449
  analytics_storage: ga4Consent ? 'granted' : 'denied',
@@ -457,7 +467,7 @@ var ProvidersGoogleAnalytics4Sdk = (function () {
457
467
  }
458
468
  const data = advancedConsentMode === '1'
459
469
  ? getGoogleConsentFromCategories(consentData.categories)
460
- : getGoogleConsentFromChannels(consentData.consent);
470
+ : getGoogleConsent(consentData);
461
471
  if (isConsentInitialised) {
462
472
  window.gtag('consent', 'update', data);
463
473
  }
@@ -763,7 +773,7 @@ var ProvidersGoogleAnalytics4Sdk = (function () {
763
773
  }
764
774
  return {
765
775
  loaded: isLoaded,
766
- sdkVersion: "1.20.1" ,
776
+ sdkVersion: "1.21.1" ,
767
777
  };
768
778
  };
769
779
 
@@ -774,7 +784,7 @@ var ProvidersGoogleAnalytics4Sdk = (function () {
774
784
  const isAdvancedConsentModeEnabled = variables.some((variable) => { var _a; return ((_a = variable.variableSet) === null || _a === void 0 ? void 0 : _a['advancedConsentMode']) === '1'; });
775
785
  const data = isAdvancedConsentModeEnabled
776
786
  ? getGoogleConsentFromCategories(consentData.categories)
777
- : getGoogleConsentFromChannels(consentData.consent);
787
+ : getGoogleConsent(consentData);
778
788
  window.gtag('consent', 'update', {
779
789
  ...data,
780
790
  functional_storage: 'granted',
package/index.mjs CHANGED
@@ -7,17 +7,28 @@ const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
7
7
  * This function validates user consent for a given provider type, not based on tagName.
8
8
  */
9
9
  const hasUserConsentForProvider = (consent, provider) => {
10
- if (!isRecord(consent)) {
11
- return false;
12
- }
13
- let allowed = isBool(consent.all) ? consent.all : false;
14
- if (provider in consent) {
15
- const providerSpecific = consent[provider];
16
- if (isBool(providerSpecific)) {
17
- allowed = providerSpecific;
10
+ var _a, _b;
11
+ let allowed = false;
12
+ if (isRecord(consent === null || consent === void 0 ? void 0 : consent.consent)) {
13
+ allowed = isBool(consent.consent.all) ? consent.consent.all : false;
14
+ if (provider in consent) {
15
+ const providerSpecific = consent.consent[provider];
16
+ if (isBool(providerSpecific)) {
17
+ allowed = providerSpecific;
18
+ }
19
+ else if (isRecord(providerSpecific)) {
20
+ return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
21
+ }
18
22
  }
19
- else if (isRecord(providerSpecific)) {
20
- return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
23
+ }
24
+ if (isRecord(consent.categories) &&
25
+ isRecord((_a = consent.consentSettings) === null || _a === void 0 ? void 0 : _a.channels)) {
26
+ allowed = isBool(consent.categories.all) ? consent.categories.all : false;
27
+ const category = (_b = Object.entries(consent.consentSettings.channels).find(([, value]) => {
28
+ return value.includes(provider);
29
+ })) === null || _b === void 0 ? void 0 : _b[0];
30
+ if (category && consent.categories[category]) {
31
+ allowed = true;
21
32
  }
22
33
  }
23
34
  return allowed;
@@ -429,8 +440,7 @@ const getGoogleConsentFromCategories = (categories) => {
429
440
  analytics_storage: analyticsConsent ? 'granted' : 'denied',
430
441
  };
431
442
  };
432
- // TODO: once categories becomes a stable field, we need to remove this and start using categories data for google consent mode.
433
- const getGoogleConsentFromChannels = (consent) => {
443
+ const getGoogleConsent = (consent) => {
434
444
  const ga4Consent = hasUserConsentForProvider(consent, 'googleAnalytics4');
435
445
  return {
436
446
  analytics_storage: ga4Consent ? 'granted' : 'denied',
@@ -454,7 +464,7 @@ const initGA4 = (ID, advancedConsentMode, consentData, executionContext) => {
454
464
  }
455
465
  const data = advancedConsentMode === '1'
456
466
  ? getGoogleConsentFromCategories(consentData.categories)
457
- : getGoogleConsentFromChannels(consentData.consent);
467
+ : getGoogleConsent(consentData);
458
468
  if (isConsentInitialised) {
459
469
  window.gtag('consent', 'update', data);
460
470
  }
@@ -760,7 +770,7 @@ const tag = ({ data, eventName, manifestVariables, eventId }) => {
760
770
  }
761
771
  return {
762
772
  loaded: isLoaded,
763
- sdkVersion: "1.20.1" ,
773
+ sdkVersion: "1.21.1" ,
764
774
  };
765
775
  };
766
776
 
@@ -771,7 +781,7 @@ const consent = ({ consentData, variables }) => {
771
781
  const isAdvancedConsentModeEnabled = variables.some((variable) => { var _a; return ((_a = variable.variableSet) === null || _a === void 0 ? void 0 : _a['advancedConsentMode']) === '1'; });
772
782
  const data = isAdvancedConsentModeEnabled
773
783
  ? getGoogleConsentFromCategories(consentData.categories)
774
- : getGoogleConsentFromChannels(consentData.consent);
784
+ : getGoogleConsent(consentData);
775
785
  window.gtag('consent', 'update', {
776
786
  ...data,
777
787
  functional_storage: 'granted',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-google-analytics-4-sdk",
3
- "version": "1.20.1",
3
+ "version": "1.21.1",
4
4
  "description": "Google Analytics 4 Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",