EN
Webmail

Live Chat in React, Next.js, Vue and Nuxt Apps with Talkmio

Live Chat in React, Next.js, Vue and Nuxt Apps with Talkmio

Live chat in React, Next.js, Vue or Nuxt looks like a bigger job than live chat on a brochure website, and in many teams it sits on the backlog for months because nobody is sure where the code should go. In a single-page application the page does not reload when a visitor clicks around, a server may render the first view before any browser code runs, and the layout file belongs to developers who would rather not touch it for a marketing widget. The good news is that Talkmio keeps the technical part small. For React and Next.js there is a ready component, and for Vue and Nuxt a single script tag is enough. This guide walks through both routes, explains where each piece of code belongs, and shows how to test the result before real visitors see it.

Talkmio is the AI live chat and inbox from Internet Solutions. Its assistant, Mio, reads your own website pages, FAQ and documents and answers visitors in their language, and a person from your team can take over any conversation. If you are new to the product, our Talkmio page explains what it does. Here we concentrate on the developer side: how the chat gets into a JavaScript application cleanly, and how to avoid the problems that typically appear in apps rather than in plain websites.

What you need before you start

Two things are required, and both take a few minutes. First, a Talkmio account. The free plan needs no credit card. Second, a site key. After signing in at app.talkmio.com you open the Websites section, add your website and copy the twelve-character key. That key identifies your site; it is not a password and appears in the script address that visitors’ browsers load, but you should still keep it in one place, such as an environment variable, rather than pasting it into many files.

It also helps to decide, before touching code, what Mio should know. The chat is only as useful as the content behind it. If your product documentation lives in a separate application or behind a login, plan to add the important pages or answers to the knowledge base so that Mio can use them. Our guide to the Talkmio knowledge base describes what to teach and how to test the answers.

Route one: the React component for React and Next.js

The React integration is a small component named TalkmioChat. According to the Talkmio integration page it works with React, Next.js (both the App Router and the Pages Router), Vite, Remix and Gatsby, and it is safe for server-side rendering: it loads the widget once in the browser and identifies the current user. The package is supplied as a download, talkmio-react-1.0.0.zip, from the integration page.

Step by step

  1. Download the zip file from the Talkmio React page and unpack it.
  2. Either copy src/index.js into your project, or install the package from the unpacked folder with npm install ./talkmio-react.
  3. Render the component once, for example in your root layout: <TalkmioChat siteKey="YOUR_SITE_KEY" user={{ name, email }} />.
  4. Build or start the app and open it in a private browser window.

The word “once” matters. The chat bubble belongs to the whole application, not to a single page, so the component should live in the part of the tree that stays mounted while visitors move between routes. If you render it inside a page component, it may be mounted and unmounted every time the route changes, which is exactly what you do not want from a chat window that holds a conversation.

Next.js App Router

In the App Router, layouts are server components by default. The Talkmio page gives a precise instruction: put the component in a client component, marked with 'use client' at the top of the file, and include that client component from app/layout.js. In practice this means a tiny wrapper file, for example chat.js, which starts with the directive, imports TalkmioChat and returns it with your site key. The layout then renders the wrapper next to its children. The Next.js documentation explains the use client directive and the boundary it creates between server and client code. Keeping the wrapper separate has a second benefit: the layout stays a server component, and only the small chat wrapper is sent to the browser as client code.

Next.js Pages Router, Vite, Remix and Gatsby

In the Pages Router the natural home is the custom app file, which wraps every page. In a Vite project it is the root component, in Remix the root route, and in Gatsby the wrapper that applies to all pages. The rule is the same in each case: one place, rendered for every route, mounted once.

Identifying signed-in users

The component accepts a user object with a name and an e-mail address. When your application knows who is signed in, passing these values means your team sees a real person in the conversation instead of an anonymous visitor, and Mio and the operator do not have to ask for contact details that the application already holds. If nobody is signed in, leave the property out or pass nothing, and the chat works for anonymous visitors. Pass only what you are comfortable sharing with the chat service, and mention it in your privacy information; the name and e-mail address are the two fields the component is designed to send.

Route two: one script tag for Vue and Nuxt

For Vue and Nuxt there is no package to install. The widget is a single script, and the address is built from your site key: https://app.talkmio.com/w/YOUR_SITE_KEY.js. The two common setups differ only in where you place that line.

Nuxt 3

In nuxt.config.ts you add the script to the head of the application. The Talkmio instructions use the app.head.script option with the script source and the async flag set to true. Because the configuration applies to every route, the script is present on every page, and because it is asynchronous it does not block rendering. The Nuxt documentation on head and meta configuration shows the available options, including how to add scripts globally or from a single page or component.

Vue with Vite

In a standard Vite project the page shell is index.html in the project root. Paste the script tag, with the async attribute, just before the closing body tag. Because a Vue single-page application loads this shell once and then changes views without reloading, the widget loads once and stays in place while visitors move through the routes.

Identifying users in Vue and Nuxt

Identification is optional. Before the Talkmio script runs, set a global variable named window.__TALKMIO_USER__ to an object with the name and e-mail address. In a Nuxt application this usually means a small client-side plugin that runs after sign-in; in a Vue application it can be set when your authentication store changes. Remember that the order matters: the value should exist before the script reads it, so set it as early as the user data is available.

Which route fits which project

