Skip to content

Commit 9ff2510

Browse files
authored
switch from UA to GA4 project (#1103)
1 parent cfac225 commit 9ff2510

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

components/GoogleAnalytics.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
const getAnalyticsScript = (id: string) => {
22
return `
3-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
4-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
5-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
6-
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
7-
ga('create', '${id}', {cookieDomain: 'auto', siteSpeedSampleRate: 100});
8-
ga('send', 'pageview');
3+
window.dataLayer = window.dataLayer || [];
4+
function gtag(){dataLayer.push(arguments);}
5+
gtag('js', new Date());
6+
gtag('config', '${id}');
97
`.replace(/\n/g, '');
108
};
119

1210
const GoogleAnalytics = ({ id }) => (
13-
<script dangerouslySetInnerHTML={{ __html: getAnalyticsScript(id) }} />
11+
<>
12+
<script async src={`https://www.googletagmanager.com/gtag/js?id=${id}`} />
13+
<script dangerouslySetInnerHTML={{ __html: getAnalyticsScript(id) }} />
14+
</>
1415
);
1516

1617
export default GoogleAnalytics;

pages/_document.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DirectoryWebsite extends Document {
1111
render = () => (
1212
<Html lang="en">
1313
<Head>
14-
<GoogleAnalytics id="UA-107832480-1" />
14+
<GoogleAnalytics id="G-T0F1XSEWES" />
1515
</Head>
1616
<body>
1717
<Main />

0 commit comments

Comments
 (0)