This document provides a high-level overview of sessions as they relate to the Google Analytics SDK v4 for Android.
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.
Session Management
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
You can manually start a new session when sending a hit to Google Analytics
by using the setNewSession
method. The following example shows
how to start a new session when sending a screen view:
// Get tracker. Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker( TrackerName.APP_TRACKER); // Set screen name. t.setScreenName(screenName); // Start a new session with the hit. t.send(new HitBuilders.ScreenViewBuilder() .setNewSession() .build());
See
Advanced Configuration for details on the getTracker
method.
Automatic Session Management
You can configure Google Analytics to automatically start new sessions when
users have placed your app in the background for a period of time. This
session timeout period is defined in seconds by the
ga_sessionTimeout
parameter in the tracker's
xml
file.
<resources> <integer name="ga_sessionTimeout">300</integer> </resources>
To programatically set the session timeout:
t.setSessionTimeout(300L);