Skip to content

Commit

Permalink
test gtag on landing pages
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfay committed Feb 10, 2024
1 parent fad81a8 commit df272b6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Document, { Head, Html, Main, NextScript } from 'next/document';
import Script from 'next/script';

import { AppConfig } from '../utils/AppConfig';

const gtmId = 'G-NV5LK0T9C1';

// Need to create a custom _document because i18n support is not compatible with `next export`.
class MyDocument extends Document {
// eslint-disable-next-line class-methods-use-this
Expand All @@ -13,6 +16,16 @@ class MyDocument extends Document {
<Main />
<NextScript />
</body>
<Script src={`https://www.googletagmanager.com/gtag/js?id=${gtmId}`} />
<Script id="google-analytics" strategy="afterInteractive">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gtmId}');
`}
</Script>
</Html>
);
}
Expand Down

0 comments on commit df272b6

Please sign in to comment.