This article outlines how to use JavaScript to listen for Live Assist events on websites. These events can be used to pass chat and engagement data into other systems such as analytics tools.
Prerequisites
If you want to send Live Assist events to your Google Analytics dashboard you need to do the following:
- You are using the embedded chat window. These events will not work with the pop out chat window.
- Your Google Analytics tracking code is loaded on the page *before* the Live Assist monitor tag. As long as the Live Assist Monitor tag is below your Google Analytics tracking code you should not have a problem.
Options to Listen for Events
To listen to an event you can either:
- Call lpTag.events.bind method with the appName, eventName and your callback function. Code sample: lpTag.events.bind(appName, eventName, callbackFunction);
- Call lpTag.events.bind method with an object configuration. This option includes more options.
Example:
lpTag.events.bind({
eventName : "EVENTNAME",
appName : "APPNAME",
func: callbackFunction,
context: callbackFunctionExecutionContext,
async: true, //default is false,
triggerOnce : true //default is false
});
Function Properties
Name |
Description |
Type |
Required |
Notes |
---|---|---|---|---|
eventName |
The name of the event. |
string |
Required |
You can use "*" to see all events. |
appName |
The name of the app that creates the event. If you do not know the name of the app, you can leave the default value to receive events from all apps. |
string |
Optional |
Default: "*". |
func |
The callback function when the event is triggered. |
Function |
Required |
|
context |
The object which is the execution context of the function. Useful if you rely on context ("this") in your code. |
Object |
Optional |
Default: null. |
async |
When set to yes, the callback will be triggered when there is free CPU time. This option is recommended when there is heavy procession to run, in order to avoid freezing the UI. |
Boolean |
Optional |
Default: false. |
triggerOnce |
When set to yes, your callback will unbind after it is called once. |
Boolean |
Required |
Default: false. |
Event Information structure
{
eventName: "MYEVENT",
appName: "TRIGGERINGAPP"
}
Callback Function example
The example below prints the event data and event info:
function processThis(data, eventInfo) {
if(window.console && window.JSON){
console.log(JSON.stringify(data) + " triggered by: " + JSON.stringify(eventInfo));
}
}
Google Analytics Code Sample
With the below code, every time a visitor accepts a Live Assist engagement you can send that event data to Google Analytics.
Place this event binding code in your source code beneath:
- The LA monitor tag
- The Google Analytics code.
<script>
lpTag.events.bind("LP_OFFERS", "OFFER_CLICK", function(eventData,eventInfo){
// Log data to console for debugging
if(window.console && window.JSON){
console.log("Campaign ID: " + JSON.stringify(eventData.campaignId) + "\tEngagement ID: " + JSON.stringify(eventData.engagementId) + "\ntriggered by: " + JSON.stringify(eventInfo));
}
// Send data to GA
ga('send', 'event', 'OFFER_CLICK', 'LP_OFFERS', eventData.engagementId);
}); </script>
Omniture sample
Below is a similar example using some Omniture events.
<script>
lpTag.events.bind("LP_OFFERS", "OFFER_CLICK", function(eventData,eventInfo){
// Log data to console for debugging
if(window.console && window.JSON)
{
console.log("Campaign ID: " + JSON.stringify(eventData.campaignId) + "\tEngagement ID: " + JSON.stringify(eventData.engagementId) + "\ntriggered by: " + JSON.stringify(eventInfo));
}
// Send data to Omniture
s.eVar27 = s.pageName; alertOmniture(eventData,'Chat Initiated','events,eVar27','event20');
}); </script>