The events are automatically pushed to the data layer array.
Pass Events in JavaScript
Pass the events in the widgetOptions object to receive the events in JavaScript.
The widgetOptions object is the part of the installation script where you pass your apiKey and snippetId.
Example
<!-- Start of Glassix Chat Widget -->
<script>
var widgetOptions = {
apiKey: "your-api-key",
snippetId: "your-snipppet-id",
events: {
'initialized': ()=> console.log("Widget initialized."),
'attached': ()=> console.log("Widget attached"),
'destroyed': ()=> console.log("Widget destroyed."),
'visiblity': (isVisible)=> console.log(isVisible ? "Widget is visible" : "Widget is hidden"),
'newTicket': (nextTicketId)=> console.log("new ticket created"),
'newMessage': ()=> console.log("New message."),
'protocolBadgeClicked': (protocolType, departmentIdentifier) => console.log("Channel clicked. protocolType: " + protocolType + " departmentIdentifier: " + departmentIdentifier)
}};
(function(n){var u=function(){GlassixWidgetClient&&typeof GlassixWidgetClient=="function"?(window.widgetClient=new GlassixWidgetClient(n),widgetClient.attach(),window.glassixWidgetScriptLoaded&&window.glassixWidgetScriptLoaded()):f()},f=function(){r.src="https://cdn.glassix.net/clients/widget.1.2.min.js";r.onload=u;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-widget-script",r=t.cloneNode(),t.onload=u,t.src="https://cdn.glassix.com/clients/widget.1.2.min.js",!document.getElementById(t.id)&&document.body)&&(i.parentNode.insertBefore(t,i),t.onerror=f)})(widgetOptions)
</script>
<!-- End of Glassix Chat Widget -->
Event Types
initialized
The widget has been initialized.
attached
The widget has been loaded into the DOM. This is the first event to fire.
destroyed
The widget instance has been removed from both the memory and the DOM.
visiblity
Fired when the chat box becomes visible (true) or hidden (false).
The isVisiblity parameter is passed. Its values are true/false.
newTicket
Fired when a new ticket was created.
The nextTicketId parameter is passed with the ticket Id.
Note:
If you want more information on the ticket you can see it using the API get endpoint.
newMessage
Fired when a message (inbound and outbound-only by human agents) is sent.
protocolBadgeClicked
Fired when a badge is clicked. For example a WhatsApp badge.
The (protocolType, departmentIdentifier) parameters are passed.
The value of protocolType is one of the protocols here.
The value of departmentIdentifier is the means of communication for the department.
Example
If the customer clicked on the WhatsApp badge:
protocolType = WhatsApp
departmentIdentifier = department's WhatsApp phone number