# DemoPage docs: 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.

Your portal is at https://app.demopage.io/portal.

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

## More guides

- [Set up DemoPage](https://demopage.io/docs.md): From sign-up to a live demo on your site: pages, embed, leads, and signed-in screens.
- [Add the demo button to your site](https://demopage.io/docs/add-to-your-site.md): Paste one script tag on Next.js, React, Webflow, WordPress, or HubSpot, or use your own button.
- [Choose pages, and who gets a live demo](https://demopage.io/docs/pages-and-access.md): Keep the pages the demo may show, and decide whose live demo waits for you.
- [Show your product, signed in](https://demopage.io/docs/demo-login.md): Give the guide a sandbox login so it can learn the product, then pick the pages a customer may see.
- [Get lead alerts in Slack](https://demopage.io/docs/slack-alerts.md): Post who watched your demo, what they asked, and a recap link into a Slack channel.
- [Connect your CRM](https://demopage.io/docs/crm.md): Every demo lead in your CRM, and a demo for each new CRM lead.
- [Read your demo results](https://demopage.io/docs/results.md): What each number means, the questions buyers asked, and your latest leads.
- [Build your demo from your code](https://demopage.io/docs/ai-tools.md): Connect Cursor, Claude Code, Codex, or ChatGPT to map your screens from code.
- [DemoPage MCP server](https://demopage.io/docs/mcp.md): Connect Claude Code, Cursor, Codex, VS Code, or ChatGPT to DemoPage's OAuth 2.1 and zero-auth public MCP servers.
