Reference for the JavaScript events emitted by the Glassix agent widget
This page documents the events emitted by the Glassix agent widget, covering how they are automatically pushed to the Google Analytics data layer and how to listen for them in JavaScript to trigger custom logic on your site.
Overview
All Glassix widget events are automatically pushed to the data layer array. If you have Google Analytics set up on your site, these events are automatically sent to it, no additional configuration required. Inside Google Analytics, you can use these events to build triggers, set up conversion tracking, and create reports based on how agents interact with your widget.
For more on how the data layer works and how events map to Google Analytics, see Google's data layer documentation.
In addition to analytics, each event can also trigger JavaScript on your page. You can use events to trigger actions on your site when the widget fires them, for example, updating your UI when an agent switches tickets, or running logic when the widget is hidden. To call methods directly on the widget client, see Methods.
| Event | Fired when | Parameters |
|---|---|---|
ticketFocused | Focus moves from one ticket to another. | nextTicketId |
destroyed | The widget instance is removed from the memory and the DOM. | — |
visibility | The widget becomes visible or hidden. | isVisible |
Pass Events in JavaScript
To receive events in JavaScript, pass an events object inside widgetOptions. The widgetOptions object is the same one where you pass your departments, userName, and snippetId. For instructions on adding the events object to your installation script, see Installation.
Example
<!-- Start of Glassix Agent Widget -->
<script>
var widgetOptions = {
departments: ["your-department-id"],
userName: "your-user-name",
snippetId: "your-snippet-id",
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")
}
};
(function(n){var u=function(){GlassixAgentClient&&typeof GlassixAgentClient=="function"?(window.agentClient=new GlassixAgentClient(n),agentClient.attach()):f()},f=function(){r.onload=u;r.src="https://cdn.glassix.net/clients/agent.1.3.min.js";document.body&&document.body.removeChild(t);i.parentNode.insertBefore(r,i)},i=document.getElementsByTagName("script")[0],t=document.createElement("script"),r;(t.async=!0,t.type="text/javascript",t.crossorigin="anonymous",t.id="glassix-agent-widget-script",r=t.cloneNode(),t.onload=u,t.src="https://cdn.glassix.com/clients/agent.1.3.min.js",!document.getElementById(t.id)&&document.body)&&(i.parentNode.insertBefore(t,i),t.onerror=f)})(widgetOptions)
</script>
<!-- End of Glassix Agent Widget -->Event Types
ticketFocused
Fired when the focus changes from one ticket to another, for example, when an agent clicks into a different conversation, or when setCurrentTicket is called programmatically. The nextTicketId parameter is passed with the ID of the newly focused ticket.
ticketFocused
| Parameter | Description |
|---|---|
nextTicketId | The ID of the newly focused ticket. |
To retrieve full details about the ticket, use the API get ticket endpoint.
destroyed
Fired when the widget instance has been removed from both the memory and the DOM, for example, after a destroy() call.
destroyed
visibility
Fired when the widget becomes visible or hidden. The isVisible parameter is passed with a value of true (visible) or false (hidden).
visiblity
| Parameter | Description |
|---|---|
isVisible | true when the widget is visible, false when hidden. |