This code sample shows how to perform an action when a specific event occurs. There are four system-generated events that require you to poll the servers to see if they have occurred. These events are call-started, call-ended, chat-started, and chat-ended. These events relate to Live Help Call and Chat functionality. If you are not monitoring for these events then you should not use polling, and it is highly recommended that you use this method which does not allow any polling.

There are a number of points to note when looking at this sample:

(function() {

var trackHistoricalRuleRan = true;

var ruleIdToObj = function(id) {

return id && ATGSvcs.rules.rulehash[id];

}

var eeHandlers = {

eeRuleRan: function(data) {

console.log('Analytics Tracking - Rule Run: ' + data.name);

},

eeOffered: function(data) {

if (data.rule) {

console.log('Analytics Tracking - Invite Offered: ' + (data.rule.name || 'unknown'));

}

},

eeAccepted: function(data) {

if (data.rule) {

console.log('Analytics Tracking - Invite Clicked: ' + (data.rule.name || 'unknown'));

}

},

eeDeclined: function(data) {

if (data.rule) {

console.log('Analytics Tracking - Invite Declined: ' + (data.rule.name || 'unknown'));

}

},

var historicalLog = ATGSvcs.rules.eventLog.slice();

if (trackHistoricalRuleRan) {

historicalLog = historicalLog.concat(ATGSvcs.rules.ruleLog);

historicalLog.sort(function(a, b) { return (a['ts'] - b['ts']); });

}

for (var i=0; i < historicalLog.length; i++) {

var logEntry = historicalLog[i];

if (logEntry.event) {

var handler = eeHandlers[logEntry.event.replace('-', '')];

if (handler) { handler(logEntry.data); }

} else if (trackHistoricalRuleRan && logEntry.id) {

var rule = ruleIdToObj(logEntry.id);

if (rule) {

var handler = eeHandlers['eeRuleRan'];

if (handler) { handler(rule); }

}

}

}

ATGSvcs.eventSubscribe ({

'eeRuleRan': function(e, data) {eeHandlers.eeRuleRan(data); },

'eeOffered': function(e, data) { eeHandlers.eeOffered(data); },

'eeAccepted': function(e, data) { eeHandlers.eeAccepted(data); },

'eeDeclined': function(e, data) { eeHandlers.eeDeclined(data); },

});

console.log('End: Rules / Events from Logs');

})();


Copyright © 1997, 2014 Oracle and/or its affiliates. All rights reserved. Legal Notices