The integration through CTLive events allows to integrate the library functions with custom code via JavaScript code. The integration takes place by listening in the main webpage document of the PostMessage events that are launched on specific actions.
Events
Event | Description | Notes | Data sent in object property |
---|---|---|---|
Loaded | Notifies that the library has been loaded and the configuration has been read |
| |
WidgetShown | The widget is shown | If the page is configured to show more than one widget an event is raised for each widget |
|
WidgetHidden | The widget is hidden |
| |
WidgetClicked | The widget has been clicked/activated |
“Chat” “CallbackNow” “CallbackLater” “ClickToCall” | |
ChatStarted | A chat request starts |
| |
ChatOnline | The chat is active |
| |
ChatFinished | The chat is ended |
| |
DatacollectionStarted | The data collection phase is started |
“Chat” “CallbackNow” “CallbackLater” “ClickToCall” |
Message Structure
Type: JSON
{ name: "CTLiveEvent", type: <event type> object: <event specific data type> }
Example
if (window.addEventListener) { addEventListener("message", messageListener, false); } else { attachEvent("onmessage", messageListener); } function messageListener (event) { if ( typeof event !== "undefined" ) { if ( event !== null ) { if (event.target.location.origin !== document.location.origin) { //Message not for me return; } if (event.data.name !== "CTLiveEvent") { return; } switch(event.data.type) { case "Loaded": console.log("[POSTMESSAGE] Received Loaded event", event.data.object); // do some stuff... break; case "WidgetShown": console.log("[POSTMESSAGE] Received WidgetShown event", event.data.object); // do some stuff... break; case "WidgetHidden": console.log("[POSTMESSAGE] Received WidgetHidden event", event.data.object); // do some stuff... break; case "WidgetClicked": console.log("[POSTMESSAGE] Received WidgetClicked event", event.data.object); // do some stuff... break; case "ChatStarted": console.log("[POSTMESSAGE] Received ChatStarted event", event.data.object); // do some stuff... break; case "ChatOnline": console.log("[POSTMESSAGE] Received ChatOnline event", event.data.object); // do some stuff... break; case "ChatFinished": console.log("[POSTMESSAGE] Received ChatFinished event", event.data.object); // do some stuff... break; } } } }