Docs · Guide

Embed DemoPage in Next.js and React.

Load DemoPage's script once in your Next.js root layout with next/script and data-button set to none, then add data-demopage-open to your Book a demo button. Visitors see your real product in an isolated read-only browser and get Q&A cited strictly from your approved docs, with payments and writes blocked.

Next.js App Router (app/layout.tsx)

Add next/script once in your root layout so the embed works on every route. Pass data-button="none" when you want your own Book a demo CTA to open the modal instead of showing a floating launcher.

import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://app.demopage.io/embed.js"
          data-demo="your-link"
          data-button="none"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}

Replace your-link with your slug from Demo settings → Embed on your site. Remove data-button="none" if you also want the floating corner launcher.

Or install @demopage/embed (npm package & CLI)

If you prefer typed Next.js / React components or a zero-install CLI that detects App Router, Pages Router, or Vite and prints your snippet + CSP headers, use the official zero-dependency @demopage/embed package on npm.

  • Cloneable Next.js App Router reference starter (with CSP headers and .cursor/mcp.json pre-wired): https://github.com/gaufire/demopage-nextjs-starter.
  • Run npx @demopage/embed mcp --write-cursor to write DemoPage's OAuth and zero-auth public MCP servers straight into .cursor/mcp.json.
# Zero-install CLI (detects Next.js App Router, Pages Router, or React)
npx @demopage/embed init --demo your-link

# Or install typed Next.js / React components
npm install @demopage/embed

// app/layout.tsx
import { DemoPageNextScript } from "@demopage/embed/next";
// Any Server or Client Component:
import { DemoPageButton } from "@demopage/embed/next";

Attach to your Book a demo button

Add data-demopage-open to any anchor or button in a Server Component or Client Component. Using an anchor with href to your hosted demo link also gives a working fallback if JavaScript is blocked.

  • No 'use client' directive is needed: embed.js listens via delegated click handling on document.
  • Optional attributes on the script tag: data-label changes the floating button copy, data-color sets its accent hex, data-position="left" moves it left, and data-language="es" opens the demo in a specific language.
  • To let visitors also open your demo from a Vercel preview or staging domain, add that host under Demo settings → Embed on your site → Shows on (up to 10 hosts).
<a
  href="https://app.demopage.io/d/your-link"
  data-demopage-open
  className="rounded-lg bg-black px-5 py-3 text-white"
>
  Book a demo
</a>

Next.js Pages Router, React, and Vite

In Next.js Pages Router, put the same next/script tag in pages/_app.tsx. In a Vite or Create React App project, place the static script tag directly in index.html before the closing body tag so it does not re-mount on client route transitions.

// pages/_app.tsx
import type { AppProps } from "next/app";
import Script from "next/script";

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <Component {...pageProps} />
      <Script
        src="https://app.demopage.io/embed.js"
        data-demo="your-link"
        data-button="none"
        strategy="afterInteractive"
      />
    </>
  );
}

Content Security Policy (CSP) headers

If your Next.js app sends a strict Content-Security-Policy header in next.config.ts or middleware.ts, allow DemoPage's script and iframe origin.

  • DemoPage runs the live product browser on its own isolated workers, not inside your visitor's browser, so your SaaS app's cookies and auth tokens are never exposed to the marketing site.
  • Other websites cannot frame your demo unless you explicitly add their host under Shows on.
script-src 'self' https://app.demopage.io;
frame-src 'self' https://app.demopage.io;

Verify before shipping

  1. 1Open your staging or production page in a private browser window and click your Book a demo button.
  2. 2Confirm the DemoPage overlay opens over your page without navigating away and shows your approved product pages.
  3. 3Check the Results tab in your portal to verify Opened the demo increments.

More guides