# Widget events

Source: https://docs.revoplyai.com/widget/events/

> The events the website widget raises in your page, what each one carries, and how to listen for them.

The widget tells your page what happens in the chat, for your analytics or your own UI.
These are browser events on the visitor's page, not [webhooks](/webhooks/): they reach
only that page, and only while it is open.

```js
const off = RevoplyAI.on('first_message', () => {
  analytics.track('chat_started');
});

// later
off();
```

| Event                | When                                                  | Handler receives                       |
| -------------------- | ----------------------------------------------------- | -------------------------------------- |
| `open`               | The panel opens                                       | Nothing                                |
| `close`              | The panel closes                                      | Nothing                                |
| `first_message`      | The visitor sends the first message of a conversation | Nothing                                |
| `message_sent`       | The visitor sends a message                           | Nothing                                |
| `reply_received`     | Replies arrive in the panel                           | `{ count }`, the number of new replies |
| `handoff_requested`  | The visitor asks for a person                         | Nothing                                |
| `conversation_ended` | The visitor ends the conversation                     | Nothing                                |
| `feedback`           | The visitor rates an answer                           | `{ helpful }`, `true` or `false`       |
| `error`              | The panel hit an error                                | `{ message, … }`, for your logs        |

* Subscribe after `embed.js` has loaded; `on()` cannot be queued.
* A handler that throws is logged to the console and does not stop the others.
* New events may be added. Events you do not subscribe to cost nothing.

To act on conversations on your server (store them, open a ticket), use the
[`message.received`](/webhooks/events/message-received/) and
[`conversation.handover`](/webhooks/events/conversation-handover/) webhooks instead: they
are signed and do not depend on the visitor's browser.
