For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.
Capturing custom data
We can instrument your app code to capture custom analytics.
An example demonstrates how to track page transitions within your app.
- On iOS, add the following code in the ViewController's viewDidLoad method.
NSArray *viewControllers = self.navigationController.viewControllers; NSUInteger numViewControllers = viewControllers.count; if (numViewControllers >= 2) { UIViewController *previous = [viewControllers objectAtIndex:(numViewControllers - 2)]; NSDictionary *metadata = @{@"fromPage": previous.title, @"toPage": self.title}; [[WLAnalytics sharedInstance] log:@"page transition" withMetadata:metadata]; }
On Android, add the following code in an Activity subclass onResume() method. String fromActivity = getIntent().getStringExtra("fromActivity"); JSONObject metadata = new JSONObject(); metadata.put("fromPage", fromActivity); metadata.put("toPage", "This Page"); WLAnalytics.log("page transition", metadata);
In JavaScript (Cordova), add the following code. // before showing the element identified by 'setting' $(document).on('pagebeforeshow', '#setting', function(e, obj) { WL.Analytics.log('page transition', { 'fromPage': obj.prevPage[0].id, 'toPage': obj.toPage[0].id }); });
For the web API, custom data is sent with the addEvent method. ibmmfpfanalytics.addEvent({'Purchases':'radio'}); ibmmfpfanalytics.addEvent({'src':'App landing page','target':'About page'});
Parent topic: Capturing analytics