How to add a support widget to a Next.js app
Add a live chat and support widget to a Next.js App Router app, with next/script or an npm provider, signed-in users, your own Help button and dark mode.
The Notert teamMonday, November 30th, 202611 min read

On this page
Support tends to arrive late in a Next.js project. You build sign-in, billing, onboarding and the dashboard, then the first real users show up with real questions, and suddenly you need a way to answer them that lives inside the product.
This guide shows how to add a support widget to a Next.js app built on the App Router: a chat your customers open from any page, an inbox your team answers from, and the same widget telling you who is writing. We use Notert's widget as the example, and cover both ways to add it: two script tags in your root layout, or a typed npm package with a React provider. For a site built on WordPress, Shopify, Webflow or Framer, see how to add a support widget to your website.
What you'll have at the end
- A support widget on every route of your Next.js app, added once in
app/layout.tsx. - Signed-in users recognized by a token your server signs, so their conversations follow them across devices.
- Optionally, your own Help button in the sidebar or header, with an unread count, in place of the round button in the corner.
- The widget following your app's light and dark mode, and its language.
- A quick way to check it's live in production.
Script tags or the npm package?
Both put the same widget on the page. Pick the one that suits how your app is built.
| You want | Use |
|---|---|
| The fewest moving parts, no new dependency | Two scripts in app/layout.tsx |
| Typed calls and editor completion | @notert/widget |
| A React hook for your own Help button | @notert/widget/react and useNotert |
| Nothing of the widget in server-rendered HTML | NotertProvider in a client component |
You can start with the scripts and move to the package later: only the first init on a page counts, so the two never draw a second widget.
Before you start
- Open Settings (opens Notert in a new tab), then General (opens Notert in a new tab) under Conversations, and switch Conversations on under Status if it's off.
- Open Widget (opens Notert in a new tab) under Conversations, and press Open guide.
- Under Where it works, check your app's domain is listed. The widget only answers on your own websites, so add your app's address if it lives apart from your marketing site, such as
app.example.com. - Under Add it to your site, copy the snippet. It already carries your workspace's id.
Anyone on your team can open the guide and copy the snippet, so a developer who is a member can do this part alone. The widget also works on localhost once your workspace has a website, so you can try everything below in development first.
Option 1: add the widget with next/script
The snippet is two scripts. The small inline one sets up window.notert, which keeps any call you make before the widget has loaded and plays it back once it has. The second loads the widget itself as a module.
In Next.js, add both to the root layout with next/script. The small one goes beforeInteractive, so window.notert exists before any of your components run:
// app/layout.tsx
import Script from "next/script";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script id="notert" strategy="beforeInteractive">
{`window.$notert=window.$notert||[];window.notert=window.notert||new Proxy({},{get:(_,p)=>typeof p=="string"&&p!="then"&&/^[a-z]/i.test(p)?(...a)=>window.$notert.push([p,...a]):void 0});
window.notert.init("YOUR_WORKSPACE_ID",{widget:true,theme:"page"});`}
</Script>
<Script src="https://app.notert.io/embed/v1.js" type="module" strategy="afterInteractive" />
</body>
</html>
);
}That's the whole install. Because the App Router keeps one document for the visit and swaps pages in place, the widget stays on screen and keeps its conversation open as people move between routes. There's no route-change hook to wire up and nothing to re-initialize.
The two scripts work in either order, so it doesn't matter if Next.js moves the module ahead of the inline script. And since only the first init counts, a layout that renders again never draws a second widget.
Option 2: add it with the npm package and a provider
If you'd rather load the widget from your own code, with every call typed, install the package:
npm install @notert/widgetNotertProvider and useNotert use React state, so in the App Router they run in a client component. Put the provider in a file of its own marked "use client":
// app/notert-provider.tsx
"use client";
import { NotertProvider } from "@notert/widget/react";
export function Notert({ children }: { children: React.ReactNode }) {
return (
<NotertProvider workspaceId="YOUR_WORKSPACE_ID" theme="page">
{children}
</NotertProvider>
);
}Then wrap your root layout's children in it:
// app/layout.tsx
import { Notert } from "./notert-provider";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<Notert>{children}</Notert>
</body>
</html>
);
}The provider adds the widget's script as it mounts in the browser, so a page rendered on the server carries nothing of it, and your layout itself stays a server component. Use the package in place of the scripts, not beside them.
There's no stylesheet to import and no CSS to configure. The widget draws inside a shadow root, so your Tailwind or global styles never reach it, and its styles never leak into your app.
Identify signed-in users
Without this step, the widget knows a visitor by their browser, and your team sees whatever name and email they type. Once you identify them, they're the same person on their laptop and their phone, and your team sees the name and email your product knows, marked as verified.
The widget believes only what your server signed. That matters because any script on a page can call the widget: a client-side identify({ email }) would let anyone claim to be anyone. So your server signs a short-lived token with your workspace's identity secret, and your page hands the token over.
In a Next.js app, signing fits naturally in a server component or a route handler, since the secret stays on the server. Here's a route handler with jose:
// app/api/notert-token/route.ts
import { SignJWT } from "jose";
import { getCurrentUser } from "@/lib/auth";
export async function GET() {
const user = await getCurrentUser();
if (!user) return Response.json({ token: null });
const token = await new SignJWT({
email: user.email,
...(user.name ? { name: user.name } : {}),
email_verified: true,
})
.setProtectedHeader({ alg: "HS256" })
.setSubject(String(user.id))
.setExpirationTime("1d")
.setIssuedAt()
.sign(new TextEncoder().encode(process.env.NOTERT_IDENTITY_SECRET));
return Response.json({ token });
}getCurrentUser stands for however your app reads its session, such as Auth.js, Clerk or Better Auth. Set email_verified only once your product has confirmed the address.
Then, in a client component that knows when the user changes, pass the widget a function that fetches a fresh token. The widget asks it straight away, and again before each token runs out, so a tab left open overnight keeps working:
// app/notert-identity.tsx
"use client";
import { notert } from "@notert/widget";
import { useEffect } from "react";
// userId is the signed-in user's id from your session, or null once they've signed out.
export function NotertIdentity({ userId }: { userId: string | null }) {
useEffect(() => {
if (!userId) {
notert.identify(null);
return;
}
notert.identify(async () => {
const response = await fetch("/api/notert-token");
const { token } = await response.json();
return token;
});
}, [userId]);
return null;
}Render <NotertIdentity userId={session?.user.id ?? null} /> once in your root layout, beside the provider or the scripts.
Call identify(null) when someone signs out. Until you do, the widget keeps the person who was signed in, so on a shared computer the next one would open their conversations. The full token format, and examples in Python, Ruby, PHP and Go, are in sign a token on your server. Our guide to identifying logged-in users in a chat widget explains why a signed token beats an email passed from the browser.
Open it from your own Help button
A round button in the corner suits a marketing site. Inside a product, people look for help in the sidebar, the account menu or the header. Pick Your own button under Where it opens in the install guide, which adds launcher: false to init, or pass launcher={false} to the provider. Then give your own element data-notert-toggle:
<button type="button" data-notert-toggle>
Help
</button>A press opens the widget and another closes it, and the focus goes back to your button when it closes. With the package, useNotert() gives your button what the round button shows, a green dot while your team is available and how many replies wait unread:
"use client";
import { useNotert } from "@notert/widget/react";
export function HelpButton() {
const { toggle, isOpen, unseen, online } = useNotert();
return (
<button type="button" aria-expanded={isOpen} onClick={() => toggle()}>
Help
{unseen > 0 ? (
<span className="badge">{unseen}</span>
) : (
online && (
<span className="dot">
<span className="sr-only">Online</span>
</span>
)
)}
</button>
);
}toggle and open take a screen too, so a menu of your own can open each part of the widget: open({ screen: "new", text: "I found a bug: " }) opens a new conversation with those words waiting in the box, and open({ screen: "request" }) opens the form for a feature request. See open it on a screen.
Match your app's dark mode and language
With theme: "page", the widget follows your app's own light and dark switch where it sets a dark class or a theme attribute on <html> or <body>, as next-themes does. If yours keeps the theme somewhere else, tell the widget each time it flips:
notert.appearance({ theme: resolvedTheme === "dark" ? "dark" : "light" });For language, pass language: "page" and the widget speaks the language your <html lang> names, among the languages your workspace offers, and follows it as your app's language menu changes it. A signed-in user's token can name their language too. See light, dark or match your site and choose its language.
Content Security Policy and nonces
Many Next.js apps send a Content Security Policy from middleware, with a nonce for inline scripts. The policy needs to allow https://app.notert.io in script-src, connect-src, font-src and frame-src, plus the image and media sources the widget draws from. The inline snippet needs your nonce like any other inline script, or you can move its two lines into a file of your own that 'self' covers.
The npm package has no inline script: it adds the widget's script from your own bundle, so it needs only the sources. The widget needs nothing in style-src, since it builds its stylesheets inside its shadow root. The full list, and a whole header to copy, is in Content Security Policy.
Show it only to some users
The snippet starts the widget for everyone your page is served to. To keep it from some of them, such as a tenant that turned support off or a visitor who declined consent, take init out of the inline script and call it from your own code once you know this person may have it:
useEffect(() => {
if (user && user.mayUseSupportChat) {
window.notert.init("YOUR_WORKSPACE_ID", { widget: true, theme: "page" });
} else {
window.notert.shutdown();
}
}, [user]);Until init is called, the widget's script loads nothing more, draws nothing and stores nothing. shutdown takes it off the page without a reload. See single-page apps.
Check it's live
Deploy, then open a page of your app on its real domain. Within moments, Check it's live in the install guide shows your app's address and how long ago it saw the widget. Send yourself a message such as "Testing the widget": it lands in your Inbox (opens Notert in a new tab) at once, and a reply from there shows in the widget live.
If the widget doesn't appear, open the browser's console and look for a line starting with Notert:. These are the usual causes:
- The domain isn't listed. Preview deployments on Vercel or another host each have their own address, so add the ones you test on under Where it works.
- The policy blocks it. A Content Security Policy needs the widget's sources, and a nonce for the inline snippet.
- The token was refused. The console says why. Paste the token into Check a token on the install guide's Signed-in users tab to see what's wrong with it.
Check it's live never counts a page on your own machine, since nobody else sees it there, so it waits until the widget loads on one of your websites. The troubleshooting guide covers every console message.
What the widget gives your users
Once it's in, the same widget does more than chat. From it, a customer can message your team, search your help articles, post a feature request and vote on others, follow your roadmap and read what's new. Everything lands in one shared inbox and on your feedback board, with who they are beside it.
If you turn on Otto, Notert's AI agent, it answers first from your own docs and help articles and hands the conversation to your team when it can't. See in-app chat support with an AI agent.
Using an AI coding agent?
If you build with Cursor, Claude Code or another agent, press Copy prompt beside AI prompt under Add it to your site in the install guide and paste it in. It carries your snippet, tells the agent where it goes in a Next.js app and how to identify signed-in users, and names your identity secret only by its environment variable, NOTERT_IDENTITY_SECRET, so you still put the secret on your server yourself.
Questions people ask
Does the widget work with the Next.js Pages Router?
Yes. The widget is a script, not an App Router feature. In the Pages Router, a beforeInteractive script belongs in pages/_document.tsx, so put both scripts there, or wrap your app in NotertProvider in pages/_app.tsx.
Do I need to re-initialize the widget on route changes?
No. Client-side navigation keeps one document, so the widget stays mounted and keeps its conversation open. Call identify again only when someone signs in or out without a reload.
Will the widget slow down my Next.js app?
It's built not to. Its script waits for your page to finish loading and for a quiet moment before it draws the launcher, and the panel loads only as someone points at the launcher or opens it. See how to add a chat widget without slowing down your site.
Can I use it with Server Components?
Your layouts and pages stay server components. Only the provider and anything that calls useNotert() are marked "use client", and the token is signed on the server, where your secret lives.
Does it work on Vercel preview deployments?
Yes, once each preview address you test on is listed under Where it works. The widget only answers on your own websites, so an unlisted address draws nothing and says why in the console.
Next.js, Vercel, Auth.js, Clerk, Cursor and the other names here belong to their owners. Notert is independent of them and isn't endorsed by them.


