This document provides a high-level overview of sessions as they relate to the Google Analytics SDK v4 for Android.
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. 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());
Advanced Configuration for details on the
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
<resources> <integer name="ga_sessionTimeout">300</integer> </resources>
To programatically set the session timeout: