Using Arbitrary Events in your Android app to do Analytics with Kii

If you read our previous blog post about Kii Analytics on Android you got a taste of how powerful and flexible it can be to analyze back-end data. In this post I’m going to show you an extra capability in Kii Analytics where you can trigger arbitrary events from your app with specific data that can be included in the analysis. I will use Android as the underlying platform but the steps for iOS are very similar.


To give you an example one common scenario for this functionality is sending user segmentation data to the back-end upon app installation (country, age, gender, etc) so you can later slice and dice it in our developer portal to get insight on your user base.

Let’s take a look at the basic steps to get this up and running:

  1. Install Kii Analytics in your app
  2. Define your metrics on the developer portal.
  3. Send Event Data from your app.
  4. Check analytics results on the developer portal and/or
  5. Fetch analytics results using the SDK.

Let’s go straight to step 2 (follow the link above for more details on step 1). First of all you have to tell Kii Analytics what type of events you will be catching (type) and what’s the event data structure (fields such as age, gender, country, etc which will translate to dimensions of analysis). And most importantly you need to define what kind of aggregation function you want to use for the data (for example you might want to know the average age of your users grouped by country). This is all done from the developer portal and explained in detail here.

Once your metrics are all set you can instruct your application to send event data that matches the structure you’ve defined in the portal. The Android code will look like this (suppose we call this upon app installation and that you have a way to find out the associated event data for each user):

// Creates a KiiEvent instance

KiiEvent event = KiiAnalytics.event("MyUser");

// Set key-value pairs
event.set("gender", "M");
event.set("city", "San Francisco");
event.set("location", "US");
event.set("children", 2);
event.set("age", 35);

// Upload Event Data to Kii Cloud
} catch (IOException e) {
    // Please check IOException to see what went wrong 

Now your app is sending events to Kii Analytics. The event data is being stored on the back-end and will be ready for you to slice and dice (e.g. visualization on multiple dimensions). If you want more details on how to navigate the aggregated data on the portal please check this page. Please be aware that data is not aggregated instantaneously and that it’s recommend to wait a least 24 hs to go and visualize the information on the portal.

But this is not all, suppose you want your app to be aware of processed data coming from the analysis. No problem, Kii Analytics allows you to fetch results of your analytics (it’s not limited to visualization) and make it available to your app. Imagine the nice features that you can add to your app with this functionality (e.g. enable gamification functionality in your app when the average age of your user drops below a certain point). In case you’re curious this is how the Android code would look like:

/ Defines filters
Filter filter = new Filter();
filter.addFilter("location", "UK");

// Defines data range
SimpleDate start = new SimpleDate(2012, 10, 01);
SimpleDate end = new SimpleDate(2012, 10, 10);
DateRange dateRange = new DateRange(start, end);

// Builds a query (while setting a dimension as "gender")
ResultQuery query = ResultQuery.builderWithGroupingKey("gender")

try {
  // Gets the snapshots
  GroupedResult result = KiiAnalytics.getResult("_Aggregation_Rule_ID_", query);
  // Check the snapshots
  List snapshots = result.getSnapShots();
} catch (KiiAnalyticsException) {
  //  Please check KiiAnalyticsException to see what went wrong

You basically define a filter in the beginning to just get a subset of your event data (this would be equal to visualizing only people in the UK if you would be using the developer portal). Then, and most importantly, you define a data range for the events (you might be interested in analyzing a specific month, year or whatever time frame you prefer). In order to get specific results from the analytics data you then define a query to extract the information that is relevant to you at that point using grouping criteria, your filter and the date range. Note that in order to get the result the Aggregation_Rule_ID must match the rule you defined on the portal (each rule get a unique id).

Analytics based on arbitrary events are a powerful feature that you might fin handy because you can define the structure of the events and even check the analytics results from the app itself. Hope you find this useful, let us know if you’re using it and how, we would love to hear about ways in which Kii analytics helps our users.

On my next blog post I’m going to show you how to use the Kii Cloud SDK on Android in the context of a game backed (e.g. maintaining leaderboards, storing game data on the cloud and more). Indie gamers please stay tuned!! 🙂


- Share -


More posts from

  • Kii IoT platform enables customers to create smart, connected solutions and services
  • Long track record of supporting customers like Docomo, Toshiba, Kyocera and many others
  • Strong ecosystem partners across the globe, consisting of carriers, device/sensor manufacturers, system integrators, network/infrastructure providers, chip vendors and solution developers
  • HQ in Tokyo, US HQ in Silicon Valley & offices in China, Taiwan, Hong Kong and Europe (UK, Spain, Germany)