Last Updated: 6/15/2022, 11:15:59 AM

# Statistics

# Overview

The Statistics service provides game developers with persistent statistic tracking for their games. Tracked statistics include gameplay-related stats such as kill, die, and assist, and internal game data such as map played and game modes played. Statistics are tied to players and can be easily integrated or displayed as game profile attributes through the game profile service.

The statistics service also acts as the reference point for consistent value tracking across other services such as Progression, Achievements, and Leaderboards. We use messaging to update statistics values asynchronously to other related services in real-time. You only need to define the statistics you want to measure once, and they’ll be applied to all related services.

# Permissions

Permissions are used to grant access to specific resources within our services. Make sure your account has the following permissions before you attempt to manage statistics in the Admin Portal:

Usage Permission Tag Action
Create a New Statistic Configuration ADMIN:NAMESPACE:{namespace}:STAT Create
Create a Single Statistic for a Player ADMIN:NAMESPACE:{namespace}:USER:{userId}:STATITEM Create
Create a Multiple Statistics for a Player ADMIN:NAMESPACE:{namespace}:USER:{userId}:STATITEM Create
Retrieve All of a Player’s Statistics ADMIN:NAMESPACE:{namespace}:USER:{userId}:STATITEM Read
Update a Single Statistic for a Player ADMIN:NAMESPACE:{namespace}:USER:{userId}:STATITEM Update
Update Multiple Statistics for Multiple Players ADMIN:NAMESPACE:{namespace}:USER:{userId}:STATITEM Update
Retrieve Global Statistics ADMIN:NAMESPACE:{namespace}:USER:{userId}:STATITEM Read

Permissions work slightly differently depending on whether they are assigned to IAM Clients or Roles assigned to users. For more information, read the Authentication and Authorization documentation.

# Managing Statistics in the Admin Portal

# Create a New Statistic Configuration

  1. In the Admin Portal, go to the Game Management section, expand the Statistics section, and select the Configurations menu.

    statistics

  2. In the Statistic Configurations window, click the Add Configuration button.

    statistics

  3. The Add New Configuration form will appear. Fill in the required fields.

    statistics

    • Input the statistic code or StatCode in the Code field, following the formatting rules given.

      NOTE

      StatCode will be used when you create an Incremental Achievement and Leaderboard as those services will use player's statistics to determine the achievement condition and generate the leaderboard.

    • Input the Name of the configuration.

    • Input a Description of the configuration. This field is optional.

    • Define the minimum value of the statistic in the Min. Value field.

    • Define the maximum value of the statistic in Max. Value field.

    • Input the Default Value of the statistic.

    • Choose the Increment value. If set to True, the stat value can only be increased. If False, the stat value can be increased or decreased.

    • Choose the Set as Global value. If set to True, every time the stat is updated the global stat value will also be updated.

    • Select the Set By value. You can choose game client or game server. This determines which client will update the stat value.

    • Input the Tag field with contextual information related to the statistic. This field is optional.

# Retrieve a Player’s Statistics

  1. In the Admin Portal, go to the Game Management section, expand the Statistics section, and select the Statistics Value menu.

    statistics

  2. Search for a player using the by using Email, Display Name, Username or by using User ID search filter. You can input the specific value that corresponds to the user you’re looking for.

    statistics

  3. Click View on the action panel of the desired player.

    statistics

  4. On the Statistics Values page, you can see detailed information about the player’s statistics.

    statistics

# Edit a Player’s Statistics

  1. On a player’s Statistics Value page, choose the statistic you want to edit and click the pencil icon under the Current Value column. Once you have made a change, click the blue tick button to save.

    statistics

# Retrieve Global Statistics

  1. In the Admin Portal, go to the Game Management section, expand the Statistics section, and select the Statistics Value menu.

    statistics

  2. Switch to the Global tab. Here you’ll see the global statistics.

    statistics

# Implementing Statistics Using the Client Server SDK

You can manage your statistics using the Client or Game Server. In this tutorial, you will learn how to set up the SDK using the Client Server.

# Create a Single Statistic for a Player

Use the following code to create a new statistic for a player.

