GetMyBot ナレッジベース

Install in a React, Next.js or Vue app

Add the chat widget to a React, Next.js, or Vue app and keep it open while visitors move between pages.

このページの内容

React, Next.js, and Vue apps often switch pages without fully reloading the browser. Add the widget code to a shared part of the app so the chat stays open during those transitions.

Copy the complete snippet from Widget → Install and add your app's domain to Allowed sites. The code placement below is for your site's developer. Chat settings are covered in Site widget.

Where to paste the snippet

Paste the complete snippet once in a shared layout that remains in place when visitors move between pages. The location depends on your site:

  • Next.js (App Router): the root app/layout.tsx, inside <head> (or via the Script component with strategy="afterInteractive").
  • Next.js (Pages Router): pages/_document.tsx, inside <Head>.
  • Vue with Vite or Vue Router: the root index.html, inside <head>. For Nuxt, ask your developer to add the snippet to the app-wide layout.
  • React with Create React App: public/index.html, inside <head>. React with Vite: the root index.html, inside <head>.

Do not paste the snippet into a single page: the app may remove that page along with an open chat when the visitor navigates away.

Verify the installation

Publish the change.

Open the chat and move to another page through the app's menu. Check that the chat and current conversation remain open. Then send a message and check that it appears in Chats in GetMyBot.

Then open Widget → Install in GetMyBot and run Check installation on a published page. Automatic diagnostics explains the widget readiness result.

Why add the code only once

An open chat should stay in place as the visitor moves between pages. Put the widget in a shared layout that the app keeps mounted. The loader preserves an existing session with window.mybot = window.mybot || {}, and loading the bundle again does not create a second widget. But if the app removes the page together with the chat, unsaved state is lost. The script does not need to run again after each navigation.

Common pitfalls

  • Do not add the snippet again to individual pages: the app may remove them along with the chat during navigation.
  • In a Next.js app using the Script component, prefer strategy="afterInteractive" over "beforeInteractive" for the loader, so it does not block first paint.
  • If a server or CDN caches pages, clear that cache when publishing. Otherwise visitors may keep receiving an older page without the new code.

What's next