Sessions

Sessions represent a time interval during which users perform a fitness activity such as a run, a bike ride, or a game. Sessions help organize data and perform detailed or aggregate queries for a fitness activity.

Sessions, datasets, and apps

Sessions in Google Fit consist of a start time, an end time, a user-friendly name, a description, an activity type, and a unique identifier. Sessions do not contain fitness data themselves. You can think of sessions as metadata objects with information that helps you query data from the fitness store later.

A dataset in Google Fit represents a fixed set of data points from a particular data source. A dataset represents data at fixed time boundaries, as shown in Figure 1. Your app can insert datasets without session information; however, in most cases you create sessions and datasets together with the same time boundaries.

Figure 1: Different apps add sessions and datasets to the fitness store.

Figure 1 shows a time interval in the fitness store during which apps A, B, and C have inserted some datasets and sessions:

  • App A inserted datasets A1 and A2 together with Session 1, and A3 indendendently of any sessions.
  • App B inserted datasets B1 and B2 together with Session 2.
  • App C inserted dataset C1 independently of any sessions.

When reading session data from the fitness store, all fitness data that falls within the time interval of a session is implicitly associated with that session, even if you insert the data after creating the session. For example, a query for fitness data from Session 1 would return:

  • Dataset A1
  • Dataset A2
  • The portion of dataset A3 between t1 and t2
  • The portion of dataset C1 between t1 and t2

You can determine which app inserted each session and dataset.

Benefits of using sessions

Sessions help you organize workouts by easily adding time interval metadata to fitness data in the fitness store. Here are some reasons why your app should use sessions with Google Fit:

  • You do not need to implement your own metadata schema and storage.
  • You can show available sessions along with the app that created each session.

Sessions make development and fitness data management easier, and they also increase user engagement with your app by interacting with other fitness apps.

Creating and reading sessions

The Sessions API lets you:

  • Create sessions in real time
  • Insert sessions in the fitness store
  • Insert activity segments to support pauses during workouts
  • Read sessions and datasets associated with them
  • Start another app to show session data
  • Receive an intent when any app starts a session

Data attribution in sessions

Sessions let you obtain the package name of the app that created them using the getAppPackageName method. You can use this information in your app to show users which other apps inserted fitness sessions that are relevant to the context. You can show the icon for each of these apps to help users identify them, and you can fire an intent to launch these apps. Other apps can also fire an intent to launch your app to view details of sessions it created.

Apps may show generic icons for other fitness apps not installed on the device.

For more information, see Data Attribution.

Send feedback about...