Skip to main content
Any element on your site can open the chat, for example a Chat with us link in your header, an Ask an expert button on product pages, or a help prompt inside a cart drawer.

Open chat from a button

This example assumes you installed the widget with the snippet in Installation, which creates window.sagepilotWidgetReady.
1

Mark the elements that open chat

Add the data-sagepilot-open attribute to any button or link. You can use it on as many elements as you like.
2

Handle the click

Add this once per page, after the widget snippet.
The handler listens on the whole page, so it also works for elements your theme or apps add later, such as a slide-out cart or a popup. If a visitor clicks before the widget has finished loading, the chat opens as soon as it is ready.

Hide the floating launcher

If only your own buttons should open the chat, add hideNativeLauncherButton: true to the init() call. This hides the launcher in the corner of the page and its welcome popup. ChatWidget.open() still works.
The unread-message badge appears only on the Sagepilot launcher. If you hide it, visitors see new replies when they open the chat.

If you cannot change the install snippet

Use this version if the widget is already installed and you cannot edit its snippet, for example when it was installed with the Sagepilot Shopify app embed, through a tag manager, or with the one-line script from Embed Code. It does not need window.sagepilotWidgetReady.
ChatWidget.open() returns false until the widget is ready, so the helper retries every 250 ms for up to 10 seconds. While it retries, the browser console may show [ChatWidget] Widget not initialized warnings. These are expected. Do not add a second copy of the widget script to reach the API. The widget must be loaded only once per page.

Complete example

A Shopify theme that shows its own Ask the concierge button and no floating launcher. Add this to layout/theme.liquid before </body>, and put the button wherever it should appear in your theme.

Close and toggle the chat

For example, a button that switches between open and closed:

How opening behaves

  • open() always opens the full chat. It skips the welcome popup and the two-step intro card.
  • Calling open() while the chat is already open does nothing. Repeated clicks do not create extra windows or new conversations.
  • Opening the chat does not send a message. To prefill or send one, see Draft and send messages.
  • Visitors who have chatted before on the same browser see their existing conversations.
  • On screens 768 px wide or narrower, the chat opens full screen. Visitors close it with the close button inside the chat.

Verify the setup

  1. Open your site in a private browser window.
  2. Click your button. The chat should open.
  3. Click it again several times. The same chat should stay open.
  4. Close the chat and click the button again. It should reopen.
  5. Repeat on a phone, or with your browser’s device toolbar set to a phone width.
  6. In your browser’s developer tools, throttle the network to a slow connection, reload, and click the button immediately. The chat should open once the widget finishes loading.
If nothing happens, see Troubleshooting.