@blotoutio/providers-google-analytics-4-sdk
Advanced tools
Comparing version 0.35.3 to 0.36.0
@@ -6,4 +6,12 @@ 'use strict'; | ||
const upsert = (map, key, update, createDefault) => { | ||
const currentValue = map.has(key) | ||
? map.get(key) | ||
: createDefault(); | ||
return map.set(key, update(currentValue)); | ||
}; | ||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
const initGA4 = (ID) => { | ||
const initGA4 = (ID, executionContext) => { | ||
var _a; | ||
window.dataLayer = window.dataLayer || []; | ||
@@ -14,2 +22,26 @@ window.gtag = function gtag() { | ||
}; | ||
let isConsentInitialised = false; | ||
for (const otherProvider of ['googleAdsClicks', 'googleAnalytics4']) { | ||
if ((_a = executionContext.get(otherProvider)) === null || _a === void 0 ? void 0 : _a.get('gtag')) { | ||
isConsentInitialised = true; | ||
break; | ||
} | ||
} | ||
if (isConsentInitialised) { | ||
window.gtag('consent', 'update', { | ||
analytics_storage: 'granted', | ||
}); | ||
} | ||
else { | ||
window.gtag('consent', 'default', { | ||
analytics_storage: 'granted', | ||
functional_storage: 'granted', | ||
personalization_storage: 'granted', | ||
security_storage: 'granted', | ||
ad_storage: 'denied', | ||
ad_user_data: 'denied', | ||
ad_personalization: 'denied', | ||
}); | ||
} | ||
upsert(executionContext, packageName, (providerMap) => providerMap.set('gtag', true), () => new Map()); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
@@ -26,3 +58,3 @@ // @ts-ignore | ||
}; | ||
const init = ({ manifest, userId }) => { | ||
const init = ({ manifest, userId, executionContext }) => { | ||
if (!window || | ||
@@ -33,4 +65,5 @@ !manifest.variables || | ||
} | ||
if (!window.gtag) { | ||
initGA4(manifest.variables['measurementId']); | ||
if (!window.google_tag_manager || | ||
!window.google_tag_manager[manifest.variables['tagId']]) { | ||
initGA4(manifest.variables['measurementId'], executionContext); | ||
} | ||
@@ -275,6 +308,18 @@ if (window.gtag) { | ||
loaded: isLoaded, | ||
sdkVersion: "0.35.3" , | ||
sdkVersion: "0.36.0" , | ||
}; | ||
}; | ||
const consent = ({ hasConsent }) => { | ||
if (!(window === null || window === void 0 ? void 0 : window.gtag)) { | ||
return; | ||
} | ||
window.gtag('consent', 'update', { | ||
analytics_storage: hasConsent ? 'granted' : 'denied', | ||
functional_storage: 'granted', | ||
personalization_storage: 'granted', | ||
security_storage: 'granted', | ||
}); | ||
}; | ||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
@@ -285,2 +330,3 @@ const data = { | ||
tag, | ||
consent, | ||
}; | ||
@@ -287,0 +333,0 @@ try { |
56
index.js
@@ -7,4 +7,12 @@ var ProvidersGoogleAnalytics4Sdk = (function () { | ||
const upsert = (map, key, update, createDefault) => { | ||
const currentValue = map.has(key) | ||
? map.get(key) | ||
: createDefault(); | ||
return map.set(key, update(currentValue)); | ||
}; | ||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
const initGA4 = (ID) => { | ||
const initGA4 = (ID, executionContext) => { | ||
var _a; | ||
window.dataLayer = window.dataLayer || []; | ||
@@ -15,2 +23,26 @@ window.gtag = function gtag() { | ||
}; | ||
let isConsentInitialised = false; | ||
for (const otherProvider of ['googleAdsClicks', 'googleAnalytics4']) { | ||
if ((_a = executionContext.get(otherProvider)) === null || _a === void 0 ? void 0 : _a.get('gtag')) { | ||
isConsentInitialised = true; | ||
break; | ||
} | ||
} | ||
if (isConsentInitialised) { | ||
window.gtag('consent', 'update', { | ||
analytics_storage: 'granted', | ||
}); | ||
} | ||
else { | ||
window.gtag('consent', 'default', { | ||
analytics_storage: 'granted', | ||
functional_storage: 'granted', | ||
personalization_storage: 'granted', | ||
security_storage: 'granted', | ||
ad_storage: 'denied', | ||
ad_user_data: 'denied', | ||
ad_personalization: 'denied', | ||
}); | ||
} | ||
upsert(executionContext, packageName, (providerMap) => providerMap.set('gtag', true), () => new Map()); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
@@ -27,3 +59,3 @@ // @ts-ignore | ||
}; | ||
const init = ({ manifest, userId }) => { | ||
const init = ({ manifest, userId, executionContext }) => { | ||
if (!window || | ||
@@ -34,4 +66,5 @@ !manifest.variables || | ||
} | ||
if (!window.gtag) { | ||
initGA4(manifest.variables['measurementId']); | ||
if (!window.google_tag_manager || | ||
!window.google_tag_manager[manifest.variables['tagId']]) { | ||
initGA4(manifest.variables['measurementId'], executionContext); | ||
} | ||
@@ -276,6 +309,18 @@ if (window.gtag) { | ||
loaded: isLoaded, | ||
sdkVersion: "0.35.3" , | ||
sdkVersion: "0.36.0" , | ||
}; | ||
}; | ||
const consent = ({ hasConsent }) => { | ||
if (!(window === null || window === void 0 ? void 0 : window.gtag)) { | ||
return; | ||
} | ||
window.gtag('consent', 'update', { | ||
analytics_storage: hasConsent ? 'granted' : 'denied', | ||
functional_storage: 'granted', | ||
personalization_storage: 'granted', | ||
security_storage: 'granted', | ||
}); | ||
}; | ||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
@@ -286,2 +331,3 @@ const data = { | ||
tag, | ||
consent, | ||
}; | ||
@@ -288,0 +334,0 @@ try { |
{ | ||
"name": "@blotoutio/providers-google-analytics-4-sdk", | ||
"version": "0.35.3", | ||
"version": "0.36.0", | ||
"description": "Google Analytics 4 Browser SDK for EdgeTag", | ||
@@ -5,0 +5,0 @@ "author": "Blotout", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32641
160
991