Analytics module lets you automatically track session, device properties and pages when you start the SDK and you can use API to track your custom events. Follow the Getting Started section if you haven’t setup and started the SDK in your application yet.
Track Session, Device Properties: Once the Analytics module is included in your app and the SDK is started, it will automatically track sessions, device properties like OS Version, model, manufacturer etc. and you don’t need to add any additional code. Look at the information on how to Start the SDK if you haven’t started it yet.
Custom Events: You can track your own custom events with up to five properties to know what’s happening in your app, understand user actions, and see the aggregates in the Mobile Center portal. For more information about custom events in Mobile Center, go to Events Metrics. Once you have started the SDK, use the
trackEvent()method to track your events with properties. You can send up to 200 distinct events. Also, note that there is a maximum of 256 characters supported per event name and 64 characters per event property name and event property value.
Map<String,String>properties=new HashMap<String,String>(); properties.put("Category", "Music"); properties.put("FileName", "favorite.avi"); Analytics.trackEvent("Video clicked", properties);
Of course, properties for events are entirely optional – if you just want to track an event, use this sample instead:
Enable or disable Analytics: You can change the enabled state of the Analytics module at runtime by calling the
Analytics.setEnabled()method. If you disable it, the SDK will not collect any more analytics information for the app. To re-enable it, pass
trueas a parameter in the same method.
You can also check, if the module is enabled or not using the