Logging events

You can log any event in your application using the Android SDK’s logEvent method. As an example, you may want to log an event named “clickButton” when a user clicks on a button in your application:

EventAPI.logEvent("clickButton", null);

Note that before logging any events, your application must call the EventAPI.configure and EventAPI.openSession methods. See Adding the SDK for more information.

Events with key-value pairs

You can include additional event properties as key-value pairs when you log events using the EventAPI.logEvent method. On the “clickButton” event, you may want to log the button name as a key-value pair (e.g., buttonName = “Done”):

EventAPI.logEvent("clickButton", Collections.singletonMap("buttonName", "Done"));

Events with content category

If your application displays content such as news articles, editorials, or reviews, then you may wish to log the category of the content that is related to an event. Logging a content category with your events allows you to see reports on how your users engage with different kinds of content in your application. For example, you can log a content category of “Sports” with a “viewArticle” event when a user reads a sports article by calling the EventAPI.logEvent method and specifying the EventAPI.CATEGORY constant as the key name:

EventAPI.logEvent("viewArticle", Collections.singletonMap(EventAPI.CATEGORY, "Sports"));

Events with application feature

If your application contains a number of distinct features, then you may wish to log the feature that is related to each event. Logging a feature with your events allows you to see reports on how your users engage with different features in your application. For example, if you have an application that allows users to search for nearby restaurants on a map, you can log the feature “Maps” with events related to that feature by calling the EventAPI.logEvent method and specifying the EventAPI.FEATURE constant as the key name:

EventAPI.logEvent("search", Collections.singletonMap(EventAPI.FEATURE, "Maps"));

Similarly, if your application allows users to post restaurant reviews, then you can log the feature “Reviews” with events related to that feature:

EventAPI.logEvent("postReview", Collections.singletonMap(EventAPI.FEATURE, "Reviews"));