WL.Analytics
The IBM® Worklight® Analytics API provides the ability to enable, disable, and log analytics data.
The default settings is enabled, meaning data passed to the WL.Analytics.log API call by both the framework code and your code are
persisted. You can explicitly enable or disable persistent data capture by calling WL.Analytics.enable
or WL.Analytics.disable
.
Starting in IBM® Worklight® V6.2.0, the enabling of Analytics capture by declaring it in initOptions.js
is deprecated. For backward
compatibility, when Analytics is enabled using initOptions.js
, the event WL/ANALYTICS/READY
is triggered. It is no longer necessary to wait for this event in order to use the WL.Analytics
API.
Starting with IBM® Worklight® V6.2.0, the WL.Analytics
API is available for use with no extra configuration or feature enablement required.
Persistent collection of WL.Analytics.log
data is enabled by default, and sent to the IBM® Worklight® server by default on
successful network init.
Note: the data collected via the WL.Analytics
API, after sending it to the IBM Worklight server, is made available in the Operational
Analytics engine console on the "Search" tab, and only the "Search" tab.
Method Attributes | Method Name and Description |
---|---|
disable()
Turns off the capture of analytics data. |
|
enable()
Turns on the capture of analytics data. |
|
log(message, name)
Logs a message with additional contextual information. |
|
restart()
|
|
send()
Send any analytics data collected up to this point to the IBM Worklight server.
|
|
state()
Get the current state of |
Turns off the capture of analytics data.
WL.Analytics.disable()
.then(function () {
//Capture of analytics data is fully disabled.
})
.fail(function (errObj) {
//errObj.src = function that failed
//errObj.res = error message
});
Turns on the capture of analytics data.
The Promise
returned by enable must be resolved prior to any WL.Analytics
API call.
Starting with IBM® Worklight® V6.2.0, WL.Analytics.enable
no longer takes any parameter arguments and it
is no longer necessary to wait for the returned Promise
to be resolved to continue using the
WL.Analytics
API.
WL.Analytics.enable()
.then(function () {
//Capture of analytics data is fully enabled.
})
.fail(function (errObj) {
//errObj.src = function that failed
//errObj.res = error message
});
Logs a message with additional contextual information.
Log messages are automatically added to a persistent queue. The accumulated data is automatically sent
to IBM® Worklight® server on the next successful network init or explicit WL.Analytics.send
function call.
WL.Analytics.log('my record');
// or
WL.Analytics.log({data: [1,2,3]});
// or
WL.Analytics.log({data: [1,2,3]}, 'MyData');
WL.Analytics.restart()
.then(function () {
//nop
})
.fail(function (errObj) {
//errObj.src = function that failed
//errObj.res = error message
});
Get the current state of WL.Analytics
.
The state object is kept by WL.Analytics
and contains the following key:
Changing the state object that is returned does not affect the state object that is kept internally.
WL.Analytics.state() .then(function (state) { // {enabled: true} }) .fail(function (errObj) { //errObj.src = function that failed //errObj.res = error message });