Skip to content

Commit

Permalink
switch from UA to GA4 project (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simek authored Jan 8, 2024
1 parent cfac225 commit 9ff2510
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions components/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -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 }) => (
<script dangerouslySetInnerHTML={{ __html: getAnalyticsScript(id) }} />
<>
<script async src={`https://www.googletagmanager.com/gtag/js?id=${id}`} />
<script dangerouslySetInnerHTML={{ __html: getAnalyticsScript(id) }} />
</>
);

export default GoogleAnalytics;
2 changes: 1 addition & 1 deletion pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DirectoryWebsite extends Document {
render = () => (
<Html lang="en">
<Head>
<GoogleAnalytics id="UA-107832480-1" />
<GoogleAnalytics id="G-T0F1XSEWES" />
</Head>
<body>
<Main />
Expand Down

0 comments on commit 9ff2510

Please sign in to comment.