cloakingx@guard:~
man cloaking-x.integrations.nextjsIntegration Guide

Next.js

Added once to your app's root layout — applies to every route automatically, including a fallback page built as another route in the same app.

1. Open app/layout.tsx (your root layout)

Note
This file wraps every page in your app. Changes here apply everywhere automatically.

2. Add the 3 tags as the first items inside <head>

tsx
// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        {/* ✅ Must be first inside <head> */}
        <style
          id="YOUR_PRE_HIDE_ID"
          dangerouslySetInnerHTML={{
            __html: 'html,body{visibility:hidden!important;background:#fff!important}',
          }}
        />
        <script
          dangerouslySetInnerHTML={{
            __html: "setTimeout(function(){var e=document.getElementById('YOUR_PRE_HIDE_ID');if(e&&e.parentNode)e.parentNode.removeChild(e);},10000);",
          }}
        />
        <script src="https://cloakingx.com/a/YOUR_ASSET_TOKEN.js" data-s="YOUR_STREAM_ID" />
      </head>
      <body>{children}</body>
    </html>
  );
}

YOUR_STREAM_ID, YOUR_ASSET_TOKEN, and YOUR_PRE_HIDE_ID are placeholders — get the real, pre-filled snippet from your dashboard's Integration page.

Note
Next.js's official recommendation for third-party scripts is next/script with strategy="beforeInteractive". Either approach works here — the raw <script> tag above is used because it guarantees p.js loads (and self-initializes from its data-s attribute) before anything else on the page renders.

3. Deploy — done

Note
The style and scripts are server-rendered, so there is zero flash on any page in your app. Real users redirect instantly; bots see your layout content.