You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_document.tsx 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import NextDocument, { Html, Head, Main, NextScript, DocumentContext } from 'next/document'
  2. import { getCssText } from 'styles'
  3. import { GA_TRACKING_ID } from 'utils/gtag'
  4. class MyDocument extends NextDocument {
  5. static async getInitialProps(ctx: DocumentContext) {
  6. const initialProps = await NextDocument.getInitialProps(ctx)
  7. return {
  8. ...initialProps,
  9. styles: (
  10. <>
  11. {initialProps.styles}
  12. <style id="stitches" dangerouslySetInnerHTML={{ __html: getCssText() }} />
  13. </>
  14. ),
  15. }
  16. }
  17. render(): JSX.Element {
  18. return (
  19. <Html lang="en">
  20. <Head>
  21. <script async src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`} />
  22. <script
  23. dangerouslySetInnerHTML={{
  24. __html: `
  25. window.dataLayer = window.dataLayer || [];
  26. function gtag(){dataLayer.push(arguments);}
  27. gtag('js', new Date());
  28. gtag('config', '${GA_TRACKING_ID}', {
  29. page_path: window.location.pathname,
  30. });
  31. `,
  32. }}
  33. />
  34. </Head>
  35. <body>
  36. <Main />
  37. <NextScript />
  38. </body>
  39. </Html>
  40. )
  41. }
  42. }
  43. export default MyDocument