Listen to Events
React to Beacon widget lifecycle events in your app.
Use Beacon.on() to subscribe to widget events and trigger actions in your own code.
Available events
| Event | Fired when |
|---|---|
open | Widget panel is opened |
close | Widget panel is closed |
message:received | A new message arrives from an agent or Rian |
conversation:started | The visitor sends their first message |
handoff | Rian escalates to a human agent |
Subscribe
Beacon.on('open', () => {
console.log('Widget opened');
});
Beacon.on('close', () => {
console.log('Widget closed');
});
Beacon.on('message:received', (message) => {
console.log('New message:', message.content);
});
Beacon.on('handoff', () => {
console.log('Escalated to human agent');
});
Example: track widget opens in analytics
Beacon.on('open', () => {
analytics.track('Support Widget Opened');
});
Example: show a notification badge
let unread = 0;
Beacon.on('message:received', () => {
unread++;
document.title = `(${unread}) Your App`;
});
Beacon.on('open', () => {
unread = 0;
document.title = 'Your App';
});