Search code examples
androidgoogle-analyticsgoogle-play-servicesgoogle-analytics-apigoogle-play-games

Google Analytics for Android - how to resume session


I'd like to track duel progress and results in multiplayer Android game: every move of every player. Game uses turn-based Google Games API, which allows to switch between multiple parallel duels.

Is is possible to resume particular Analytics Tracker session, when user returns to given game? We could base session number/symbol on Games-API Id to identify resumed game.

If not, how can I use analytics to (all goals at the same time):

  • track move of every player as it happens /game is turn-based/ and identify moves from single game even if it was interrupted by moves of another game(s)
  • be able to filter out in web console all moves from unfinished games /in progress or abandoned/
  • be able to tell, what was distribution of game length /turn number/

Solution

  • I don't believe you can resume a session in Google Analytics. You can however disable the automatic session tracking by setting the session timeout to -1 and manually start new session by calling setNewSession on ScreenViewBuilder. Your code will like something like this:

    analytics = GoogleAnalytics.getInstance(getApplicationContext());
    tracker = analytics.newTracker(TRACKER_ID);
    tracker.setSesstionTimeout(-1); // Disable automatic session tracking
    
    // When you need to start new session, send a screen view
    tracker.send(new HitBuilders.ScreenViewBuilder().setNewSession().build());
    

    Here is a link to the session definition in Google Analytics: https://support.google.com/analytics/answer/2731565?hl=en

    And the Android SDK API reference:

    https://developers.google.com/analytics/devguides/collection/android/v4/sessions#manual

    https://developer.android.com/reference/com/google/android/gms/analytics/Tracker.html#setSessionTimeout(long)