Class ibmmfpfanalytics

ibmmfpfanalytics

Description:

The IBM® MobileFirst® web analytics client API provides the ability to enable, disable and log custom events, and to send them to the MobileFirst server.

The data collected via this API is then available in the IBM MobileFirst Analytics Console (Apps -> Client Log Search).

The user calls the send method in order to deliver the analytics to the server. In case of an unhandled JavaScript error, analytics data is sent automatically.

ibmmfpfanalytics is implemented as UMD JavaScript module. This means it can be consumed as a separate AMD module with require.js, or used under the global context.

Example:
Usage as AMD module, with 'define':

define([
'ibmmfpfanalytics'
], function(ibmmfpfanalytics){
ibmmfpfanalytics.send();  
}
);
Usage with global context:



Property Summary
Field Attributes Field Name and Description
 
IBM® MobileFirst® logger object that facilitates logging to the IBM MobileFirst server at all levels.
Method Summary
Method Attributes Method Name and Description
 
addEvent(event)
Submits custom event data (JSON object), events later can be processed and reported.
 
enable(flag)

Sets the enablement flag for data collection.

 
enableAutoSend(autoSend)
Enable/Disable the Auto Send Logs feature.
 
init(deviceID, appName, contextRoot)

Initializes the ibmmfpfanalytics.

 
send()
Send all analytics data collected up to this point to the IBM MobileFirst server.
 
setUserContext(usedId)
Specify current application user.
 
state()
Gets the current state of the ibmmfpfanalytics instance.
Property Detail
logger
<static> {ibmmfpfanalytics.logger} ibmmfpfanalytics.logger
IBM® MobileFirst® logger object that facilitates logging to the IBM MobileFirst server at all levels.
Method Detail
addEvent
addEvent(event)
Submits custom event data (JSON object), events later can be processed and reported.
Parameters:
{object} event - The event.
Example:
ibmmfpfanalytics.addEvent({'Purchases':'radio'});
ibmmfpfanalytics.addEvent({'src':'App landing page','target':'About page'});

enable
enable(flag)

Sets the enablement flag for data collection.

Parameters:
{boolean} flag - enable or disable analytics collection (if enabled data is being collected and sent by send() call).
Example:
ibmmfpfanalytics.enable(true);

enableAutoSend
enableAutoSend(autoSend)
Enable/Disable the Auto Send Logs feature. If enabled the logs will be sent automatically after each successful resource request, if no logging has occurred for 60 seconds.
Parameters:
{boolean} autoSend
Example:
enableAutoSend(true);

init
init(deviceID, appName, contextRoot)

Initializes the ibmmfpfanalytics.

Parameters:
{String} deviceID - The deviceId.
{String} appName - The Application name.
{String} contextRoot - The context root (default is mfp).
Example:
ibmmfpfanalytics.init('device-uuid-12345', 'application1', 'mfp');

send
{Promise} send()
Send all analytics data collected up to this point to the IBM MobileFirst server.
Returns:
{Promise} Resolved with success status, rejected with an error message.
Example:
ibmmfpfanalytics.send()
.then(function (response) {
	console.log(response);
})
.catch(function (error) {
	console.log(error);
 });

setUserContext
setUserContext(usedId)
Specify current application user. If you want user-based analytics, you must use this method call. Use it when the user logs in. There is no unsetUserContext method. The user session ends after 30 minutes of inactivity, unless another call is made to setUserContext(used). If your application supports user profiles, call this method when the user profile changes.
Parameters:
{String} usedId - User id for current app user.
Example:
ibmmfpfanalytics.setUserContext();

state
state()
Gets the current state of the ibmmfpfanalytics instance.
Returns:
the current state of ibmmfpfanalytics.
Example:
ibmmfpfanalytics.state();

© Copyright IBM Corp. 2011, 2016.