---
title: Install the chat
description: Add the PandaDesk chat to your website with one script tag, allow your domains, and confirm it's live.
section: Chat and knowledge
order: 1
---

The PandaDesk chat is one script tag. Add it once to your site's layout and every page gets a chat bubble that answers from your knowledge and hands off to your team.

## 1. Allow your website

The chat only loads on websites you've allowed, plus your own PandaDesk help center. Add every origin the chat runs on under **Settings → Security → Allowed websites** (or in the **Allow your website** setup step).

- An origin is the scheme, host and port: `https://app.example.com`, `http://localhost:3000`.
- `example.com` also covers `www.example.com`, and the other way round.
- Wildcards (`*.example.com`) aren't accepted. Add each subdomain you use.

> **Note:** If the chat doesn't appear, check the browser console. The loader prints `[PandaDesk] Messenger not loaded:` with the reason, for example that the site isn't allowed.

## 2. Add the snippet

Copy the snippet with your workspace's key from the **Install** page in the dashboard:

```html
<script src="https://pandadesk.app/widget.js" data-key="pk_YOUR_KEY" async></script>
```

Put it once per page, before `</body>` (or in `<head>`: it loads asynchronously and never blocks your page). One snippet covers the whole site.

### Next.js (App Router)

```tsx
// app/layout.tsx
import Script from "next/script";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script src="https://pandadesk.app/widget.js" data-key="pk_YOUR_KEY" strategy="afterInteractive" />
      </body>
    </html>
  );
}
```

### Next.js (Pages Router)

```tsx
// pages/_document.tsx, inside <body> after <NextScript />
<script src="https://pandadesk.app/widget.js" data-key="pk_YOUR_KEY" async></script>
```

### React, Vue and other single-page apps

Append the script once, for example in your root component:

```tsx
useEffect(() => {
  if (document.querySelector('script[data-key="pk_YOUR_KEY"]')) return;
  const s = document.createElement("script");
  s.src = "https://pandadesk.app/widget.js";
  s.async = true;
  s.dataset.key = "pk_YOUR_KEY";
  document.body.appendChild(s);
}, []);
```

In Vue, do the same in `onMounted` of your root component (or in `main.ts`). Route changes are picked up automatically, so your team sees which page the visitor is on.

### WordPress

**Appearance → Theme File Editor → footer.php**, paste the snippet before `</body>`. Or use any "header and footer scripts" plugin.

### Shopify

No code needed: install PandaDesk from the Shopify App Store, then turn on the **PandaDesk chat** app embed. See [Shopify](/docs/shopify).

### Webflow, Framer, Squarespace

**Site settings → Custom code → Footer code**, paste the snippet, then publish.

## 3. Check it's live

Open a page of your site in a browser. Setup's **Add the chat to your site** step ticks off the first time the chat loads on one of your allowed websites.

## How the chat loads

The loader is built to cost almost nothing on pages where nobody chats:

- `widget.js` is cached by browsers for an hour. Your chat's look is cached for a minute per visitor.
- The chat window itself loads only when the visitor opens the bubble or hovers over it, so it still opens instantly.
- A visitor with a conversation in progress gets the chat loaded in the background a few seconds after the page settles. If your team has replied, the bubble shows a red dot.
- While the chat is open, it checks for new messages every 3 seconds. While it's closed, every 45 seconds.

Changes you make under **Chat appearance** reach your site on the next page load, without touching the snippet.

## Script tag options

| Attribute | Required | What it does |
|---|---|---|
| `data-key` | Yes | Your workspace's public key (`pk_…`). It's safe to put in page source. |
| `data-color` | No | A hex color for the bubble and chat, overriding the dashboard. |
| `data-position` | No | `left` puts the bubble in the bottom-left corner, overriding the dashboard. |

## JavaScript API

Calls made before the script has loaded are queued, as long as you define the queue first:

```html
<script>
  window.PandaDesk = window.PandaDesk || function () { (window.PandaDesk.q = window.PandaDesk.q || []).push(arguments) };
</script>
```

| Call | What it does |
|---|---|
| `PandaDesk('open')` | Opens the chat. |
| `PandaDesk('close')` | Closes it. |
| `PandaDesk('toggle')` | Opens or closes it. |
| `PandaDesk('preload')` | Loads the chat now instead of on first open. |
| `PandaDesk('identify', identity)` | Attaches a signed-in user. See [Signed-in users](/docs/signed-identity). |
| `PandaDesk('reset')` | Forgets the visitor, for example on logout. The next chat starts fresh. |

`window.Pandachat` is kept as an alias for older snippets.

## Without the bubble

To build your own interface, the same chat runs over a small HTTP API: start a session with `POST /api/v1/widget/<key>/session`, send messages with `POST /api/v1/widget/<key>/messages` (with the session token as a Bearer token), and poll `GET /api/v1/widget/<key>/messages`. The **Install** page shows working `curl` examples with your key.

## With your coding agent

Ask your agent to "add the PandaDesk chat to this site". It uses:

- `allow_website` for each origin (`npx pandadesk allow_website --origin https://example.com`)
- `get_embed_code` for the snippet for your framework
- `check_install` with a page URL after you deploy, which reports a missing snippet, a wrong key or an origin that isn't allowed

See [Connect your AI agent](/docs/connect-ai-agent).
