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 Next + Cloudfare integration snippet #43

Open
kellenwiltshire opened this issue Mar 28, 2023 · 0 comments
Open

Fix Next + Cloudfare integration snippet #43

kellenwiltshire opened this issue Mar 28, 2023 · 0 comments

Comments

@kellenwiltshire
Copy link
Contributor

kellenwiltshire commented Mar 28, 2023

import Document, { Html, Main, NextScript } from "next/document";
const isProd = process.env.NODE_ENV === "production";

export default class MyDocument extends Document {
  render(): JSX.Element {
    return (
      <Html>
        <body>
          <Main />
          <NextScript />
          {/* Cloudflare Web Analytics */}
          {isProd && (
            <>
              <script
                defer
                src="https://static.cloudflareinsights.com/beacon.min.js"
                data-cf-beacon='{"token": "your_token", "spa": true}'
              />
            </>
          )}
        </body>
      </Html>
    );
  }
}

This should include <Head /> from 'next/document` in order to not break styling.

import Document, { Html, Main, Head, NextScript } from "next/document";
const isProd = process.env.NODE_ENV === "production";

export default class MyDocument extends Document {
  render(): JSX.Element {
    return (
      <Html>
        <Head />
        <body>
          <Main />
          <NextScript />
          {/* Cloudflare Web Analytics */}
          {isProd && (
            <>
              <script
                defer
                src="https://static.cloudflareinsights.com/beacon.min.js"
                data-cf-beacon='{"token": "your_token", "spa": true}'
              />
            </>
          )}
        </body>
      </Html>
    );
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant