Last Updated: 4/11/2022, 6:30:33 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 Statistics section of the Admin Portal, open the Configurations menu.

    cloud-save

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

    cloud-save

  3. Fill in the required fields.

    cloud-save

    • Input the statistic code in the Code field, following the formatting rules given.
    • 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 select either the 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 Global Statistics

  1. In the Admin Portal, click the Statistics Value menu.

    cloud-save

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

    cloud-save

# Implementing Statistics Using the SDK

# Create a Single Statistic for a Player

You can use SDK to create a statistic for a player from your game server by following the example below.

# Create Multiple Statistics for a Player

To create statistics for a player in bulk, follow the example below.

# Retrieve a Player’s Statistic by StatCode

This example will only retrieve a player's statistic for the specified statCode in a game namespace.

# Retrieving a Player’s Statistic by Tag

This example will only retrieve a player's statistic for the specified tag in a game namespace.

# Update Multiple Statistics for a Player

This example is used to update multiple statistics for a player simultaneously.

# Update Multiple Statistics for Multiple Players

This example is used to update multiple statistics for multiple players simultaneously. This update must be authorized by a user with higher privileges, such as an admin.

# Connecting Custom Services to Statistics using the Server SDK

# 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):