UNPKG

gtag-ga

Version:

Google Analytics 4 (gtag.js) for NodeJS ES Module. Simple installation to send page views or event tracking.

1 lines 490 B
export function gtag(...t){window.dataLayer.push(t)}export function initializeGtag(t,e){if("undefined"==typeof window)throw new Error("'window' object not found, make sure you're using initialize in the right place.");if(void 0!==window.gtag)return;const n=document.createElement("script");n.async=!0,n.src=`https://www.googletagmanager.com/gtag/js?id=${t}`,document.head.insertBefore(n,document.head.firstChild),window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config",t,e)}