Skip to the page

How to add a support widget to a React app

Add a support and live chat widget to a Vite React app with a typed npm package, a useNotert hook for your own Help button, and signed-in users.

The Notert team10 min read

A modern timber and glass house in a pine forest, a woman hanging a small lantern beside its front door as a guest arrives on the path
On this page

If your product is a React app, the best place to answer a customer's question is the screen they're stuck on. A support widget puts a chat, your help articles and a way to suggest features one press away, without sending anyone to a contact page or a separate help desk.

This guide shows how to add a support widget to a React app built with Vite, or any React setup that renders in the browser. For a site built on WordPress, Shopify, Webflow or Framer, see how to add a support widget to your website. It uses Notert's widget as the example and goes past the first install: a Help button of your own with an unread count, signed-in users, sending the page's context to your team, and wiring the widget's events into your analytics. If you're on Next.js, read how to add a support widget to a Next.js app instead.

Two ways in

ApproachBest for
Paste into index.htmlGetting it live in a minute, with no new dependency
@notert/widget from npmTyped calls, a React hook, and loading it from your own code

Both draw the same widget, and only the first init on a page counts, so you can start with one and switch to the other later.

Before you start

  1. 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.
  2. Open Widget (opens Notert in a new tab) under Conversations, and press Open guide.
  3. Under Where it works, check your app's address is listed. The widget only answers on your own websites, so add your app's domain if it isn't your marketing site's.
  4. Under Where it opens, pick Chat bubble for a round button in the corner, or Your own button to open it from a Help item in your app.
  5. Under Add it to your site, copy the snippet. Its first value is your workspace's id, which the npm package needs too.

Option 1: paste it into index.html

A Vite or Create React App project has one HTML page every route shares, so the widget goes there once, below the element your app mounts in:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Brightline</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
    <script>
      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 type="module" async src="https://app.notert.io/embed/v1.js"></script>
  </body>
</html>

The small inline script runs before your app's module, since a module waits for the page to be read, so window.notert exists by the time your components call it. It also keeps any call made before the widget has loaded and plays it back once it has, so you never wait for a ready event.

With React Router or TanStack Router changing pages in place, the widget stays on screen and keeps its conversation open as people move around. There's nothing to call on a route change.

Option 2: install the npm package

npm install @notert/widget

Wrap your app in NotertProvider once, near the root:

// src/main.tsx
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { NotertProvider } from "@notert/widget/react";
import { App } from "./app";

createRoot(document.getElementById("root")!).render(
  <StrictMode>
    <NotertProvider workspaceId="YOUR_WORKSPACE_ID" theme="page">
      <App />
    </NotertProvider>
  </StrictMode>,
);

The provider loads the widget's script once as it mounts, however many times React renders it. Later props change nothing, and unmounting it leaves the widget on the page; call notert.shutdown() when you want it gone.

There's no CSS to import. The widget draws inside a shadow root, so your global styles, Tailwind's reset and your component library never reach it, and its styles never reach your app. Its font goes under a name of its own, so it never replaces yours.

Outside React, loadNotert does the same job from plain TypeScript:

import { loadNotert } from "@notert/widget";

loadNotert({ workspaceId: "YOUR_WORKSPACE_ID", theme: "page" });

Build your own Help button with useNotert

In a product, the corner is often taken by something else, and people look for help in the sidebar or the account menu. Pass launcher={false} to the provider to leave out the round button, and use useNotert() in your own:

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>
  );
}
  • unseen counts your team's replies the visitor hasn't seen, and updates about a request of theirs, such as one that moved on your roadmap.
  • online is whether someone on your team is available to answer, so the green dot means a person is around.
  • isOpen lets your button tell a screen reader whether the widget is open, which the widget leaves to your page, since the button is yours.

Before the widget has loaded, the hook reads closed, with nothing unseen and no one online, so your button renders at once and fills in. When the widget closes, the focus goes back to the button that opened it. useNotert needs React 18 or later.

Open the right screen from anywhere in your app

open and toggle take a screen, so any menu item, empty state or error message can lead straight to the part of the widget it's about:

import { notert } from "@notert/widget";

// A "Report a bug" item in your user menu.
notert.open({ screen: "new", text: "I found a bug: " });

// A "Suggest a feature" link beside a missing option.
notert.open({ screen: "request", title: "Export to CSV" });

// A "How does this work?" link beside a field customers ask about.
notert.open({ screen: "help", article: "0b7e0c8e-6f1a-4c55-9d4c-0e2a0d6c1f00" });

Nothing is sent by itself: words you write into a box wait there for your customer to send or change. The widget also opens only what the visitor may see, so a request form opens your board's Feedback tab instead for someone who may not post. Every screen is in open it on a screen.

Without any JavaScript, a button can name a screen too, with data-notert-toggle="help", "new", "request", "roadmap" and more. For a whole guide to collecting feature requests this way, see how to add a feature request button to your app.

Identify signed-in users

The widget believes only a token your server signed with your workspace's identity secret, so nobody can claim to be one of your users from the browser's console. Fetch the token with the data your app already loads for the signed-in user, and pass it on whenever the user changes:

import { notert } from "@notert/widget";
import { useEffect } from "react";

