Guide

Add a popup to Next.js

Free to use · no credit card · no pageview cap

This guide names the exact files for the App Router and the Pages Router. It was not tested on a live Next.js deployment; the placement and the warnings come from the Next.js documentation and the widget's own install requirements. Test on a preview deployment before shipping.

The short version

  1. Save the popup in the studio and copy its two-line snippet.
  2. App Router: put the div and a next/script in app/layout.tsx, inside <body>.
  3. Pages Router: put them in pages/_app.tsx, or use a plain async script tag in pages/_document.tsx.
  4. Deploy a preview, load a page, and confirm the popup appears and a test response reaches the inbox.

App Router: app/layout.tsx

Render the widget div after {children} and load the script with next/script and strategy="afterInteractive". That strategy loads the widget after hydration, so it does not compete with the page's own JavaScript.

import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <div data-popuploom="YOUR_WIDGET_ID" />
        <Script
          src="https://popuploom.com/embed/1.2.0/popuploom.js"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}

Keep YOUR_WIDGET_ID exactly as the studio gives it. The div is empty and static, so it does not cause a hydration mismatch.

Pages Router: pages/_app.tsx

If you use the Pages Router, load the script once from _app.tsx and render the div in the same tree:

import Script from "next/script";
import type { AppProps } from "next/app";

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <Component {...pageProps} />
      <div data-popuploom="YOUR_WIDGET_ID" />
      <Script
        src="https://popuploom.com/embed/1.2.0/popuploom.js"
        strategy="afterInteractive"
      />
    </>
  );
}

Do not use next/script inside _document.tsx. The Next.js documentation says it is not supported there. If you need the tag in the document, add a plain async script instead:

<body>
  <Main />
  <NextScript />
  <div data-popuploom="YOUR_WIDGET_ID" />
  <script async src="https://popuploom.com/embed/1.2.0/popuploom.js" />
</body>

Client-side navigation

Next.js changes routes without reloading the document. The widget loads once, with the first document. That is fine for a popup triggered by a timer, a click or a scroll, because those events keep working. It matters for page targeting: a route reached by client-side navigation may not re-evaluate a URL rule the way a full load does.

Test the exact case you care about: open the site, navigate to the target route through the UI, and see whether the popup fires. If it does not, load that route directly or attach the popup to a click instead. Do not assume a route change behaved like a page load.

If your site sets a Content Security Policy, the widget needs https://popuploom.com in script-src and connect-src. If the overlay renders but looks unstyled, the policy may be blocking the widget's style injection. Check the browser console on the preview deployment, not just locally.

Test checklist

  • The popup appears on a fresh preview deployment, in a private window.
  • A test submission lands in the lead inbox.
  • The page's own JavaScript still works; no console errors from the widget.
  • Direct load and client-side navigation behave as you expect.
  • CSP, if enabled, allows the script and the configuration request.
  • Removing the two lines removes the popup on the next deploy.

Removal

Delete the div and the Script component, then redeploy. The saved popup stays in the studio; nothing is deleted from your account when you remove the embed.

Common questions

Where does the PopupLoom script go in the Next.js App Router?

In app/layout.tsx, render the widget div and the next/script component inside the body, after {children}. Use strategy="afterInteractive" so the widget loads after hydration rather than blocking the page.

Should I use next/script in pages/_document.tsx?

No. The Next.js documentation says next/script should not be used in _document. For the Pages Router, either load the script from _app.tsx with next/script, or add a plain async script tag in _document.tsx.

Does the popup appear after a client-side route change?

Test it on your router. The document does not reload on client-side navigation, so a page-level script may not re-evaluate route targeting. If it does not appear on a navigated route, load that route directly or trigger the popup from an event instead of assuming it fired.

Will the widget slow down the Next.js build or page?

The snippet is one small external script loaded after hydration. It does not run at build time and adds no dependency to your bundle. Configuration is fetched from PopupLoom at runtime.

Official references

Written by Shailu016, founder of PopupLoom. Checked against the Next.js documentation on 17 November 2026; not tested on a live deployment. No ranking, traffic or conversion claim is made. Related: React, Astro, static HTML, the general install guide and exit intent.