# Add a feedback widget to Next.js

> Add a feedback and bug report widget to a Next.js app with next/script, in the App Router or the Pages Router. Copy-paste code included.

Source: https://commentpin.com/guides/add-feedback-widget-nextjs
Last updated: 2026-12-02

## How do I add a feedback widget to Next.js?

To add a feedback widget to Next.js, put a `next/script` tag in your root layout with the widget URL and your project key. It takes one file change.

## 1. Get your project key

Create a project in the dashboard, add your domains (for example `localhost:3000` and your production domain) to **Allowed domains**, and copy the project key.

## 2. App Router

Edit `app/layout.tsx`:

```tsx
import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://commentpin.com/widget.js"
          data-project="YOUR_PROJECT_KEY"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}
```

## 3. Pages Router

Edit `pages/_app.tsx`:

```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://commentpin.com/widget.js" data-project="YOUR_PROJECT_KEY" />
    </>
  );
}
```

## Only on staging

```tsx
{
  process.env.NEXT_PUBLIC_FEEDBACK === "true" && (
    <Script src="https://commentpin.com/widget.js" data-project="YOUR_PROJECT_KEY" />
  );
}
```

## Check it works

Open the site. A feedback button appears in the corner. Send a test report and find it in your inbox.

More detail in the [install docs](/docs/install-the-widget). See [in-app bug reports for SaaS](/use-cases/saas-bug-reports), the [bug report template](/guides/bug-report-template), or the [WordPress guide](/guides/add-feedback-widget-wordpress).

## FAQ

### Where do I add the widget in the App Router?

In app/layout.tsx, inside the body, using the Script component from next/script.

### Which loading strategy should I use?

afterInteractive, the default. The widget is not needed before the page is interactive.

### Does the widget work with client-side navigation?

Yes. It loads once and records the current URL when someone sends a report.

### Can I show the widget only on staging?

Yes. Render the Script only when an environment variable is set, for example when NEXT_PUBLIC_FEEDBACK is true.

### Why does the button not appear?

The domain is probably not in the project's allowed domains. The widget stays hidden on domains you have not allowed.
