A session represents a single period of user interaction with your app. The equivalent concept in web analytics is a visit. Like visits, 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 sessionTimeout setting in your analytics.xml file:
<-- Set session time out to 60 seconds -- >
  • 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 altogether, 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.

Last edited Aug 11, 2013 at 11:43 PM by timgreenfield, version 2