window.ChatWidget is available to your code.
Find your widget key
- In Sagepilot, open Channels and click your Website Widget channel.
- Open Embed Code.
- Copy the key from the launcher script. It has the format
workspace_id:channel_id.
Add the script
Paste this before the closing</body> tag. On Shopify themes, that is usually in layout/theme.liquid.
WORKSPACE_ID:CHANNEL_ID with your widget key. To change how the widget starts, add options to the init() call. See Configuration.
If your workspace is hosted in the EU region, you sign in at
eu.sagepilot.ai. Replace app.sagepilot.ai with eu.sagepilot.ai in both the script URL and host.Wait for the widget before calling it
window.sagepilotWidgetReady is created as soon as the snippet runs, before the widget has finished loading. Any code that uses window.ChatWidget can wait on it:
open() returns false and sendMessage() returns not_initialized. Always wait on the promise first.
The launcher script shown in Embed Code is a shorter one-line version. It works for the floating launcher, but it does not create
window.sagepilotWidgetReady until the script has downloaded. Use the snippet above when your own code calls the widget. If you cannot change an existing installation, see Open chat from your own button.Single-page apps
In React, Next.js, Vue, and similar apps, load the widget once for the whole app, not once per route or component render.- Add the snippet to your root HTML template, or run it once from your app’s entry point.
- Do not call
ChatWidget.init()again when routes change. A second call is ignored and logs a warning. - Keep a single
window.sagepilotWidgetReadypromise and wait on it wherever you call the widget.
app/layout.tsx
Tag managers
You can add the snippet as a Custom HTML tag in Google Tag Manager or a similar tool. Fire it on all pages where chat should appear, and fire it only once per page load.Shopify
You can install the widget on a Shopify store in two ways.
Use one method per store. Do not add the snippet to a theme that also has the Sagepilot app embed turned on.
Inline embed
To place the chat inside a section of a page instead of as a floating launcher, use an iframe:window.ChatWidget API does not control inline embeds.
Verify the installation
- Open your site in a private browser window.
- Confirm the launcher appears, unless you hid it.
- In the browser console, run
await window.sagepilotWidgetReadyand thenwindow.ChatWidget.open(). It should returntrueand open the chat. - Send a test message and confirm a ticket appears in Sagepilot on the Website Widget channel.