为您的游戏添加玩家统计信息
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在弃用 Google 登录 API 后,我们将于 2026 年移除 games v1 SDK。2025 年 2 月之后,您将无法在 Google Play 上发布新集成了 games v1 SDK 的游戏。我们建议您改用 games v2 SDK。
虽然采用旧版游戏 v1 集成的现有游戏仍可在未来几年内正常运行,但我们建议您从 2025 年 6 月开始迁移到 v2。
本指南介绍了如何使用 Play 游戏服务 v1 SDK。Play 游戏服务 v2 的 C++ SDK 尚未推出。
利用 Player Stats API,您可以针对某些玩家细分群体和玩家生命周期的不同阶段量身设计游戏体验。您可以根据玩家的游戏进度、消费情况和互动度,为每个玩家细分群体量身打造体验。举例来说,您可以使用此 API 采取积极的措施来鼓励活跃度较低的玩家重新积极地玩游戏,例如您可以在玩家登录时显示并推销新的游戏内商品。
本指南介绍了如何在原生 C++ 或 Objective-C 应用中使用 Player Stats API。
玩家统计信息基础知识
您可以使用 Player Stats API 检索玩家在游戏内的活动数据。您可以检索的玩家数据类型包括:
- 平均会话时长:玩家的平均会话时长,以分钟为单位。每次的会话时长从玩家登录 Google Play 游戏服务之时开始计算,到退出服务为止。
- 流失概率:对玩家是否会在次日流失进行的预测,以 0(流失概率较低)或 1(流失概率较高)表示。流失的定义系指玩家连续 7 天无活动。
- 距离上次玩游戏的天数:距离玩家上一次玩游戏的大概天数。
- 购物次数:玩家在应用内购买商品的大概次数。
- 会话次数:玩家的大概会话次数。会话次数根据玩家登录 Google Play 游戏服务的次数来计算。
- 会话百分位:玩家的会话百分位近似值,以 0 到 1 之间(包括这两个数值)的小数值表示。此值反映与此游戏的玩家群中其他的玩家相比,当前玩家玩游戏的会话次数。数字越大,表示此玩家玩游戏的会话越多。
- 消费百分位:玩家的消费百分位近似值,以 0 到 1 之间的小数值(包括这两个数值)表示。此值反映与此游戏的玩家群中其他的玩家相比,当前玩家已经消费的金额。数字越大,表示此玩家的消费越多。
使用 C++ 获取当前已登录玩家的玩家统计数据
// Create the callback for our asynchronous fetch call. This callback will
// log either an error or the average session length for the currently
// signed-in player.
gpg::StatsManager::FetchForPlayerCallback callback = [](gpg::StatsManager::FetchForPlayerResponse const &response) {
if (IsError(response.status)) {
LogE("An error occurred fetching player stats.");
} else {
gpg::PlayerStats const & player_stats = response.data;
if (player_stats.HasAverageSessionLength()) {
LogI("Average session length: %f", player_stats.AverageSessionLength());
} else {
LogW("Currently signed-in player had no associated average session length stats.");
}
}
};
// Asynchronously fetch the Player Stats. When the fetch is finished it
// will call our callback. game_services_ is the std::unique_ptr<GameServices>
// returned by gpg::GameServices::Builder.Create()
game_services_->Stats().FetchForPlayer(callback);
使用 Objective-C 获取当前已登录玩家的玩家统计信息
// Asynchronously fetches the Player Stats and then logs either a
// description of them or an error
[GPGPlayerStats playerStatsWithCompletionHandler:^(GPGPlayerStats *playerStats, NSError *error) {
if (error) {
NSLog(@"Error fetching player stats: %@", error);
} else {
NSLog(@"Description of stats for the currently signed-in player: %@", playerStats);
}
}];
有关使用玩家统计数据的提示
利用 Play Stats API,您可以根据玩家在游戏内的互动情况和消费行为,轻松识别不同类型的玩家,然后采取相应的策略提升玩家的游戏体验。
下表列出了一些玩家细分示例以及建议的互动度提升策略:
玩家细分 |
互动度提升策略 |
玩家以往通常会话次数较多、消费百分位较高,但最近已经有一周或更长时间没有玩游戏了。 |
- 发通知告诉他们回来玩游戏可享受折扣或获得特别奖励。
- 通过显示欢迎回来的消息,对玩家的出色成绩表示认可,并奖励一枚专为鼓励玩家回来玩游戏而设计的徽章。
|
玩家的互动度较高、消费百分位较低。 |
- 量身设计奖励来激励他们邀请好友安装并使用您的游戏。此方法是利用玩家对游戏所表现出的兴趣来吸引新的玩家。
|
高消费玩家玩游戏的积极性已达顶峰,且有迹象表明他们开始降低玩游戏的频率。 |
- 量身设计奖励来重新唤起他们的兴趣,例如提供价值高、有效期短的工具、武器或折扣。
- 在玩家下次登录时,显示一个视频,引导玩家体验社区功能(例如部族攻击),从而促进玩家更频繁、更持久地玩游戏。
|
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Add player stats to your game\n\nFollowing the deprecation of the\n[Google Sign-In](https://android-developers.googleblog.com/2024/09/streamlining-android-authentication-credential-manager-replaces-legacy-apis.html)\nAPI, we are removing the games v1 SDK in 2026. After February 2025, you will be unable to publish\ntitles that are newly integrated with games v1 SDK, on Google Play. We recommend that you use the\ngames v2 SDK instead. \n\nWhile existing titles with the previous games v1 integrations continue to function for a\ncouple of years, you are encouraged to\n[migrate to v2](/games/pgs/android/migrate-to-v2)\nstarting June 2025. \n\nThis guide is for using the Play Games Services v1 SDK. The C++ SDK for\nPlay Games Services v2 is not yet available.\n\nThe Player Stats API let you tailor game experiences to specific segments of\nplayers and different stages of the player lifecycle. You can build tailored\nexperiences for each player segment based on how players are progressing,\nspending, and engaging. For example, you can use this API to take proactive\nactions to encourage a less active player to re-engage with your game, such as\nby displaying and promoting new in-game items when the player signs in.\n\nThis guide shows you how to use the Player Stats API in a native C++ or\nObjective-C application.\n\nPlayer stats basics\n-------------------\n\nYou can use the Player Stats APIs to retrieve data about a player's in-game\nactivity. The types of player data you can retrieve include:\n\n- **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.\n- **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.\n- **Days since last played**: The approximate number of days since the player last played.\n- **Number of purchases**: The approximate number of in-app purchases for the player.\n- **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.\n- **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.\n- **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.\n\nGet player stats for a currently signed-in player with C++\n----------------------------------------------------------\n\n // Create the callback for our asynchronous fetch call. This callback will\n // log either an error or the average session length for the currently\n // signed-in player.\n gpg::StatsManager::FetchForPlayerCallback callback = [](gpg::StatsManager::FetchForPlayerResponse const &response) {\n if (IsError(response.status)) {\n LogE(\"An error occurred fetching player stats.\");\n } else {\n gpg::PlayerStats const & player_stats = response.data;\n if (player_stats.HasAverageSessionLength()) {\n LogI(\"Average session length: %f\", player_stats.AverageSessionLength());\n } else {\n LogW(\"Currently signed-in player had no associated average session length stats.\");\n }\n }\n };\n // Asynchronously fetch the Player Stats. When the fetch is finished it\n // will call our callback. game_services_ is the std::unique_ptr\u003cGameServices\u003e\n // returned by gpg::GameServices::Builder.Create()\n game_services_-\u003eStats().FetchForPlayer(callback);\n\nGet player stats for a currently signed-in player with Objective-C\n------------------------------------------------------------------\n\n // Asynchronously fetches the Player Stats and then logs either a\n // description of them or an error\n [GPGPlayerStats playerStatsWithCompletionHandler:^(GPGPlayerStats *playerStats, NSError *error) {\n if (error) {\n NSLog(@\"Error fetching player stats: %@\", error);\n } else {\n NSLog(@\"Description of stats for the currently signed-in player: %@\", playerStats);\n }\n }];\n\nTips for using player stats data\n--------------------------------\n\nThe Play Stats API lets you easily identify various types of players, based on\ntheir engagement and spending behavior, and apply appropriate strategies to\nenhance their game experience.\n\nThe following table lists some example player segments and recommended\nengagement strategies:\n\n| Player Segment | Engagement Strategy |\n|---------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| 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. |\n| 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. |\n| 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 them to community features, like clan attacks, that drive more frequent and longer engagement. |"]]