Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/window.gtag is not defined for Next.js-hydration event(#40410) #40645

Merged
merged 7 commits into from Sep 23, 2022
30 changes: 30 additions & 0 deletions examples/with-google-analytics/pages/_document.js
@@ -0,0 +1,30 @@
import { Html, Head, Main, NextScript } from 'next/document'
import * as gtag from '../lib/gtag'
dave-hay marked this conversation as resolved.
Show resolved Hide resolved

export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />

{/* Global Site Tag (gtag.js) - Google Analytics */}
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
/>
dave-hay marked this conversation as resolved.
Show resolved Hide resolved
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

`,
}}
/>
</body>
</Html>
)
}