From 9ff2510915ba0c283e053890ec64de3e89f21967 Mon Sep 17 00:00:00 2001 From: Bartosz Kaszubowski Date: Mon, 8 Jan 2024 10:22:43 +0100 Subject: [PATCH] switch from UA to GA4 project (#1103) --- components/GoogleAnalytics.tsx | 15 ++++++++------- pages/_document.tsx | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/GoogleAnalytics.tsx b/components/GoogleAnalytics.tsx index c2333d2d..35411cd2 100644 --- a/components/GoogleAnalytics.tsx +++ b/components/GoogleAnalytics.tsx @@ -1,16 +1,17 @@ const getAnalyticsScript = (id: string) => { return ` -(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','//www.google-analytics.com/analytics.js','ga'); -ga('create', '${id}', {cookieDomain: 'auto', siteSpeedSampleRate: 100}); -ga('send', 'pageview'); +window.dataLayer = window.dataLayer || []; +function gtag(){dataLayer.push(arguments);} +gtag('js', new Date()); +gtag('config', '${id}'); `.replace(/\n/g, ''); }; const GoogleAnalytics = ({ id }) => ( -