# Create Multiple Statistics for a Player

Use the following code to create multiple new statistics for a player.

# Retrieve a Player’s Statistic by StatCodes or Tags

Use the following code to retrieve a player’s statistic by a specific StatCodes or Tags.

# Retrieve All Players’ Statistics

Use the following code to retrieve all of your players’ statistics.

# Reset Multiple Statistics

Use the following code to reset a player's statistic to the default values as specified in your game namespace.

# Update Multiple Statistics

Use the following code to update multiple statistics. There are 4 update strategies that you can use to handle the strategy.

Update Strategy Usage
OVERRIDE Update a player’s StatItem value.
INCREMENT Add to or subtract from a player’s StatItem value.
MAX Update a player’s StatItem with a specified value greater than the current value.
MIN Update a player’s StatItem with a specified value lower than the current existing value.

You also can use additionalKey to add more additional information about the player. The additionalKey parameter is added as a suffix to userId and is used to support multi-level players' stat items such as character stat items. If provided, the user's stat items will be saved with the key userId_additionalKey.

# Implementing Statistics Using the Game Server SDK

You can manage your statistics using the Client or Game Server. In this tutorial, you will learn how to set up the SDK using Game Server.

# Create a Single Statistic for a Player

Use the following code to create a new statistic for a player from your game server.

# Create Multiple Statistics for a Player

Use the following code to multiple statistics for a player simultaneously.

# Create Multiple Statistics for Multiple Players

Use the following code to create multiple statistics for multiple players simultaneously.

# Retrieve a Player’s Statistic by StatCodes or Tags

Use the following code to retrieve a player’s statistics by StatCodes or Tags.

# Retrieve All Players’ Statistics

Use the following code to retrieve all players’ statistics.

# Reset Multiple Statistics for a Player

Use the following code to reset multiple statistics for a player to the default values as specified in your game namespace.

# Reset Multiple Statistics for Multiple Players

Use the following code to reset multiple players’ statistics to the default values as specified in your game namespace.

# Update Multiple Statistics for a Player

Use the following code to update multiple statistics for a player using the updating strategy (opens new window) options.

# Update Multiple Statistics for Multiple Players

Use the following code to update multiple statistics for multiple players using the updating the strategy (opens new window) options.

# Connecting Custom Services to Statistics using Server-side SDKs

# SDK Initialization

Before using the Statistics service from the SDK, you will need to initialize your server-side SDK to make you authorized and able to perform create, read, update, and delete actions.

# Golang SDK Initialization

Before using the Statistics from the Golang SDK, you will need to initialize the SDK by following the steps below:

Once completed, you can use the Golang SDK to create, read, update, or delete Statistics (opens new window) from your serverless app.

# Python SDK Initialization

Before using the Statistics service from the Python SDK, you will need to initialize the SDK by following the steps below:

Once completed, you can use the Python SDK to create, read, update, or delete Statistics (opens new window) from your serverless app.

# .NET (C#) SDK Initialization

Before using the Social service, you will need to set some permissions. Use the following .NET namespaces:

using AccelByte.Sdk.Api.Social.Model;
using AccelByte.Sdk.Api.Social.Operation;
using AccelByte.Sdk.Api.Social.Wrapper;

# Java SDK Initialization

Before using the Social service, you will need to set some permissions. Initialize the StatConfiguration wrapper from the Social service using the following code:

StatConfiguration wStatConfig = new StatConfiguration(sdk);

Once completed, you can use the SDK to create, read, update, or delete a player’s statistics from your game client.

# Create a Statistic Configuration

Use the following function to create a statistic configuration (opens new window):

# Delete a Statistic Configuration

Use the following function to delete a statistic configuration (opens new window):

# Retrieve a Statistic Configuration by Stat Code

Use the following function to retrieve a statistic configuration (opens new window):

# Retrieve All Statistic Configurations

Use the following function to retrieve all statistic configurations: (opens new window):

# Search for a Statistic Configuration by Keyword

Use the following function to search for a statistic configuration (opens new window) based on a keyword:

# Update a Statistic Configuration

Use the following function to update a statistic configuration (opens new window):