> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sagepilot.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Web SDK

> Add Sagepilot chat and Web Push to an authenticated website.

The Sagepilot Web SDK has two independent browser integrations:

| Integration | What it owns |
| - | - |
| Website Widget script | Hosted support chat, customer identity, messages and launcher behavior through `window.ChatWidget`. |
| `@sagepilot-ai/web-push-addon` | Browser permission, service worker, Web Push subscription, endpoint registration, preferences, logout and engagement observations. |

The chat widget is a single script served by Sagepilot, so there is no chat package to install. Web Push is an optional npm add-on and works without chat. When you use both, identify them from the same authenticated customer so Sagepilot can associate browser and mobile endpoints with one customer.

## Requirements

* A **Website Widget** channel in Sagepilot. See [Website Widget](https://docs.sagepilot.ai/integrations/channels/website-widget) to create one.
* The channel's widget key, in the format `workspace_id:channel_id`. You can copy it from the channel's install script.
* Access to your site's HTML, theme files, or tag manager.

For Web Push, you also need an active **Push Notifications** channel, HTTPS, a backend-authenticated customer and the `@sagepilot-ai/web-push-addon` package. Follow [Web Push integration](https://docs.sagepilot.ai/sdks/web/push-notifications.md).

## Quick start

**1. Add the script**

Paste this before the closing `</body>` tag on every page where chat should be available. It loads the widget and stores a promise, `window.sagepilotWidgetReady`, that resolves when the widget is ready.

```html theme={null}
<script>
  window.sagepilotWidgetReady = new Promise(function (resolve, reject) {
    var script = document.createElement("script");
    script.src = "https://app.sagepilot.ai/chat-widget.js";
    script.async = true;
    script.onload = function () {
      window.ChatWidget.init({
        host: "https://app.sagepilot.ai",
        key: "WORKSPACE_ID:CHANNEL_ID"
      }).then(resolve, reject);
    };
    script.onerror = function () {
      reject(new Error("Sagepilot widget failed to load"));
    };
    document.head.appendChild(script);
  });
</script>
```

**2. Open chat from your own button**

```html theme={null}
<button type="button" data-sagepilot-open>Chat with us</button>

<script>
  document.addEventListener("click", async function (event) {
    if (!event.target.closest("[data-sagepilot-open]")) return;
    event.preventDefault();
    await window.sagepilotWidgetReady;
    window.ChatWidget.open();
  });
</script>
```

**3. Identify signed-in customers**

```js theme={null}
await window.sagepilotWidgetReady;
await window.ChatWidget.identify({
  user_id: "user_123",
  email: "jane@example.com",
  name: "Jane Doe",
  user_hash: "HASH_FROM_YOUR_SERVER"
});
```

Replace `WORKSPACE_ID:CHANNEL_ID` with your widget key.

## Start here

> [card] [Install the widget](https://docs.sagepilot.ai/sdks/web/installation.md)
>
> Add the script to a website, single-page app, tag manager, or Shopify store.

> [card] [Configure the widget](https://docs.sagepilot.ai/sdks/web/configuration.md)
>
> Set launcher, placement, and layout options when the widget starts.

> [card] [Open chat from your button](https://docs.sagepilot.ai/sdks/web/opening-chat.md)
>
> Connect chat to your own buttons, links, and banners.

> [card] [Identify customers](https://docs.sagepilot.ai/sdks/web/identity.md)
>
> Link chats to signed-in customers and verify their identity.

> [card] [Add Web Push](https://docs.sagepilot.ai/sdks/web/push-notifications.md)
>
> Register browser endpoints, manage consent and capture notification engagement.

> [card] [Draft and send messages](https://docs.sagepilot.ai/sdks/web/sending-messages.md)
>
> Prefill or send a message from your page.

> [card] [API reference](https://docs.sagepilot.ai/sdks/web/api-reference.md)
>
> Every `window.ChatWidget` method and what it returns.

## How it works

The script adds a launcher button and a hidden chat frame to your page. The chat itself is hosted by Sagepilot, so appearance, greetings, conversation starters, and the AI agent come from the channel settings in Sagepilot. You can change those settings without editing your site.

| Where you change it | What it controls |
| - | - |
| Sagepilot channel settings | Colors, logo, launcher position and text, welcome popup, conversation starters, contact form, OTP, identity verification, AI agent, and routing. |
| `ChatWidget.init()` options | Page-level overrides such as hiding the launcher, bottom padding, and stacking order. See [Configuration](https://docs.sagepilot.ai/sdks/web/configuration.md). |
| `window.ChatWidget` methods | Runtime behavior from your code: opening and closing chat, identity, and messages. |
| Web Push add-on | Browser permission, subscription repair, endpoint registration, notification preferences and signed engagement observations. |

On screens 768 px wide or narrower, the open chat fills the screen. On wider screens, it opens as a panel of up to 420 × 700 px on the side set in the channel settings.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.