Getting Analysis Results with the API

We can extract the analysis results via the Android SDK by specifying the following information:

  • Dimension/Grouping Key (which field?). If omitted, the default view will be used.
  • Filters (if any). When multiple filters are defined, they will be concatenated using "AND".
  • Date range.

Please specify the target rule with its rule ID. The rule ID is shown on the developer portal. For setting dimensions and filters, please use the value(s) set as "Name" when you define your Aggregation Rule.

Here is the sample code for getting the analysis result.

  • // Define a filter.
    Filter filter = new Filter();
    filter.addFilter("location", "UK");
    
    // Define a data range.
    SimpleDate start = new SimpleDate(2012, 10, 01);
    SimpleDate end = new SimpleDate(2012, 10, 10);
    DateRange dateRange = new DateRange(start, end);
    
    // Build a query with the "gender" dimension.
    ResultQuery query = ResultQuery.builderWithGroupingKey("gender")
                                   .withFilter(filter)
                                   .withDateRange(dateRange)
                                   .build();
    
    try {
      // Get snapshots.
      GroupedResult result = KiiAnalytics.getResult("_Aggregation_Rule_ID_", query);
      // Check the snapshots.
      List<GroupedSnapShot> snapshots = result.getSnapShots();
    } catch (KiiAnalyticsException e) {
      // Handle the error.
    }
  • // Define a filter.
    Filter filter = new Filter();
    filter.addFilter("location", "UK");
    
    // Define a data range.
    SimpleDate start = new SimpleDate(2012, 10, 01);
    SimpleDate end = new SimpleDate(2012, 10, 10);
    DateRange dateRange = new DateRange(start, end);
    
    // Build a query with the "gender" dimension.
    ResultQuery query = ResultQuery.builderWithGroupingKey("gender")
                                   .withFilter(filter)
                                   .withDateRange(dateRange)
                                   .build();
    
    // Get snapshots.
    KiiAnalytics.getResult("_Aggregation_Rule_ID_", query, new KiiResultCallback() {
      @Override
      public void onGetCompleted(String ruleId, ResultQuery query, AnalyticsResult result, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
        // Check the snapshots.
        GroupedResult groupedResult = (GroupedResult)result;
        List<GroupedSnapShot> snapshots = groupedResult.getSnapShots();
      }
    });

The analysis results will be a list of GroupedSnapShots. Each GroupedSnapShot has the following properties:

  • Name : The label of the dimension/grouping key (i.e., the value set as "Label" when you define your Aggregation Rule. If you did not set it, the value set as "Name" will be used instead).
  • Data : The JSON Array that contains the data retrieved by the query.
  • PointStart : The date (in milliseconds since UNIX epoch in UTC) in which the data starts.
  • PointInterval : Interval (in milliseconds) between data points.

Please check our Javadoc for more details on how to interpret GroupSnapShot.