Fetch Analytics Results with the API

We can extract the analysis results via the REST API in two formats:

  • Tabular Result: The aggregated results are returned for a combination of dimensions.
  • Grouped Result: The aggregated results are returned for a value of the specified dimension.

Tabular result:

Here is an example of fetching a tabular result. Here, we are fetching the aggregates analyzed from 2012-12-1 to 2013-1-31.

curl -v -X GET \
  -H "Authorization: Basic {BASE64_ENCODED_APPID_AND_APPKEY}" \
  -H "Accept: application/vnd.kii.TabularAnalyticResult+json" \
  "https://api.kii.com/api/apps/{APP_ID}/analytics/{AGGREGATION_RULE_ID}/data?startDate=2012-12-1&endDate=2013-1-31"

You get the result with Basic Authentication. Replace {BASE64_ENCODED_APPID_AND_APPKEY} with a Base64-encoded string of concatenated AppID and an arbitrary value with a colon (:) in between the two values.

Kii Cloud will return the result like the following.

{
  "labels" : [ {
    "label" : "UserScore",
    "type" : "DIMENSION"
  }, {
    "label" : "UserLevel",
    "type" : "DIMENSION"
  }, {
    "label" : "AppVersion",
    "type" : "DIMENSION"
  }, {
    "label" : "Count",
    "type" : "FACT"
  } ],
  "snapshots" : [ {
    "createdAt" : 1357862400000,
    "data" : [ [ 90, "Hard", 5, 1 ], [ 0, "Easy", 1, 8 ],   (...snip...)   , [ 90, "Hard", 4, 1 ] ]
  }, {
    "createdAt" : 1357948800000,
    "data" : [ [ 0, "Easy", 1, 8 ], [ 90, "Hard", 6, 1 ],   (...snip...)   , [ 90, "Hard", 5, 1 ] ]

  (... snip ...)

  } ]
}

We can also specify some filters (e.g. only fetch the aggregates for "UserLevel = Easy"). Please refer the detailed REST API documentation to learn more.

Grouped result:

Here is an example of fetching a grouped result. Here, we are fetching the aggregates analyzed from 2012-12-1 to 2013-1-31 while grouping the results with the dimension "UserLevel". (For specifying the dimension, use the value set as "Name" when you define your Conversion Rule).

curl -v -X GET \
  -H "Authorization: Basic {BASE64_ENCODED_APPID_AND_APPKEY}" \
  -H "Accept: application/vnd.kii.GroupedAnalyticResult+json" \
  "https://api.kii.com/api/apps/{APP_ID}/analytics/{AGGREGATION_RULE_ID}/data?startDate=2012-12-1&endDate=2013-1-31&group=UserLevel"

You get the result with Basic Authentication. Replace {BASE64_ENCODED_APPID_AND_APPKEY} with a Base64-encoded string of concatenated AppID and an arbitrary value with a colon (:) in between the two values.

Kii Cloud will return the result like the following.

{
  "snapshots" : [ {
    "name" : "Easy",
    "data" : [ 236, 236, 236,  (...snip...)   , 236 ],
    "pointStart" : 1357862400000,
    "pointInterval" : 86400000
  }, {
    "name" : "Hard",
    "data" : [ 330, 330, 354,  (...snip...)   , 354],
    "pointStart" : 1357862400000,
    "pointInterval" : 86400000
 }, {

  (... snip ...)

  } ]
}

The response contains the following information:

  • 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 (milliseconds since UNIX epoch in UTC) in which the data starts.
  • pointInterval : Interval (in milliseconds) between data points.

We can also specify some filters (e.g. only fetch the aggregates for "UserLevel = Easy"). Please refer the detailed REST API documentation to learn more.