HeadSpin Documentation
Documentation

Usage Report

The Usage API offers the following routes for usage data and statistics retrieval. Note that we adopted a new model that logs the user token after Aug 2022. Before this change, a device session is either associated with a user or a team, hence the <code class="dcode">[total usage]</code> is always the sum of  <code class="dcode">[usage by teams] + [usage by users]</code>. In the current scheme,  <code class="dcode">[total usage] = [usage by teams] = [usage by users]</code>.

Route Method Description
/v1/usage GET Get aggregated usage metric in individual time bins in the time range.
/v1/usage/device GET Get aggregated usage metric per device in individual time bins in the time range.
/v1/usage/user GET Get aggregated usage metric per user in individual time bins in the time range.
/v1/usage/team GET Get aggregated usage metric per team in individual time bins in the time range.
/v1/usage/host GET Get aggregated usage metric per host in individual time bins in the time range.
/v1/usage/country GET Get aggregated usage metric per country in individual time bins in the time range.
/v1/usage/team/device GET Get aggregated usage metric per team per device in individual time bins in the time range.
/v1/usage/user/team GET Same as /v0/usage/user but adds a column to display the teams that the user is affiliated with.
/v1/usage/devicemodel GET Get aggregated usage metric per device model in individual time bins in the time range.
/v1/usage/team/devicemodel GET Get aggregated usage metric per team per device model in individual time bins in the time range.
/v0/usage/events GET Return a list of individual usage events for the org in the time range.

Calculate Aggregated Usage Statistics

We provide several usage statistics that can be grouped by device, device model, user, team, host, or region via the usage API routes. You may find the configurable query parameters here.

Example Request

  • Get the total device usage time per day in a date range.

curl -X GET -H "Authorization: Bearer <your_api_token>" "https://api-dev.headspin.io/v1/usage?start_date=20230301&end_date=20230331&metric=total_time&timezone=US/Pacific&bin_size=day&display_all=false" 
  • Example response

{"report":
  [
    {
      "datetime": "YYYY-MM-DD",
      "total_time": <float>,
      "unit": "hour",
    }, ...
  ]
}
  • Evaluate the average session length for each team on a weekly timescale in a date range.

curl -X GET -H "Authorization: Bearer <your_api_token>" "https://api-dev.headspin.io/v1/usage/team?start_date=20230301&end_date=20230331&metric=total_time&timezone=US/Pacific&bin_size=day"
  • Example response

{"report":
  [
    {
      "datetime": "YYYY-MM-DD",
      "team": <team name>,
      "unit": "minute",
      "avg_session_length": <float>,
    }, ...
  ]
}
  • Get device usage for specific teams and device address

curl -X GET -H "Authorization: Bearer <your_api_token>" "https://api-dev.headspin.io/v1/usage/team/device?start_date=20230301&end_date=20230331&metric=total_time&timezone=US/Pacific&bin_size=month&display_all=false&filter_on.team_name=team_1_to_include&filter_on.team_name=team2%20to%20include&filter_on.device_address=device_id@hostname"

Query Parameters

All usage aggregation routes accept the following keywords.

Keyword Type Description Optional Default Value
start_date str The start of the date range for gathering device usage. Should be passed in YYYYMMDD format. False N/A
end_date str The end of the date range for gathering device usage. Should be passed in YYYYMMDD format. True Current date in the time zone specified by timezone
metric str The usage metric to calculate. See below for the usage metrics we support. True total_time
bin_size str Size of the time bin to aggregate over. Can be either hour, day, week, or month. True month
timezone str Timezone of the supplied date range . See available timezone names in the column TZ database name True UTC
format str Output usage statistics format. Can be either json or csv. True json
display_all bool Display devices/teams/users with 0 usage. When intending for device usage per team via /v1/usage/team/device, we advise using this option together with the filter_on.team_name filter to reduce the delay in response. True False
automated bool Select automated (true) or manual (false) sessions only. Data will contain both types of testing if this keyword is not specified. True None
filter_on.* str Aggregate on events that satisfy the filtering criteria. Supported filtering keywords must be passed with the prefix filter_on. and any key may have more than one value. Note that certain characters such as white space must be escaped in the url. See example. True None
combine_phone_os bool Group phone devices into AndroidPhone and iPhone by its os. This argument only takes effect in routes containing devicemodel. True False
group_by_device_id bool Omit hostname when grouping by device. This argument only takes effect in routes containing device. True False
include_user_notes bool Include User Notes in usage report. This argument only takes effect in routes aggregating users' usage. True False

Supported Usage Metrics

Usage Metric Alias Description Unit
Total Time total_time Sum of device usage time. Hour or Minute(*)
Average Session Length avg_session_length Mean of session duration. Minute
Session Count session_count Unique count of sessions. N/A
Device Count device_count Unique count of devices. N/A
User Count user_count Number of distinct users. N/A
Team Count team_count Number of distinct teams. N/A

*note: The total time unit is shown in minutes only when <code class="dcode">bin_size = 'hour'</code>.

Supported Filtering Keywords

Column Alias
Team team_name
Email user_email
Device Address device_address
Host Name hostname

Get A List of Device Usage Events

Individual usage events before any data aggregation may be retrieved via the route <code class="dcode">/v0/usage/events</code>.

A JSON body should be included that has the following shape


{
 "start_date": "<date>",
 "end_date": "<date>",
 "devices": [<device_address> ...],
 "format": "<format>",
}

Where <code class="dcode">date</code> can have the format <code class="dcode">YYYYMMDD</code> or <code class="dcode">YYYY/MM/DD</code>. <code class="dcode">device_address</code> is a device id and hostname joined by @, as in <code class="dcode">abcd123@dev-us-mv-0-proxy-2.headspin.io</code>

  • <code class="dcode">start_date</code>: The start date from which to gather device usage. Required.
  • <code class="dcode">end_date</code>: The end date from which to gather device usage. Optional, this defaults to the current date.
  • <code class="dcode">devices</code>: list of device addresses. Optional and defaults to all devices accessible
  • <code class="dcode">format</code>: <code class="dcode">json</code> or <code class="dcode">csv</code>, the format of the report. Optional, defaults to <code class="dcode">json</code>

The total range from <code class="dcode">start_date</code> to <code class="dcode">end_date</code> cannot be more than 120 days.

Both the <code class="dcode">json</cod> and <code class="dcode">csv</code> output format contain the same information in their respective formats. For <code class="dcode">json</code>, the output is


{"report":
  [
    {"user": <user name>,
     "email": <email of user>,
     "device_id": <device id>,
     "hostname": <hostname>,
     "start_time": <start date with second resolution>,
     "end_time": <end date with second resolution>,
     "duration": <duration of usage in seconds>,
     "date": <YYYYMMDD date of usage>
    },
    ...
  ]
}

When a device is used in automation mode instead of <code class="dcode">user</code> and <code class="dcode">email</code> the usage row will contain <code class="dcode">team</code> and the team name.

The <code class="dcode">csv</code> output will have the same fields as the <code class="dcode">json</code> output with the fields as the titles.


User/Team,Email,Device Id,Hostname,Start time,End time,Duration,Date
...

For an automation team usage the <code class="dcode">Email</code> field will be <code class="dcode">N/A</code>.

Example to get device usage events for the month of June 2020:


curl -X GET -H "Authorization: Bearer <your_api_token>" https://api-dev.headspin.io/v0/usage/events -d '{"start_date": "20200601", "end_date": "20200701"}'