diff --git a/src/telemetry/ga.js b/src/telemetry/ga.js index 51829416b..f4b7daf62 100644 --- a/src/telemetry/ga.js +++ b/src/telemetry/ga.js @@ -1,8 +1,12 @@ export const googleAnalytics = (gaID) => { - (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) - })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); + const script = document.createElement('script'); + script.src = `https://www.googletagmanager.com/gtag/js?id=${gaID}`; + script.async = true; + document.head.appendChild(script); - ga('create', gaID, 'auto'); -}; + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + + gtag('config', gaID); +}; \ No newline at end of file diff --git a/src/telemetry/index.js b/src/telemetry/index.js index 3e4707630..02f652a26 100644 --- a/src/telemetry/index.js +++ b/src/telemetry/index.js @@ -67,11 +67,11 @@ export function initializeTelemetry() { * @param {string} path The current page path. */ export function submitPageViewTelemetry(path) { - // Send telemetry to Google Analytics. - if (window.ga) { - // `ga` will not be set if not using google analytics - ga("set", "page", path); - ga("send", "pageview"); + // Send page view event to GA4. + if (window.gtag) { + window.gtag("event", "page_view", { + page_path: path, + }); } // Send telemetry to Glean.