@blotoutio/providers-google-analytics-4-sdk
Advanced tools
Comparing version 0.6.5 to 0.6.6
33
index.js
var ProvidersGoogleAnalytics4Sdk = (function () { | ||
'use strict'; | ||
const initGA4 = (ID) => { | ||
window.dataLayer = window.dataLayer || []; | ||
window.gtag = function gtag() { | ||
// eslint-disable-next-line prefer-rest-params | ||
window.dataLayer.push(arguments); | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
window.gtag('js', new Date()); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
window.gtag('config', ID); | ||
const element = document.createElement('script'); | ||
element.async = !0; | ||
element.src = `https://www.googletagmanager.com/gtag/js?id=${ID}`; | ||
const script = document.getElementsByTagName('script')[0]; | ||
if (script && script.parentNode) { | ||
script.parentNode.insertBefore(element, script); | ||
} | ||
}; | ||
const init = ({ manifest, userId }) => { | ||
if (!manifest.variables || !window || !window.gtag) { | ||
if (!manifest.variables || !window) { | ||
return; | ||
} | ||
window.gtag('config', manifest.variables['googleAnalytics4MeasurementId'], { | ||
user_id: userId, | ||
}); | ||
if (!window.gtag && manifest.variables['enableBrowser'] === '1') { | ||
initGA4(manifest.variables['measurementId']); | ||
} | ||
if (window.gtag) { | ||
window.gtag('config', manifest.variables['measurementId'], { | ||
user_id: userId, | ||
}); | ||
} | ||
}; | ||
@@ -12,0 +37,0 @@ |
{ | ||
"name": "@blotoutio/providers-google-analytics-4-sdk", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"description": "Google Analytics 4 Browser SDK for EdgeTag", | ||
@@ -5,0 +5,0 @@ "author": "Blotout", |
2266
52