QuestionReact componentScript tag
Frameworks listed by TalkmioReact, Next.js, Vite, Remix, GatsbyVue, Nuxt and any other site
What you installA small package or one source fileOne line of HTML or head configuration
Where it goesRoot layout, rendered onceNuxt head configuration, or the page shell
Identifying usersThe user property with name and e-mailA window.__TALKMIO_USER__ value set before the script
Server renderingSafe: loads once in the browserNot applicable: the script runs in the browser
Best forTeams that want the chat as part of the component treeTeams that want no new dependency

Nothing stops a React team from using the plain script tag as well. The component exists because many React teams prefer to keep everything inside the application, and because it handles the user identification in a way that fits the framework. If your project is a mixture, for example a marketing site on one framework and an application on another, you can use a different route for each,.

Testing before you go live

Talkmio recommends a simple test that works for every platform: after installing, open your site in a private browser window and ask Mio two or three questions your customers often ask. Check that each answer comes from your own pages. If something is missing, add it to your website or knowledge base and ask again. For a JavaScript application, add a few technical checks to that list.

  • Navigate without reloading. Click through at least three routes. The bubble should stay in place, and an open conversation should not reset.
  • Refresh a deep route. Load a page two levels down directly. The bubble should appear there too.
  • Check the console. Open the browser developer tools and look for errors on first load. A hydration warning or a blocked script points to the cause quickly.
  • Sign in and out. If you pass user details, confirm that the name and e-mail appear when signed in and that nothing stale remains after signing out.
  • Try a phone. Open the app on a small screen and make sure the bubble does not cover a primary button or a cookie banner.

Problems that appear in applications, and how to avoid them

The widget loads twice

If the component sits in a page that remounts, or if both a head script and a component are present, you can end up with two bubbles or two connections. Use one route per application and render it in one place.

A content security policy blocks the script

Many applications ship a Content-Security-Policy header. If yours restricts script sources, add the Talkmio script host to the allowed list, or the browser will refuse to load the widget and the console will say so. Our guide to security headers explains how these policies work and why they are worth keeping.

Consent tools and tag rules

If a consent management tool controls which third-party scripts run, decide with whoever owns privacy in your company whether the chat should load before or after consent, and configure the tool to match. This is a policy decision rather than a technical one, and it is easier to settle before launch than after a complaint.

Performance

An asynchronous script does not block the first paint, but every third-party script has a cost. Measure your own pages before and after, and read our guide on how third-party scripts and widgets slow a website for what to check. Talkmio’s own advice is to keep the installation simple: one script, loaded once.

Search engines and rendered content

The chat widget is not content that you want indexed, and it does not change what search engines see on your pages. If your application renders most of its text in the browser, that is a separate question from the chat, covered in our article on JavaScript SEO.

After the install: make the first week count

The code is the easy part. The value comes from what the chat knows and how quickly your team responds when a person is needed. Spend the first week adding the pages and answers that customers ask about most, read the first conversations, and fix gaps as they appear. Our seven-day plan for the first week with Talkmio gives a day-by-day order of work, and the article on widget setup covers colours, greeting and business hours. Talkmio also lists installation pages for many other platforms; the integrations overview shows all of them, and if your platform is missing, the widget is one script tag and the team builds modules on request.

A short checklist for developers

  1. Create the account and add the website to get the site key.
  2. Store the key in an environment variable or configuration file.
  3. Choose one route: the React component or the script tag.
  4. Place it once, in the root layout or the page shell.
  5. Decide whether to identify signed-in users, and pass only the name and e-mail address.
  6. Check the content security policy and the consent tool.
  7. Test in a private window, across routes, on a phone.
  8. Add your key pages and answers to the knowledge base.

Frequently Asked Questions

Do I need a package to add Talkmio to a Vue or Nuxt app?

No. For Vue and Nuxt the widget is a single script tag. In Nuxt 3 you add it in the head section of the configuration file, and in a Vite-based Vue project you paste it into the index page before the closing body tag.

Does the React component work with server-side rendering?

Yes. Talkmio describes the component as safe for server-side rendering: it loads the widget once in the browser. In the Next.js App Router, place it in a client component marked with the use client directive and include that component from the root layout.

Where is my site key?

Sign in at app.talkmio.com, open Websites, add your website and copy the twelve-character key. You can create a free account without a credit card.

Can the chat show who is signed in?

Yes. In React you pass a user object with a name and e-mail address to the component. In Vue and Nuxt you set a global value named window.__TALKMIO_USER__ before the script loads. Identification is optional, and the chat also works for anonymous visitors.

Will the chat reset when visitors move between pages?

It should not. Because the widget loads once and stays in the application shell, a conversation continues while visitors move between routes. If it resets, check that the component is not mounted inside a page that is replaced on every route change.

How do I know the answers are correct before launch?

Open the site in a private browser window, ask Mio two or three questions your customers often ask and check that each answer comes from your own pages. If something is missing, add it to your website or knowledge base and ask again.

The Bottom Line

Adding live chat to a JavaScript application is a small technical task if you pick the right route. Use the React component for React, Next.js, Vite, Remix and Gatsby, and the single script tag for Vue, Nuxt and everything else. Place it once, in the part of the application that stays mounted, pass user details only if you want them, and test in a private window across several routes and on a phone. Then spend your effort where it counts: giving Mio good content and answering quickly when a person is needed. If you would like help with the integration or with the application around it, the website development team at Internet Solutions builds web applications, client portals and internal systems, and can add the chat as part of the work.