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 independently 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 REST API lets you create sessions and retrieve sessions within a specific time interval. You can also read data from datasets that overlap with the time interval of a session. For more information, see Working with Sessions and Working with Datasets.

Data attribution in sessions

Sessions let you obtain the package name of the Android app that created them using the session.application property. For sessions that were created using the REST API, you can use the property. You can use this information in your app to show users which other apps inserted fitness sessions that are relevant to the context. For more information, see Data Attribution.