User-activity API
chevron down
 

User-activity API

Variable: today

Type: Today

The User Activity API allows developers to retrieve data and events relating to a user's physical activity levels.

It is recommended to use the adjusted value which matches the value displayed within the Fitbit mobile app.

You must request the access_activity permission to use this API.

If the local.elevationGain value is undefined, then the current device does not contain a barometer sensor for floor detection, therefore you should not display the floor count.

import { me as appbit } from "appbit";
import { today } from "user-activity";

if (appbit.permissions.granted("access_activity")) {
   console.log(`${today.adjusted.steps} Steps`);
   if (today.local.elevationGain !== undefined) {
     console.log(`${today.adjusted.elevationGain} Floor(s)`);
   }
}

Variable: goals

Type: Goals

The User Activity API allows developers to retrieve data and events relating to a user's physical activity goals.

You must request the access_activity permission to use this API.

import { me as appbit } from "appbit";
import { goals } from "user-activity";

if (appbit.permissions.granted("access_activity")) {
   console.log(`${goals.adjusted.steps} Step Goal`);
   if (goals.local.elevationGain !== undefined) {
     console.log(`${goals.adjusted.elevationGain} Floor Goal`);
   }
}

Interface: Goals

A Goals object represents target goal values for certain activities, and emits events when those goals are reached.

Activities for which no goal has been set are undefined.

Properties

activeMinutes

number or undefined

Number of active minutes.

calories

number or undefined

Number of calories burned, in Calories (kcal).

distance

number or undefined

Distance travelled, in meters.

elevationGain

number or undefined

Elevation gain, in number of floors climbed.

onreachgoal

((this: Goals, event: Event) => any) or undefined

Event handler for reachgoal events emitted by this Goals object.

steps

number or undefined

Number of steps taken.

Methods

addEventListener()

addEventListener(type: "reachgoal", listener: (this: Goals, event: Event) => any)

Returns: void

Add a listener for reachgoal events emitted by this Goals object.

Variable: dayHistory

Type: ActivityHistory

New in SDK 4.0

Retrieve activity data for past day.

Variable: minuteHistory

Type: ActivityHistory

New in SDK 4.0

Retrieve activity data for past minutes.

Interface: ActivityHistory

New in SDK 4.0

Historical activity over some time period as defined by the interface instance.

Properties

readonly maxRecordCount

number

How far back does this history record extend, exclusive of the current time period. This is the maximum number of records getHistory can return.

Methods

query()

query(options?: { limit?: number | undefined; } | undefined)

Returns: ActivityHistoryRecord[]

Retrieve ActivityHistoryRecords for the previous N minutes or days. An optional limit parameter is available to limit the number of results returned to less than the maximum.

The first record in the array corresponds to the most recent time from which data could be available. This is 0-60s ago for minute records, and 0-24h ago for daily records. A dummy record (with undefined fields) will be inserted whenever data is not available for a given minute or day, or if the application does not have permission.

Note that this never includes records for the current minute or day, as that is not yet history.

Interface: ActivityHistoryRecord

New in SDK 4.0

An activity history object represents user activity over some time interval, defined by the interface providing these objects.

Properties

readonly averageHeartRate

number or undefined

Average heartrate, in beats per minute in the historical period. Note that you must have the access_heart_rate permission for this to be set.

readonly calories

number or undefined

Number of calories burned in the historical period, in Calories (kcal).

readonly distance

number or undefined

Distance traveled in the historical period in meters.

readonly elevationGain

number or undefined

Elevation gain, in number of floors climbed in the historical period.

readonly restingHeartRate

number or undefined

Resting heartrate, in beats per minute in the historical period. Note that you must have the access_heart_rate permission for this to be set.

readonly steps

number or undefined

Number of steps taken in the historical period.

Interface: Today

Today's physical activity.

Properties

readonly adjusted

Activity

Activity values with possible adjustment online based on other data sources such as manually reported activity values.

When no adjustments have been made or when the device has not received any adjustment from the online service, those values are the same as the local values.

readonly local

Activity

Activity values as measured locally on the device.

Interface: Activity

An Activity object represents several measurements of the user's physical activity for the current day.

Values that are not available on the device or currently unknown are undefined.

Implemented by user-activity.Goals

Properties

activeMinutes

number or undefined

Number of active minutes.

calories

number or undefined

Number of calories burned, in Calories (kcal).

distance

number or undefined

Distance travelled, in meters.

elevationGain

number or undefined

Elevation gain, in number of floors climbed.

steps

number or undefined

Number of steps taken.