Adding Player Stats to Your Android Game

The Player Stats API let you tailor game experiences to specific segments of players and different stages of the player lifecycle. You can build tailored experiences for each player segment based on how players are progressing, spending, and engaging. For example, you can use this API to take proactive actions to encourage a less active player to re-engage with your game, such as by displaying and promoting new in-game items when the player signs in.

This guide shows you how to use the Player Stats API in an Android application.

Before you begin

Before you start to use the Player Stats API:

Once the player is signed in and the GoogleApiClient is connected, your game can start using the Player Stats API.

Player Stats basics

You can use the Player Stats APIs to retrieve data about a player’s in-game activity. The types of player data you can retrieve include:

  • Average session length: The average session length of the player in minutes. Session length is determined by the time that a player is signed in to Google Play Games services.
  • Churn probability: The prediction of whether a player will churn in the next day, given as 0 (low probability of churn) or 1 (high probability of churn). Churn is defined as 7 days of inactivity.
  • Days since last played: The approximate number of days since the player last played.
  • Number of purchases: The approximate number of in-app purchases for the player.
  • Number of sessions: The approximate number of sessions of the player. Sessions are determined by the number of times that a player signs in to Google Play Games services.
  • Session percentile: The approximation of sessions percentile for the player, given as a decimal value between 0 and 1 (inclusive). This value indicates how many sessions the current player has played in comparison to the rest of this game's player base. Higher numbers indicate that this player has played more sessions.
  • Spend percentile: The approximate spend percentile of the player, given as a decimal value between 0 and 1 (inclusive). This value indicates how much the current player has spent in comparison to the rest of this game's player base. Higher numbers indicate that this player has spent more.
  • Spend probability: The approximate probability of the player choosing to spend in this game, given as 0 (low probability of spend) or 1 (high probability of spend).
  • Total spend next 28 days: The approximate total expected player spend over the next 28 days in this game.
  • High spender probability: The approximate probability that over the next 28 days a player will spend an amount that is in the 95th percentile or higher of this game’s player base. Value is given given as 0 (low probability of becoming a high spender) or 1 (high probability of become a high spender).

Retrieving Player Stats data

To retrieve Player Stats data for the currently signed-in player, follow these steps:

  1. Create a GoogleApiClient object and configure it to use the Games API and SCOPE.
  2. Call the Games.Stats.loadPlayerStats() method. If the call is made successfully, it returns a Stats.LoadPlayerstatsResult object.
  3. Call the getPlayerStats() method of the LoadPlayerstatsResult object. A successful call returns a PlayerStats object which let's you access data about the signed-in player’s activity.

The following code snippet shows how you might retrieve the player's number of days since last played and number of sessions:

public void checkPlayerStats() {
    PendingResult<Stats.LoadPlayerStatsResult> result =
            Games.Stats.loadPlayerStats(
            mGoogleApiClient, false /* forceReload */);
    result.setResultCallback(new
            ResultCallback<Stats.LoadPlayerStatsResult>() {
        public void onResult(Stats.LoadPlayerStatsResult result) {
            Status status = result.getStatus();
            if (status.isSuccess()) {
                PlayerStats stats = result.getPlayerStats();
                if (stats != null) {
                    Log.d(TAG, "Player stats loaded");
                    if (stats.getDaysSinceLastPlayed() > 7) {
                        Log.d(TAG, "It's been longer than a week");
                    }
                    if (stats.getNumberOfSessions() > 1000) {
                        Log.d(TAG, "Veteran player");
                    }
                    if (stats.getChurnProbability() == 1) {
                        Log.d(TAG, "Player is at high risk of churn");
                    }
                }
            } else {
                Log.d(TAG, "Failed to fetch Stats Data status: "
                        + status.getStatusMessage());
            }
        }
    });
}

Tips for Using Player Stats data

The Play Stats API lets you easily identify various types of players, based on their engagement and spending behavior, and apply appropriate strategies to enhance their game experience.

The following table lists some example player segments and recommended engagement strategies:

Player Segment Engagement Strategy
Frequent players with a high number of sessions and good spend percentile, but have not played for the last week or more.
  • Send a notification about a discount or special bonus available upon their return to play.
  • Show a welcome back message that acknowledges impressive accomplishments, and award a badge designed to encourage return play.
Highly engaged players in a low spend percentile.
  • Tailor bonuses to incentivize them to invite their friends to install and join your game. This approach builds on the player's demonstrated enjoyment of the game to recruit new players.
High spending players showing signs of having peaked and starting to play less frequently.
  • Tailor bonuses to freshen their interest, such as by offering high-value, short-duration tools, weapons, or discounts.
  • The next time the player signs in, show a video that directs him or her to community features, like clan attacks, that drive more frequent and longer engagement.
Players with very high or very low spend probability.
  • Unlikely to spend: Give the option to watch an advertisement video. Show lower-priced items for purchase.
  • Likely to spend: Direct them to the in-game store early, and provide special promotions to incentivize them to buy.

Send feedback about...

Play Games Services for Android
Play Games Services for Android