Pass the events in the options object.
The events are automatically pushed to the data layer array.

Fired when the focus changes from one ticket to another.

The widget instance has been removed from both the memory and the DOM.

Fired when the chat box becomes visible or hidden.

var widgetOptions = {
    events: {
        'ticketFocused': (nextTicketId) => console.log("Next focused ticket: " + nextTicketId),
        'destroyed': () => console.log("Widget destroyed."),
        'visiblity': (isVisible) => console.log(isVisible ? "Widget is visible" : "Widget is hidden")