# Add the chat widget to your website

> Paste one script tag before the closing body tag and your AskVault agent answers visitors on your site, with sources. Works on plain HTML, React and Next.js.

Copy the script tag from **Channels** and paste it before the closing `</body>` tag on every page where you want the chat. The widget loads without blocking your page, answers from the content you indexed, and shows the pages each answer came from.

The widget is plain JavaScript that draws its own chat inside a closed shadow DOM, so your site styles cannot leak into it and its styles cannot leak out. It works on any stack: WordPress, Shopify, Webflow, Wix, Squarespace, React, Vue, Next.js, Angular, Svelte and plain HTML.

## Before you start

- An AskVault agent with content indexed. The widget can only answer from pages and files AskVault has read. See [add your website](/knowledge/add-your-website/).
- Access to your site's HTML, theme or layout file.
- The Free plan includes the widget. 

## Steps

#### New dashboard

1. Open **Channels & Apps** in the sidebar, then the **Channels** tab.
2. On the **Website widget** card, click **Manage** and copy the snippet from the install view.
3. Paste it before the closing `</body>` tag on every page that should show the chat.
4. Reload your site. The launcher appears. Ask a question only your content can answer.

#### Previous dashboard

1. Open **Channels** and pick **Website Widget**. The **Install** tab shows your embed code and a live preview.
2. Copy the snippet. The `data-token` value is unique to your agent. It is safe to keep in public page source because it is not a secret.
3. Paste it before the closing `</body>` tag on every page that should show the chat.
4. Reload your site. The launcher appears in the corner. Ask a question only your content can answer.

## The snippet

```html
<script src="https://api.askvault.co/widget.js" data-token="YOUR_TOKEN" data-api="https://api.askvault.co" async></script>
```

Use the exact snippet your dashboard shows, with your own token. The `async` attribute means the script never holds up your page. Position, colour and theme come from your appearance settings, so changing them in the dashboard reaches your live site without editing the snippet. See [customise your agent's look](/agent/appearance/).

## React and Next.js

The widget is a script tag, not an npm package. It runs the same on any React version and adds nothing to your JavaScript bundle.

#### Plain HTML, Vite, Create React App

Put the tag in your HTML template, just before `</body>`:

```html
<body>
  <div id="root"></div>
  <script src="https://api.askvault.co/widget.js" data-token="YOUR_TOKEN" data-api="https://api.askvault.co" async></script>
</body>
```

#### Next.js

Load it once from your root layout with the built-in `Script` component. In the Pages Router, put the same component in `pages/_app.tsx`.

```tsx
// app/layout.tsx

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        
      </body>
    </html>
  );
}
```

The layout can stay a Server Component. The widget runs in the browser after hydration.

To show the widget only on some routes, inject the script from an effect on those routes, and keep the script's `src`, `data-token` and `data-api` values as above. Once loaded, the widget stays for the rest of the browser session.

To tell the widget who is signed in, to open it from your own button, or to record events, see the [widget JavaScript API](/developers/widget-javascript-api/). To stop anyone posing as another user, use [identity verification](/developers/identity-verification/).

## Restrict the widget to your domains

Each widget token has an **Allowed Domains** field. Leave it empty and the widget answers on any site that carries your token. List your domains and it answers only there. Add your production domain here, or the widget will refuse to answer on it. A domain list also stops other sites from using your token and spending your message credits.

## Let visitors talk to a person

Turn on **Let visitors talk to a human** for the widget and the chat offers a **Talk to a human** option. Those conversations arrive in your Inbox, and the agent can also hand a chat to your team on its own. Live chat needs the Growth plan. 

If nobody on your team joins within 2 minutes, the widget tells the visitor nobody is available and shows a short form to leave contact details. See [hand a chat to a person](/actions/hand-off-to-a-person/) and [handoff and spam protection](/agent/handoff-and-spam/).

## Remove the "Powered by AskVault" badge

Widgets on Free and Starter show a small "Powered by AskVault" link. The Growth plan and above can remove it with the branding toggle in your appearance settings. 

## Check it worked

1. **The launcher shows on every page you expect.** If it is missing on one, that page does not carry the script tag.
2. **Answers cite your content.** Ask something only your pages answer. The reply shows its sources. No sources usually means indexing is not finished: check **Knowledge**.
3. **The conversation reaches your Inbox.** Send a test message and look for it in the [Inbox](/inbox/) within a minute. If it never appears, the token in the snippet is wrong.

## If it doesn't work

**The launcher never appears.** Open your browser's Network tab and look for `widget.js`. If it loads, check the token and that the agent is active. If it does not load, a content blocker or a caching layer may be serving an old page: try a private window.

**The widget refuses to answer on your live site.** Your domain is missing from **Allowed Domains**. Add it and save.

**"window is not defined" in a server-rendered app.** Touch `window.AskVault` only inside an effect or behind a `typeof window !== 'undefined'` check.

**Two chat bubbles overlap.** Remove the other chat tool, or move the AskVault launcher to the other corner in your appearance settings.

**Visitors without JavaScript see nothing.** The widget needs JavaScript. Link to your [hosted chat page](/channels/hosted-page/) as a fallback.

## Common questions

### Can I run two widgets on one page?

No. One agent has one widget. For a sales bot and a support bot, use separate agents (workspaces) and load whichever token fits the page.

### Can the widget collect leads?

Yes. Switch on the lead-capture action and the agent asks for a name and email when a visitor shows buying interest. See [collect leads](/actions/collect-leads/).

### What does the widget store in the visitor's browser?

A conversation ID, so a returning visitor can pick up where they left off.

## Related

- [Channels](/channels/) lists every place your agent can answer.
- [Add AI chat to a WordPress site](/channels/wordpress/)
- [Share a hosted chat page](/channels/hosted-page/)

Source: https://docs.askvault.co/channels/website-widget/
