About this task
The
MobileFirst Analytics API
allows for the capturing of the following metrics.
- App lifecycle events - app usage rates, usage duration, app crash
rates
- Network usage - breakdown of API call frequencies, network performance
metrics
- Users - users of the app that are identified by a supplied user
ID
- Custom analytics - custom key/value pairs that are defined by
the app developer
The initialization of the analytics
API must be written in native code, even in Cordova apps.
- To capture app usage, you must register app lifecycle event listeners
before the event to which you are listening occurs.
- To use the file system or native language and device features,
the API must be initialized. If the API is used in a way that requires
native device features (like the file system), but was not initialized,
the API call fails. This behavior is especially
true on Android.
Note: No listeners are required for the web apps.
To
initialize the MobileFirst Analytics SDK
and enable the capture of lifecycle and network analytic data:
- On iOS, add the following code in your Application Delegate application:didFinishLaunchingWithOptions method.
WLAnalytics *analytics = [WLAnalytics sharedInstance];
[analytics addDeviceEventListener:NETWORK];
[analytics addDeviceEventListener:LIFECYCLE];
- Similarly, on Android, add the following
code in your Application subclass onCreate method.
WLAnalytics.init(this);
WLAnalytics.addDeviceEventListener(DeviceEvent.NETWORK);
WLAnalytics.addDeviceEventListener(DeviceEvent.LIFECYCLE);
- For Cordova apps, the listener must be created
in the native code. See MobileFirst Cordova
plug-in initialization for analytics and MobileFirst Cordova
plug-in initialization of analytics.
- For web apps, no listeners
are required. Analytics can be enabled and disabled through the ibmmfpfanalytics.logger class.
ibmmfpfanalytics.logger.config({analyticsCapture: true});