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

# Events

> Browser events dispatched by the homie embed.

The embed dispatches `CustomEvent`s on `window` so you can react to lifecycle and interaction without polling. Each event carries `{ chatbotId }` in `event.detail`. For almost all integrations, these events plus the [methods](/en/api-reference/client/methods) are all you need.

## Browser events

| Event                      | When it fires                                             | `event.detail`  |
| -------------------------- | --------------------------------------------------------- | --------------- |
| `homiebot:api-ready`       | `window.homieBot` is available                            | `{ chatbotId }` |
| `homiebot:assistant-ready` | The chat iframe is ready for `sendMessage` / `getHistory` | `{ chatbotId }` |
| `homiebot:opened`          | The chat widget was opened                                | `{ chatbotId }` |
| `homiebot:closed`          | The chat widget was closed                                | `{ chatbotId }` |

<Note>
  `homiebot:opened` and `homiebot:closed` fire for every open/close action — the launcher button, welcome bubbles,
  `window.homieBot.open()` / `.close()` / `.toggle()`, and actions triggered from inside the chat.
</Note>

### Listen for the API

Fired once `window.homieBot` is usable.

```js theme={null}
window.addEventListener('homiebot:api-ready', (e) => {
  const { chatbotId } = e.detail;
  console.log('homie API ready', chatbotId);
  window.homieBot.open();
});
```

### Listen for the assistant

Fired once the iframe is ready for `sendMessage` and `getHistory`.

```js theme={null}
window.addEventListener('homiebot:assistant-ready', () => {
  window.homieBot.sendMessage({ text: 'Hello', newChat: false });
});
```

### Track open and close

Useful for forwarding interactions to analytics.

```js theme={null}
window.addEventListener('homiebot:opened', (e) => {
  window.dataLayer?.push({ event: 'homie_chat_opened', chatbotId: e.detail.chatbotId });
});

window.addEventListener('homiebot:closed', (e) => {
  window.dataLayer?.push({ event: 'homie_chat_closed', chatbotId: e.detail.chatbotId });
});
```
