For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.
Capturing analytics
We can initialize the MobileFirst Analytics SDK and enable the capture of lifecycle and network analytic data.
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, we 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});
- Tracking users
To track individual users, use the setUserContext and unsetUserContext methods.- Capturing custom data
We can instrument your app code to capture custom analytics.
Parent topic: Analytics SDK