Use Next.js’s built-in <Script> component with strategy="afterInteractive" so the widget loads after the page becomes interactive without blocking rendering. Add it to your root layout so it appears on every page.
1

Open app/layout.tsx

Open app/layout.tsx (or app/layout.jsx) — the root layout that wraps every page in your app.
2

Import Script and add the widget

app/layout.tsx
Replace kb_xxx and bq_pk_... with your actual values.
3

Run the dev server

Run npm run dev. Open the browser DevTools → Sources and confirm beforequery-widget.js is loaded, then verify the launcher appears on the page.
Use strategy="afterInteractive" (not "beforeInteractive" or "lazyOnload"). afterInteractive is the closest equivalent to the plain-HTML async attribute — it hydrates the script client-side after the page is interactive without blocking the server render.
Get your keys — your knowledge base ID and public client key (bq_pk_...) are in the BeforeQuery dashboard under Knowledge Base → Integration. Add your Next.js app’s domain (e.g. docs.yourproduct.com) to the key’s origin allowlist.
For all widget configuration options, see Widget reference.