User-activity API
chevron down
 

User-activity API

Variable: week

Type: Week

New in SDK 6.0

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

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.

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

if (appbit.permissions.granted("access_activity")) {
   console.log(`${week.adjusted.activeZoneMinutes} AZM`);
}

Variable: weekGoals

Type: WeekGoals

New in SDK 6.0

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

You must request the access_activity permission to use this API.

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

if (appbit.permissions.granted("access_activity")) {
   console.log(`${weekGoals.activeZoneMinutes} AZM Goal`);
}

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: primaryGoal

Type: ["steps" | "distance" | "calories" | "elevationGain" | "activeZoneMinutes"]

New in SDK 4.2

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

This property contains the name of the user's primary activity goal type. You can use the value provided to index directly into the goals/today objects provided by the User Activity API to get progress for this goal.

You must request the access_activity permission to use this API.

If you do not have the appropriate permission, this property will be undefined.

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

if (appbit.permissions.granted("access_activity")) {
   console.log(`User's primary activity goal is ${primaryGoal}`);
}

Note: old activeMinutes has been replaced with activeZoneMinutes (check Activity interface)

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

activeZoneMinutes

ActiveZoneMinutes or undefined

New in SDK 4.2

The Zone Minutes spent in each of the heart rate zones that relate to physical activity.

calories

number or undefined

Number of calories burned, in Calories (kcal).

distance

number or undefined

Distance traveled, 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: WeekGoals

New in SDK 6.0

A WeekGoals 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

activeZoneMinutes

number or undefined

Total number of Active Zone Minutes.

onreachgoal

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

Event handler for reachgoal events emitted by this Goals object.

Methods

addEventListener()

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

Returns: void

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

Interface: Week

New in SDK 6.0

This week's physical activity.

Properties

readonly adjusted

WeekActivity

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

WeekActivity

Activity values as measured locally on the device.

Interface: WeekActivity

New in SDK 6.0

A WeekActivity object represents several measurements of the user's physical activity for the current week.

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

Implemented by user-activity.WeekGoals

Properties

activeZoneMinutes

number or undefined

Total number of Active Zone 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 heart rate, 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

New in SDK 4.2

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

readonly restingHeartRate

number or undefined

Resting heart rate, 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: ActiveZoneMinutes

New in SDK 4.2

ActiveZoneMinutes is a physical activity metric that counts minutes spent in the each heart rate zone, counting all activities that get the user's heart pumping.

There are 3 heart rate zones: Fat Burn, Cardio and Peak.

Depending on the heart rate zone, a user can earn 2X the minutes with more effort:

  • 1 minute in Fat Burn zone = 1 Zone Minute

  • 1 minute in Cardio or Peak zone = 2 Zone Minutes

Properties

readonly cardio

number or undefined

Number of Zone Minutes spent in Cardio zone. Note: This property is optional, it must be checked! (e.g. for the Today's adjusted case or goals variable, the ActiveZoneMinutes will only have the total value available)

readonly fatBurn

number or undefined

Number of Zone Minutes spent in Fat Burn zone. Note: This property is optional, it must be checked! (e.g. for the Today's adjusted case or goals variable, the ActiveZoneMinutes will only have the total value available)

readonly peak

number or undefined

Number of Zone Minutes spent in Peak zone. Note: This property is optional, it must be checked! (e.g. for the Today's adjusted case or goals variable, the ActiveZoneMinutes will only have the total value available)

readonly total

number

Total number of Active Zone Minutes. Calculated by total = fatBurn + cardio + peak.

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

activeZoneMinutes

ActiveZoneMinutes or undefined

New in SDK 4.2

The Zone Minutes spent in each of the heart rate zones that relate to physical activity.

calories

number or undefined

Number of calories burned, in Calories (kcal).

distance

number or undefined

Distance traveled, in meters.

elevationGain

number or undefined

Elevation gain, in number of floors climbed.

steps

number or undefined

Number of steps taken.