export function NotertIdentity({ user }: { user: { notertToken: string } | null }) {
  useEffect(() => {
    // A token your server signed for this user, or null once they've signed out.
    notert.identify(user ? user.notertToken : null);
  }, [user]);
  return null;
}

Call it from the code that knows when someone signs in or out, not from a script rendered with the page, since a single-page app doesn't run that again. Until identify(null), the widget keeps whoever was signed in. For an app people leave open in a tab for days, pass a function that fetches a fresh token instead, and the widget asks it whenever it needs one. Signing the token takes a few lines in Node.js, Python, Ruby, PHP or Go: see sign a token on your server, and identify logged-in users in your chat widget for why it's built this way.

Once you do, your team sees each person's verified name and email beside their conversation, and any traits you choose to send, such as their plan or seat count.

Send the page's context with each message

The questions that take longest to answer are the ones where support has to ask "which account?" or "what did you see?". context hands your team the answer with the message:

notert.context({ plan: "team", workspace: "acme", lastError: "card_declined" });

The latest set goes with the visitor's next message or request, and your team sees it beside the conversation under "From the page". Call it again whenever the facts change. It's the page's word, not verified, so it never decides who the visitor is; that's what the signed token is for.

track records what the visitor did, by its ids, which your team reads as a short timeline beside their conversation:

notert.track("checkout.failed", { code: "card_declined", attempt: 2 });

Events wait in the page and go with the visitor's first message, so a visitor who never writes sends nothing. See context and track.

Send the widget's events to your analytics

The widget tells your page what happens in it, so you can measure support like any other feature:

import { notert } from "@notert/widget";

notert.on("conversation:started", ({ conversationId }) => {
  analytics.track("Support conversation started", { conversationId });
});
notert.on("request:submitted", ({ requestId }) => {
  analytics.track("Feature request submitted", { requestId });
});
notert.on("open", () => pauseVideo());

Events carry ids alone, never what anyone wrote or who the visitor is, so they're safe to send to an analytics tool. They also follow Notert's answer: a message tells your page once Notert has it, never as the key is pressed. The full list is in on and off.

TypeScript

window.notert isn't typed for you, but the package is. Import notert from @notert/widget and your editor completes every call, screen, event and option. Its types, such as NotertPlace, NotertEvents and NotertInitOptions, make a misspelled screen or event fail your build rather than warn in the console. The package's notert calls the same widget whether loadNotert, the provider or a pasted snippet put it on the page, and does nothing on the server.

Small touches that matter on a phone

  • Back closes it. On a phone the widget fills the screen, so people reach for the Back gesture. Pass closeOnBack: true to init and Back closes the widget rather than leaving your page. It adds one history entry while open, so try it with your router before you ship it.
  • Your page keeps still. While the widget fills the screen, your page doesn't scroll behind it, and it scrolls as before once it closes.
  • Dark mode follows yours. With theme: "page", the widget matches your app where your theme switch sets a dark class or a theme attribute on <html> or <body>. Otherwise call notert.appearance({ theme }) when it flips.

See single-page apps for each of these with code.

Suggest the right help articles on each screen

The widget's first screen suggests help articles for the page it's on, by its address, as your team picks them. In a React app, one address can hold several screens, such as tabs kept in state. Name the articles yourself as the screen changes, and pass [] to hand the choice back:

useEffect(() => {
  notert.suggest(tab === "billing" ? ["0b7e0c8e-6f1a-4c55-9d4c-0e2a0d6c1f00"] : []);
}, [tab]);

Customers often find the answer there without writing at all. If you don't have a help center yet, see how to create a knowledge base.

Check it works

Run your app, open the widget and 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 you send from there shows in the widget live. Then deploy: Check it's live in the install guide shows your app's address once the widget loads on one of your websites. It never counts localhost, since nobody else sees it there.

If nothing appears, open the browser's console and look for a line starting with Notert:, which says why. The troubleshooting guide covers each one.

Questions people ask

Does the widget work with React Router and TanStack Router?

Yes. Both change pages without a reload, so the widget stays mounted and keeps its conversation open. You don't call anything on a route change.

Do I need to wrap my whole app in a provider?

Only if you use the npm package's provider. useNotert works anywhere on the page, under the provider or not, as long as something loads the widget, so a pasted snippet and the hook work together too.

Can I build the chat UI myself instead?

Notert's widget is a finished UI you can dress in your colors and drive from your own buttons and code, rather than a set of components you assemble. That's what lets it handle the parts that take the longest to build well: replies that reach a visitor by email once they've left, unread counts, attachments, keyboard and screen reader support, right-to-left text, and your customers' own languages.

Does it work in Vue, Svelte or plain JavaScript?

Yes. The snippet and @notert/widget don't depend on React; only @notert/widget/react does. The single-page apps guide has a Vue example.

Will it change my app's styles?

No. It draws inside a shadow root, so neither side's CSS reaches the other.

React, Vite, React Router, TanStack Router, Vue and the other names here belong to their owners. Notert is independent of them and isn't endorsed by them.

Keep reading

Start with your next request.

Put the widget in your app today, and tell the next customer who asks when it ships.