AI live chat for Next.js, App Router or Pages Router
Add the widget once in your root layout with next/script. It's a plain script, not a React component, so it stays out of the way of Server Components and client-side navigation.
Card required · Cancel before day 15 and pay nothing
Last reviewed 2026-10-23
Replyze on Next.js / React
4 steps · Developer setup
- 1Open app/layout.tsx (App Router) or pages/_app.tsx (Pages Router).
- 2Add the two scripts with next/script, as in the example on this page: an inline config script with an id, then the widget script.
- 3Replace wgt_YOUR_TOKEN_HERE with your widget token.
- 4Deploy, then open your live site and check that the chat button appears.
<script>
window.ReplyzeConfig = {
token: 'wgt_YOUR_TOKEN_HERE',
apiUrl: 'https://client.replyze.chat'
};
</script>
<script src="https://cdn.replyze.chat/widget.js" async></script>Why Replyze for Next.js / React
The script loads asynchronously, so it doesn't block your page.
Works with the App Router (app/layout.tsx) and the Pages Router (pages/_app.tsx).
Not a React component: no provider, no props, no state. It renders in its own shadow DOM container, so your CSS and the widget's don't collide.
Loaded once in the root layout, it stays on screen through client-side route changes.
Works in other React setups too (Vite, Remix, Astro): add the snippet to the HTML template or root layout.
Install
Add Replyze to Next.js / React
Add the config script and the widget script to your root layout with next/script, then deploy.
- 1
Open app/layout.tsx (App Router) or pages/_app.tsx (Pages Router).
- 2
Add the two scripts with next/script, as in the example on this page: an inline config script with an id, then the widget script.
- 3
Replace wgt_YOUR_TOKEN_HERE with your widget token.
- 4
Deploy, then open your live site and check that the chat button appears.
Snippet to paste
<script>
window.ReplyzeConfig = {
token: 'wgt_YOUR_TOKEN_HERE',
apiUrl: 'https://client.replyze.chat'
};
</script>
<script src="https://cdn.replyze.chat/widget.js" async></script> Replace wgt_YOUR_TOKEN_HERE with your widget token, or copy the snippet with your token already in it from Settings → Chat Widget → Install in your Replyze dashboard.
In practice
How Replyze fits into Next.js / React
The Replyze widget is a plain script, not a React component: it reads window.ReplyzeConfig, then adds the chat in its own shadow DOM container at the end of the page. There's no provider to wrap and no server-side setup.
In JSX you can't paste the HTML snippet as it is, because the braces in the config would be read as JSX. Use next/script instead: one inline script with an id for the config, then the widget script, as in the example below. In the App Router, put both in app/layout.tsx; in the Pages Router, put them in pages/_app.tsx so they load on every page.
Leave the strategy on afterInteractive, the default: Next.js loads the scripts early, after some of the page has hydrated, which suits a chat button. lazyOnload waits for browser idle time, and beforeInteractive is for scripts that must load before any page hydration, which a chat widget doesn't need.
The widget runs entirely in the browser, so React Server Components, streaming and middleware don't affect it.
import Script from 'next/script'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script id="replyze-config" strategy="afterInteractive">
{`window.ReplyzeConfig = { token: 'wgt_YOUR_TOKEN_HERE', apiUrl: 'https://client.replyze.chat' };`}
</Script>
<Script src="https://cdn.replyze.chat/widget.js" strategy="afterInteractive" />
</body>
</html>
)
}What visitors on Next.js / React get
AI first, your team when it matters
Answers from your own help articles
The AI replies in the visitor's language from the articles you publish and the answers your team teaches it. If the answer isn't there, it says so instead of guessing.
A person when it matters
Visitors can ask for a person at any time, and topics your industry setup marks for the team, such as refunds and complaints, are handed over too. The teammate replies in the same chat, with the whole conversation in front of them.
Chat, email and messaging in one inbox
Web chat on every plan. Email, WhatsApp and Telegram on Pro and Business, with Messenger and Instagram in beta, all in one shared inbox.
FAQ
Next.js / React + Replyze, answered
Yes. The widget runs entirely in the browser and isn't a React component, so Server Components render as usual and the widget starts on its own once its script loads.
The widget script loads asynchronously, so it doesn't block your page, and with strategy="afterInteractive" Next.js adds it after the page starts hydrating. Like any third-party script it still has to download and run, so compare your own pages before and after.
You can, but you usually don't want to. In the root layout it loads once and stays through client-side route changes. Inside a component it would only load where that component renders.
Unaffected. The widget is a client-side script. Middleware runs on the server before the response is sent; the widget loads after the browser receives the page.
Yes: anywhere you can ship a script tag. Paste the snippet into index.html in a Vite app or src/app.html in SvelteKit. In Astro, paste it into your layout and add is:inline to the first script so Astro leaves it as written. In JSX-based setups such as Remix, add the config as an inline script and the widget as a script tag in your root component.
Other platforms
Get your Next.js / React chat ready for customers
Once the widget is installed, give it useful answers and connect it to the people who will reply. These examples cover what to publish, where to test the chat and how to handle the first enquiries from your Next.js / React site.
Read moreRead less: Get your Next.js / React chat ready for customers
What will visitors ask on your Next.js / React site?
“Where do I find the getting-started guide?” is one question to try. It is the kind of detail a visitor may want while reading a page, before sending a message or making a purchase. Start with the questions your team hears most often about onboarding, plan features and support contacts. Write the answer in a Replyze help article, using the same terms and conditions customers see on the website. Include the next step and a useful link when the customer needs another page.
Open the page where that question is likely to come up and ask it in your own words. Then ask a follow-up: “What if my situation is different?” Read both replies and request a person. This gives you a first check of the answer and the connection to your team before you invite customers to use chat.
Before and after adding chat to Next.js / React
Before: someone looking for onboarding, plan features and support contacts may search the navigation, open a contact form and wait for an email. A clear website already answers many of these questions, so look for the points where people still get stuck. Your last few customer messages can show which explanation is missing or hard to find.
After: the visitor asks in the widget and receives an answer from the articles you have published. If the question concerns their own order, appointment or account, the team can continue in the same conversation. For example, a general policy question can lead into “Can you check my request?” The first answer stays visible when a colleague takes over, along with the details the customer has already shared.
Which help articles should you prepare first?
Create a short article for each of your main topics: onboarding, plan features and support contacts. Explain the usual answer, the conditions that change it and the contact route for an individual request. Use your current website information as the starting point. The widget connects your site to Replyze; add the information you want the assistant to use in the knowledge base as a separate setup step.
If those answers already live in a document, Write with AI can prepare draft articles for you to check. Read the dates, amounts and exceptions carefully before publishing. Remove old versions that disagree with the new answer. When you change a policy on your Next.js / React site, update the corresponding article too so customers get the same explanation in both places.
Where should you add the Next.js / React snippet?
Use the framework placement shown above and check client navigation so the widget is not inserted again on every route. Start with the first installation step above: Open app/layout.tsx (App Router) or pages/_app.tsx (Pages Router). Use the snippet from the Replyze workspace that belongs to this website and follow the remaining platform steps. The workspace setting determines where the messages arrive, so check it before publishing, especially if you manage several brands or client sites.
Keep the snippet in one installation location. If another person previously added chat through a theme, a custom-code setting or a tag manager, locate that copy before adding a new one. Two installations can make troubleshooting confusing. Tell the person maintaining the site where you placed it, so the next theme update or redesign includes the same check.
What happens when a visitor needs a person?
Try a follow-up that needs somebody to check an individual request: “Can you change this for me?” The chat should explain how to reach the team and keep the conversation available for the person who responds. The website installation provides chat; account changes, order checks and booking confirmations still use the business systems and people responsible for them.
Ask directly for a teammate as well. Open the shared inbox and read the conversation from the receiving person’s side. Can they see what the customer wants and what has already been answered? Set the opening hours and contact instructions your team can actually support. When nobody is available, the customer needs a way to leave a contact detail and a clear expectation for the reply.
Should chat replace your contact form?
Keep a contact form when it helps customers send a detailed enquiry in one go. A project brief, a request involving several products or a message sent outside office hours may suit that format. Chat is useful when somebody has a short question and wants to ask a follow-up while looking at the page. The two contact options can serve the same website.
Try both routes with the question “Where do I find the getting-started guide?”. Check which one helps the visitor reach an answer comfortably. On a phone, open the chat alongside any cookie notice and the page’s main button. Make sure customers can still continue browsing, submit the form or complete their purchase. Adjust the widget placement through its available settings if it covers an important control.
Which Next.js / React pages should you check?
Start with the first page load and two client-side route changes. These checks catch differences between templates and publishing settings that a homepage-only test can miss. Visit each page directly, then navigate between them as a customer would. Confirm that the chat opens and that a message reaches the same intended workspace from each location.
Some parts of a platform have their own code restrictions or access settings. Use the platform instructions above when checking a checkout, customer account or other restricted area. Keep your existing support link available wherever the widget is not installed. A simple list of the pages you have checked helps the website maintainer repeat the right tests after a redesign.
How can you tell that messages reach the right team?
Send a message labelled “Website chat test” from the published Next.js / React site and find it in Replyze. Reply as a teammate and check that the answer appears in the visitor’s chat. Request a human handover and verify the notification route the team uses. This confirms the path in both directions.
For an agency or a business with several websites, repeat the test for each workspace. Check that the help articles and team access belong to the same business as the site. Ask the colleague who will answer real enquiries to try a reply. They should know where the conversation appears and which contact instructions customers see outside opening hours.
What if the widget is missing on Next.js / React?
First check the published site in a fresh browser window. Confirm that the installation change was saved and published, and follow any cache instructions in the guide above. Use the framework placement shown above and check client navigation so the widget is not inserted again on every route. Check the snippet location before changing its contents. A missing publish step or a different active template can explain why a change appears in an editor but not on the public website.
Once the widget appears, test typing, opening and closing it on a phone. Navigate to another page and try again. Keep the previous website configuration in your normal version history so the site maintainer can undo a mistaken placement. Removing the snippet from the website is a separate task from managing the Replyze workspace and its conversations.
What should you update after launch?
Read the first enquiries about onboarding, plan features and support contacts. If several people ask the same question, improve the relevant help article and the page that prompted it. When a reply needs a teammate, check whether that person had enough information to continue. A useful first week often reveals a missing policy detail or a confusing link that is easy to fix.
Repeat the installation check after a theme change, a new template or a platform migration. Repeat the answer check when your services or policies change. Give the website maintainer the page list and give the support team the sample questions. That keeps both parts of your Next.js / React chat working as the site grows.
Choose your next step
Let AI answer the questions you get every day
Teach it your answers, pick your colours and add it to your site. When a customer needs a person, your team takes over.
Card required · Cancel before day 15 and pay nothing. No card? Start on the Free plan.