Unverified Commit bebf3725 authored by David Hay's avatar David Hay Committed by GitHub

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

Next.js-hydration now triggered after gtag is initialized. Fixed by adding _document.js and appropriate script elements.
---
## Documentation / Examples

- [X] Related issues linked using fixes #40410
- [X] Make sure the linting passes by running `pnpm lint`
- [X] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

Next.js-hydration now triggered after gtag is initialized.
parent f19241bf
import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
{/* Global Site Tag (gtag.js) - Google Analytics */}
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
`,
}}
/>
</body>
</Html>
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment