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

# Install with code

> Add the chat with one script tag

One script tag adds the chat to a page. It loads after your page, shows the chat button, and puts `DeskHoot` on `window` for your own code.

```html Your install code theme={null}
<script
  async
  src="https://widget.deskhoot.com/widget/v1.js"
  data-project="YOUR_PROJECT_ID"
></script>
```

Paste it before `</body>` on every page.

## Attributes

**src** `string` *required*

The address of DeskHoot's script: `https://widget.deskhoot.com/widget/v1.js`.

**data-project** `string` *required*

Your public project ID, shown on your [**Install**](https://app.deskhoot.com/app/channels?tab=widgets\&page=install) page. It only works on the websites you allow, so it is safe to publish.

**data-inbox** `string`

The Install ID of the widget to show, such as `billing`. Leave it out to show your default widget.

**data-client** `string` (default: default)

A name for this chat, for pages that load more than one. The chat named `default` is `window.DeskHoot`; reach any other with `DeskHootClients.get(name)`.

## React and single-page apps

Add the script once, in your root component. The chat stays in place as your routes change.

```jsx App.jsx theme={null}
import { useEffect } from "react";

useEffect(() => {
  const script = document.createElement("script");
  script.src = "https://widget.deskhoot.com/widget/v1.js";
  script.async = true;
  script.dataset.project = "YOUR_PROJECT_ID";
  document.body.appendChild(script);
}, []);
```

## Call DeskHoot before it loads

The script is `async`, so `DeskHoot` may not exist yet when your code runs. Make it a queue first: each entry is a method name followed by its arguments. DeskHoot runs the queued calls, up to 100, in order as soon as it loads.

```html theme={null}
<script>
  window.DeskHoot = window.DeskHoot || [];
  DeskHoot.push(["open"]);
  DeskHoot.push(["setTheme", "dark"]);
</script>
```

## Allowed websites

The chat only works on websites you allow, so nobody can put your chat on their own site. On any other website the button shows in a plain default look, and opening it says "Chat is unavailable." Add each address under [**Install**](https://app.deskhoot.com/app/channels?tab=widgets\&page=install), in **Allow your websites**.

* An address is the scheme and host, such as `https://www.example.com`. `https://example.com` is a different website.
* Public websites must use `https://`.
* `http://` is accepted only for `localhost` and `127.0.0.1`, such as `http://localhost:3000`. LAN addresses are refused.
* A different port is a different website. Paths are ignored, and there are no wildcards.
* A widget allows up to 20 websites.

## What it loads

| When | What |
| - | - |
| On page load | The script, its stylesheet, and one request for your button's look. |
| When the chat first opens | The chat itself, in an iframe. |
| On page load, for returning visitors | The chat too, so unread replies show on the button. |

The script stores one flag in your site's `localStorage`, to remember that the visitor has chatted. Everything else, including the session cookie, is stored on DeskHoot's own address. Having the script on a page twice still gives one chat.

## Content Security Policy

If your website sends a Content Security Policy, allow DeskHoot in these four directives. No `unsafe-inline` and no `img-src` entry are needed.

```text theme={null}
script-src  https://widget.deskhoot.com;
style-src   https://widget.deskhoot.com;
connect-src https://widget.deskhoot.com;
frame-src   https://widget.deskhoot.com;
```

## A second widget

Every widget has its own code on its **Install** page. A widget that is not your default one carries its Install ID in `data-inbox`. An ID that matches no widget does not fall back to your default: the chat says "This support widget is unavailable."

To show two widgets on one page, give each script its own `data-client` name.

```html theme={null}
<script
  async
  src="https://widget.deskhoot.com/widget/v1.js"
  data-project="YOUR_PROJECT_ID"
  data-inbox="billing"
></script>
```

## Related

> [card] [Open and close](https://docs.deskhoot.com/sdk/control.md)
>
> Control the chat from your own code.

> [card] [Verify users](https://docs.deskhoot.com/sdk/identify.md)
>
> Show signed-in customers to your team.

> [card] [Events](https://docs.deskhoot.com/sdk/events.md)
>
> Run your code when something happens.

> [card] [Methods](https://docs.deskhoot.com/sdk/methods.md)
>
> What `DeskHoot` can do.


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