Sessions - Android SDK v2 (Legacy)

This document provides a high-level overview of sessions in Google Mobile App Analytics and the Google Analytics SDK for Android v2 and describes the various methods available to manage sessions in your app.


A session represents a single period of user interaction with your app. Sessions serve as useful containers of measured activity, which includes screen views, events, and ecommerce transactions.

By default, Google Analytics will group hits that are received within 30 minutes of one another into the same session. However, many developers might want to implement an additional layer of session management that takes into account the state of their app, such as when the app is in the background and for how long.

The rest of this document will describe the methods that are available to implement that logic. Your options range from fully-automated session management, provided by EasyTracker, to manually building your own session management logic, or using a mix of both.

Managing Sessions

The following section will describe the methods available to you to manage sessions in your app.

Automated session management using EasyTracker

EasyTracker provides automated session management that can handle the work of starting new sessions for you. Here's an overview of how automated session management works:

  • A default implementation has a session timeout period of 30 seconds. You can change the timeout period by modifying ga_sessionTimeout parameter in your analytics.xml file:
      <-- Set session time out to 60 seconds -- >
      <integer name="ga_sessionTimeout">60</integer>
  • If the app remains in the background for longer than the session timeout period, EasyTracker will flag the need for a new session and the next hit will be part of a new session.

Manual session management

Even if you're using EasyTracker's automated session management, it may be useful to start new sessions manually at key events in your app's lifecycle.

For example, you might want to manually start a new session each time a user successfully signs in to your app. Since the user's intent in using the app may have changed, or it may be a different user altogehter, starting a new session on sign in will help keep usage data separate and easier to understand in your reports.

To start a new session, call setStartSession(true) . This will add a parameter to the next sent hit indicating that it should start a new session.

In the example below, we assume that onSignIn() is called any time a user successfully signs in to your app:

// Called after a user successfully signs in to your app.
private void onSignIn() {
  ... // The rest of your onSignIn() code.
  myTracker.setStartSession(true); // Where myTracker is an instance of Tracker.
  myTracker.sendEvent("app_flow", "sign_in", "", null); // First activity of new session.