[_document.tsx][m]: configure nextjs root file (_document.tsx), inorder to include gtag.

This commit is contained in:
steveoni 2020-11-30 13:26:33 +01:00
parent bc9d357621
commit f2c9a1058c

View File

@ -0,0 +1,34 @@
import Document, { Html, Head, Main, NextScript } from 'next/document';
const GA_TRACKING_ID = 'G-NX72GYFHFS';
export default class CustomDocument extends Document {
render() {
return (
<Html>
<Head>
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-NX72GYFHFS"
/>
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_TRACKING_ID}',{
page_path: window.location.pathname,
});
`,
}}
/>
</Head>
<body>
<Main />
</body>
<NextScript />
</Html>
);
}
}