CTLive integration through events
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” |
DatacollectionSubmitted | The data collection phase is completed |
|
“Chat” “CallbackNow” “CallbackLater” “ClickToCall” |
SurveyStarted | The survey phase is started |
|
|
SurveySubmitted | The survey phase is completed |
|
|
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;
case "DatacollectionStarted":
console.log("[POSTMESSAGE] Received DatacollectionStarted event", event.data.object);
// do some stuff...
break;
case "DatacollectionSubmitted":
console.log("[POSTMESSAGE] Received DatacollectionSubmitted event", event.data.object);
// do some stuff...
break;
case "SurveyStarted":
console.log("[POSTMESSAGE] Received SurveyStarted event", event.data.object);
// do some stuff...
break;
case "SurveySubmitted":
console.log("[POSTMESSAGE] Received SurveySubmitted event", event.data.object);
// do some stuff...
break;
}
}
}
}