Important: This document describes a legacy version of the SDK. New users should use the latest SDK.

Sessions - Android SDK

This document provides a high-level overview of sessions as they relate to the Google Analytics SDK for Android v3.

Overview

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.

Managing Sessions

By default, Google Analytics will group hits that are received within 30 minutes of one another into the same session. This period is configurable at the property level. Learn how to configure this session timeout period.

Manual Session Management

To manually start or end a session, set the session control parameter in the Map you pass into the tracker send method.

// May return null if a tracker has not yet been initialized.
Tracker tracker = GoogleAnalytics.getInstance(this).getDefaultTracker();

// Start a new session with an AppView hit.
MapBuilder builder = MapBuilder.createAppView();
builder.set(Fields.SESSION_CONTROL, "start");
tracker.set(Fields.SCREEN_NAME, "My Screen");
tracker.send(builder.build());
// There should be no need to end a session explicitly.  However, if you do
// need to indicate end of session with a hit, simply add the following line
// of code to add the parameter to the builder:
builder.set(Fields.SESSION_CONTROL, "end");

Automatic Session Management (EasyTracker)

EasyTracker can automatically start new sessions for you when users have placed your app in the background for a period of time. This session timeout period is defined by the ga_sessionTimeout parameter in your analytics.xml file.

<!-- analytics.xml -->

<!-- Set a session timeout period of 30 seconds -->
<integer name="ga_sessionTimeout">30</integer>