Skip to main content

Device Activity

GET /clients/{client_id}/analytics/devices/{device_id}/activity

Returns a daily time-series of activity for a specific device. Supports multiple metrics -- total activity count and distinct user count per day.

Use Case

Use this endpoint to:

  • Display device usage trends on the device detail page (line chart, sparkline)
  • Track how many users are active on a shared device over time
  • Identify underutilized or heavily used devices
  • Compare device activity across time periods

Path Parameters

ParameterTypeDescription
client_idstring (uuid)Unique identifier for the client organization
device_idstring (uuid)Unique identifier for the device

Query Parameters

ParameterTypeRequiredDescription
granularitystringYesAggregation granularity: daily, weekly, monthly, quarterly
start_datestringYesStart of date range (YYYY-MM-DD)
end_datestringYesEnd of date range, inclusive (YYYY-MM-DD)
metricstringYesMetric to retrieve. See Available Metrics.

Available Metrics

MetricLabelDescriptionDB Aggregation
activity-countTotal ActivitySum of all activity events on this deviceSUM(heartbeats.total_activity_count) GROUP BY DATE(generated_at_utc) WHERE device_id = ?
user-countDaily UsersNumber of distinct users active on this device per dayCOUNT(DISTINCT heartbeats.user_id) GROUP BY DATE(generated_at_utc) WHERE device_id = ?

Response

Returns an ActivityTimeSeries.

Example Requests

Activity count

curl -X GET "https://api.example.com/v2/clients/aa7cf840-9ca9-46a3-9778-9015d6580d50/analytics/devices/f1e2d3c4-b5a6-7890-abcd-ef1234567890/activity?start_date=2026-01-01&end_date=2026-01-15&metric=activity-count" \
-H "Authorization: Bearer YOUR_API_TOKEN"

User count

curl -X GET "https://api.example.com/v2/clients/aa7cf840-9ca9-46a3-9778-9015d6580d50/analytics/devices/f1e2d3c4-b5a6-7890-abcd-ef1234567890/activity?start_date=2026-01-01&end_date=2026-01-15&metric=user-count" \
-H "Authorization: Bearer YOUR_API_TOKEN"

Example Responses

activity-count

{
"metric": "activity-count",
"label": "Total Activity",
"period": {
"start": "2026-01-01",
"end": "2026-01-15"
},
"data": [
{ "date": "2026-01-01", "value": 87 },
{ "date": "2026-01-02", "value": 64 },
{ "date": "2026-01-03", "value": 92 },
{ "date": "2026-01-04", "value": 0 },
{ "date": "2026-01-05", "value": 0 },
{ "date": "2026-01-06", "value": 78 },
{ "date": "2026-01-07", "value": 81 },
{ "date": "2026-01-08", "value": 95 },
{ "date": "2026-01-09", "value": 73 },
{ "date": "2026-01-10", "value": 88 },
{ "date": "2026-01-11", "value": 0 },
{ "date": "2026-01-12", "value": 0 },
{ "date": "2026-01-13", "value": 91 },
{ "date": "2026-01-14", "value": 85 },
{ "date": "2026-01-15", "value": 79 }
]
}

user-count

{
"metric": "user-count",
"label": "Daily Users",
"period": {
"start": "2026-01-01",
"end": "2026-01-15"
},
"data": [
{ "date": "2026-01-01", "value": 3 },
{ "date": "2026-01-02", "value": 2 },
{ "date": "2026-01-03", "value": 3 },
{ "date": "2026-01-04", "value": 0 },
{ "date": "2026-01-05", "value": 0 },
{ "date": "2026-01-06", "value": 3 },
{ "date": "2026-01-07", "value": 2 },
{ "date": "2026-01-08", "value": 3 },
{ "date": "2026-01-09", "value": 2 },
{ "date": "2026-01-10", "value": 3 },
{ "date": "2026-01-11", "value": 0 },
{ "date": "2026-01-12", "value": 0 },
{ "date": "2026-01-13", "value": 3 },
{ "date": "2026-01-14", "value": 2 },
{ "date": "2026-01-15", "value": 3 }
]
}

Error Responses

StatusDescription
400Invalid parameters (bad date format, range exceeds 90 days, unknown metric)
401Authentication required
403Insufficient permissions for this client
404Device or client not found
500Server error

Example Error Response

{
"error": {
"code": "invalid_parameter",
"message": "Unknown metric: invalid-metric. Valid values: activity-count, user-count",
"details": {
"metric": "invalid-metric"
}
}
}

Notes

  • The response always includes every date in the range, even weekends or days with zero activity.
  • All dates are in the client's configured timezone.
  • user-count counts distinct users per day, not cumulative. A user active on 3 days appears in each day's count separately.
  • Data freshness depends on heartbeat delivery (typically within 5 minutes).