Add a feedback widget to Next.js
Last updated:
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:
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:
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
{
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. See in-app bug reports for SaaS, the bug report template, or the WordPress guide.
Frequently asked questions
- 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.