For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.
Initializing your app to capture app usage
App usage measures the number of times a specific app is brought to the foreground, and then sent to the background. To capture app usage in your mobile app, the MobileFirst Analytics client SDK must be configured to listen for the app lifecycle events.
We can use the MobileFirst Analytics API to capture app usage. Make sure you have first created a relevant device listener.
- On iOS, add the following code in your Application Delegate application:didFinishLaunchingWithOptions method.
WLAnalytics *analytics = [WLAnalytics sharedInstance]; [analytics addDeviceEventListener:LIFECYCLE];
Similarly, on Android, add the following code in your Application subclass onCreate method. WLAnalytics.init(this) WLAnalytics.addDeviceEventListener(DeviceEvent.LIFECYCLE);
For Cordova apps, the listener must be created in the native code. See Initilization for Android Cordova apps and Initialization for iOS Cordova apps. For Web apps, no listeners are required. Analytics can be enabled and disabled through the WLlogger class. logger.config({analyticsCapture: true});
Parent topic: App usage analytics