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.

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.