Statistics
Overview
AccelByte Cloud's 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 Cloud Profile service.
AccelByte Cloud's 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 achievements in the Admin Portal. For a full list of permissions that impact achievements management, see the Social tab of the permissions reference.
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, see our Cloud Authentication and Authorization documentation.
Manage Statistics in the Admin Portal
Create a New Statistic Configuration
In the Admin Portal, go to the Game Management section, expand the Statistics section, and select the Configurations menu.
In the Statistic Configurations window, click the Add Configuration button.
The Add New Configuration form will appear. Fill in the required fields.
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 these Cloud services use player statistics to determine achievement conditions and generate leaderboards.
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
In the Admin Portal, go to the Game Management section, expand the Statistics section, and select the Statistics Value menu.
Search for a player using the by using Email, Display Name, Username or by using User ID search filters. You can input the specific value that corresponds to the user you're looking for.
Click View on the action panel of the desired player.
On the Statistics Values page, you can see detailed information about the player's statistics.
Edit a Player's Statistics
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.
Retrieve Global Statistics
In the Admin Portal, go to the Game Management section, expand the Statistics section, and select the Statistics Value menu.
Switch to the Global tab. Here you'll see the global statistics.
Implement Statistics Using the Client Server SDKs
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.
- Unreal Engine
- Unity
TArray<FString> StatCodes;
StatCodes.Add(FString("coin"));
StatCodes.Add(FString("popularity"));
FRegistry::Statistic.CreateUserStatItems(StatCodes, THandler<TArray<FAccelByteModelsBulkStatItemOperationResult>>::CreateLambda([](const TArray<FAccelByteModelsBulkStatItemOperationResult>& Result)
{
// Do something if CreateUserStatItems has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if CreateUserStatItems has an error
UE_LOG(LogTemp, Log, TEXT("Error CreateUserStatItems, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
List<CreateStatItemRequest> statItems = new List<CreateStatItemRequest>();
statItems.Add(new CreateStatItemRequest
{
statCode = "coin"
});
statItems.Add(new CreateStatItemRequest
{
statCode = "popularity"
});
AccelBytePlugin.GetStatistic().CreateUserStatItems(statItems, result =>
{
if (result.IsError)
{
// Do something if CreateUserStatItems has an error
Debug.Log($"Error CreateUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if CreateUserStatItems has been successful
}
});
Create Multiple Statistics for a Player
Use the following code to create multiple new statistics for a player.
- Unreal Engine
- Unity
TArray<FAccelByteModelsBulkStatItemInc> Data;
FAccelByteModelsBulkStatItemInc Data1;
Data1.statCode = FString("coin");
Data1.inc = 500;
Data.Add(Data1);
FAccelByteModelsBulkStatItemInc Data2;
Data2.statCode = FString("popularity");
Data2.inc = 2500;
Data.Add(Data2);
FRegistry::Statistic.IncrementUserStatItems(Data, THandler<TArray<FAccelByteModelsBulkStatItemOperationResult>>::CreateLambda([](const FAccelByteModelsBulkStatItemOperationResult& Result)
{
// Do something if IncrementUserStatItems has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if IncrementUserStatItems has an error
UE_LOG(LogTemp, Log, TEXT("Error IncrementUserStatItems, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
List<StatItemIncrement> statItems = new List<StatItemIncrement>();
statItems.Add(new StatItemIncrement
{
statCode = "coin",
inc = 500
});
statItems.Add(new StatItemIncrement
{
statCode = "popularity",
inc = 2500
});
AccelBytePlugin.GetStatistic().IncrementUserStatItems(statItems.ToArray(), result =>
{
if (result.IsError)
{
// Do something if IncrementUserStatItems has an error
Debug.Log($"Error IncrementUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if IncrementUserStatItems has been successful
}
});
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.
- Unreal Engine
- Unity
TArray<FString> StatCodes;
StatCodes.Add(FString("Kill"));
StatCodes.Add(FString("Death"));
StatCodes.Add(FString("Assist"));
TArray<FString> Tags;
Tags.Add(FString("Tag1"));
Tags.Add(FString("Tag2"));
Tags.Add(FString("Tag3"));
FRegistry::Statistic.GetUserStatItems(StatCodes, Tags, THandler<FAccelByteModelsUserStatItemPagingSlicedResult>::CreateLambda([](const FAccelByteModelsUserStatItemPagingSlicedResult& Result)
{
// Do something if GetUserStatItems has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserStatItems has an error
UE_LOG(LogTemp, Log, TEXT("Error GetUserStatItems, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
string[] statCodes = { "kill", "death", "assist" };
string[] tags = { "tag1", "tag2", "tag3" };
AccelBytePlugin.GetStatistic().GetUserStatItems(statCodes, tags, result =>
{
if (result.IsError)
{
// Do something if GetUserStatItems has an error
Debug.Log($"Error GetUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetUserStatItems has been successful
}
});
Retrieve All Players' Statistics
Use the following code to retrieve all of your players' statistics.
- Unreal Engine
- Unity
FRegistry::Statistic.GetAllUserStatItems(THandler<FAccelByteModelsUserStatItemPagingSlicedResult>::CreateLambda([](const FAccelByteModelsUserStatItemPagingSlicedResult& Result)
{
// Do something if GetALlUserStatItems has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString ErrorMessage)
{
// Do something if GetAllUserStatItems has an error
UE_LOG(LogTemp, LogTemp, TEXT("Error GetAllUserStatItems, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
AccelBytePlugin.GetStatistic().GetAllUserStatItems(result =>
{
if (result.IsError)
{
// Do something if GetAllUserStatItems has an error
Debug.Log($"Error GetAllUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetAllUserStatItems has been successful
}
});
Reset Multiple Statistics
Use the following code to reset a player's statistic to the default values as specified in your game namespace.
- Unity
List<StatItemReset> resets = new List<StatItemReset>();
resets.Add(new StatItemReset
{
statCode = "coin"
});
resets.Add(new StatItemReset
{
statCode = "popularity"
});
AccelBytePlugin.GetStatistic().ResetUserStatItems(resets.ToArray(), result =>
{
if (result.IsError)
{
// Do something if ResetUserStatItems has an error
Debug.Log($"Error ResetUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ResetUserStatItems has been successful
}
});
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.
- Unity
// Update User Statistics without using additional key
List<StatItemUpdate> updates = new List<StatItemUpdate>();
updates.Add(new StatItemUpdate
{
statCode = "coin",
updateStrategy = StatisticUpdateStrategy.OVERRIDE,
value = 250
});
updates.Add(new StatItemUpdate
{
statCode = "popularity",
updateStrategy = StatisticUpdateStrategy.INCREMENT,
value = 1000
});
AccelBytePlugin.GetStatistic().UpdateUserStatItems(updates.ToArray(), result =>
{
if (result.IsError)
{
// Do something if UpdateUserStatItems has an error
Debug.Log($"Error UpdateUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if UpdateUserStatItems has been successful
}
});
// Update User Statistics using additional key
string additionalKey = "SomeUserId";
AccelBytePlugin.GetStatistic().UpdateUserStatItems(additionalKey, updates.ToArray(), result =>
{
if (result.IsError)
{
// Do something if UpdateUserStatItems has an error
Debug.Log($"Error UpdateUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if UpdateUserStatItems has been successful
}
});
Implement Statistics Using the Game Server SDKs
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.
- Unreal Engine
- Unity
FString UserId = FString("SomeUserId");
TArray<FString> StatCodes;
StatCodes.Add(FString("Kill"));
StatCodes.Add(FString("Death"));
StatCodes.Add(FString("Assist"));
FRegistry::ServerStatistic.CreateUserStatItems(UserId, StatCodes, THandler<TArray<FAccelByteModelsBulkStatItemOperationResult>>::CreateLambda([](const FAccelByteModelsBulkStatItemOperationResult& Result)
{
// Do something if CreateUserStatItems has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if CreateUserStatItems has an error
UE_LOG(LogTemp, Log, TEXT("Error CreateUserStatItems, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
string userId = "SomeUserId";
List<CreateStatItemRequest> statItems = new List<CreateStatItemRequest>();
statItems.Add(new CreateStatItemRequest
{
statCode = "Kill"
});
statItems.Add(new CreateStatItemRequest
{
statCode = "Death"
});
AccelByteServerPlugin.GetStatistic().CreateUserStatItems(userId, statItems.ToArray(), result =>
{
if (result.IsError)
{
// Do something if CreateUserStatItems has an error
Debug.Log($"Error CreateUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if CreateUserStatItems has been successful
}
});
Create Multiple Statistics for a Player
Use the following code to multiple statistics for a player simultaneously.
- Unreal Engine
- Unity
FString UserId = FString("SomeUserId");
TArray<FAccelByteModelsBulkStatItemInc> Data;
FAccelByteModelsBulkStatItemInc Data1;
Data1.statCode = FString("Kill");
Data1.inc = 5;
Data.Add(Data1);
FAccelByteModelsBulkStatItemInc Data2;
Data2.statCode = FString("Death");
Data2.inc = 2;
Data.Add(Data2);
FRegistry::ServerStatistic.IncrementUserStatItems(UserId, Data, THandler<TArray<FAccelByteModelsBulkStatItemOperationResult>>::CreateLambda([](const FAccelByteModelsBulkStatItemOperationResult& Result)
{
// Do something if IncrementUserStatItems has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if IncrementUserStatItems has an error
UE_LOG(LogTemp, Log, TEXT("Error IncrementUserStatItems, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
string userId = "SomeUserId";
List<StatItemIncrement> Increments = new List<StatItemIncrement>();
Increments.Add(new StatItemIncrement
{
statCode = "Kill",
inc = 5
});
Increments.Add(new StatItemIncrement
{
statCode = "Death",
inc = 5
});
AccelByteServerPlugin.GetStatistic().IncrementUserStatItems(userid, increments, result =>
{
if (result.IsError)
{
// Do something if IncrementUserStatItems has an error
Debug.Log($"Error IncrementUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if IncrementUserStatItems has been successful
}
});
Create Multiple Statistics for Multiple Players
Use the following code to create multiple statistics for multiple players simultaneously.
- Unreal Engine
- Unity
TArray<FAccelByteModelsBulkUserStatItemInc> Data;
FAccelByteModelsBulkUserStatItemInc Data1;
Data1.statCode = FString("Kill");
Data1.inc = 5;
Data1.userId = FString("SomeUserId1");
Data.Add(Data1);
FAccelByteModelsBulkUserStatItemInc Data2;
Data2.statCode = FString("Kill");
Data2.inc = 3;
Data2.userId = FString("SomeUserId2");
Data.Add(Data2);
FRegistry::ServerStatistic.IncrementManyUsersStatItems(Data, THandler<TArray<FAccelByteModelsBulkStatItemOperationResult>>::CreateLambda([](const TArray<FAccelByteModelsBulkStatItemOperationResult>& Result)
{
// Do something if IncrementManyUsersStatItems has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if IncrementManyUsersStatItems has an error
UE_LOG(LogTemp, Log, TEXT("Error IncrementManyUsersStatItems, Error Code %d Error Message %s"), ErrorCode, *ErrorMessage);
}));
List<UserStatItemIncrement> Increments = new List<UserStatItemIncrement>();
Increments.Add(new UserStatItemIncrement
{
statCode = "Kill",
inc = 5,
userId = "SomeUserId1"
});
Increments.Add(new UserStatItemIncrement
{
statCode = "Kill",
inc = 2,
userId = "SomeUserId2"
});
AccelByteServerPlugin.GetStatistic().IncrementManyUsersStatItems(Increments, result =>
{
if (result.IsError)
{
// Do something if IncrementManyUsersStatItems has an error
Debug.Log($"Error IncrementManyUsersStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if IncrementManyUsersStatItems has been successful
}
});
Retrieve a Player's Statistic by StatCodes or Tags
Use the following code to retrieve a player's statistics by StatCodes or Tags.
- Unreal Engine
- Unity
FString UserId = FString("SomeUserId");
TArray<FString> StatCodes;
StatCodes.Add(FString("Kill")),
StatCodes.Add(FString("Death"));
StatCodes.Add(FString("Assist"));
TArray<FString> Tags;
Tags.Add(FString("Tag1"));
Tags.Add(FString("Tag2"));
Tags.Add(FString("Tag3"));
FRegistry::ServerStatistic.GetUserStatItems(UserId, StatCodes, Tags, THandler<FAccelByteModelsUserStatItemPagingSlicedResult>::CreateLambda([](const FAccelByteModelsUserStatItemPagingSlicedResult& Result)
{
// Do something if GetUserStatItems has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserStatItems has an error
UE_LOG(LogTemp, Log, TEXT("Error GetUserStatItems, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
string userId = "SomeUserId";
string[] statCodes = { "Kill", "Death", "Assist" };
string[] tags = { "tag1", "tag2", "tag3" };
AccelByteServerPlugin.GetStatistic().GetUserStatItems(userId, statCodes, tags, result =>
{
if (result.IsError)
{
// Do something if GetUserStatItems has an error
Debug.Log($"Error GetUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetUserStatItems has been successful
}
});
Retrieve All Players' Statistics
Use the following code to retrieve all players' statistics.
- Unreal Engine
- Unity
FString UserId = FString("SomeUserId");
FRegistry::ServerStatistic.GetAllUserStatItems(UserId, THandler<FAccelByteModelsUserStatItemPagingSlicedResult>::CreateLambda([](const FAccelByteModelsUserStatItemPagingSlicedResult& Result)
{
// Do something if GetAllUserStatItem has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetAllUserStatItems has an error
UE_LOG(LogTemp, Log, TEXT("Error GetAllUserStatItems, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
string userId = "SomeUSerId";
AccelByteServerPlugin.GetStatistic().GetAllUserStatItems(userId, result =>
{
if (result.IsError)
{
// Do something if GetAllUserStatItems has an error
Debug.Log($"Error GetAllUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetAllUserStatItems has been successful
}
});
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.
- Unity
string userId = "SomeUserId";
List<StatItemReset> resets = new List<StatItemReset>();
resets.Add(new StatItemReset
{
statCode = "Kill"
});
resets.Add(new StatItemReset
{
statCode = "Death"
});
AccelByteServerPlugin.GetStatistic().ResetUserStatItems(userId, resets.ToArray(), result =>
{
if (result.IsError)
{
// Do something if ResetUserStatItems has an error
Debug.Log($"Error ResetUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ResetUserStatItems has been successful
}
});
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.
- Unity
List<UserStatItemReset> resets = new List<UserStatItemReset>();
resets.Add(new UserStatItemReset
{
userId = "SomeUserId1",
statCode = "Kill"
});
resets.Add(new UserStatItemReset
{
userId = "SomeUserId2",
statCode = "Kill"
});
AccelByteServerPlugin.GetStatistic().ResetManyUsersStatItems(resets.ToArray(), result =>
{
if (result.IsError)
{
// Do something if ResetManyUserStatItems has an error
Debug.Log($"Error ResetManyUsersStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ResetManyUserStatItems has been successful
}
});
Update Multiple Statistics for a Player
Use the following code to update multiple statistics for a player using the updating strategy options.
- Unity
string userId = "SomeUserId";
List<StatItemUpdate> updates = new List<StatItemUpdate>();
statItemUpdates.Add(new StatItemUpdate
{
statCode = "Kill",
updateStrategy = StatisticUpdateStrategy.OVERRIDE,
value = 5
});
statItemUpdates.Add(new StatItemUpdate
{
statCode = "Death",
updateStrategy = StatisticUpdateStrategy.INCREMENT,
value = 2
});
AccelByteServerPlugin.GetStatistic().UpdateUserStatItems(userid, statItemUpdates.ToArray(), result =>
{
if (result.IsError)
{
// Do something if UpdateUserStatItems has an error
Debug.Log($"Error UpdateUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if UpdateUserStatItem has been successful
}
});
string additionalKey = "SomeAdditionalKey"
AccelByteServerPlugin.GetStatistic().UpdateUserStatItems(userid, additionalKey, updates.ToArray(), result =>
{
if (result.IsError)
{
// Do something if UpdateUserStatItems has an error
Debug.Log($"Error UpdateUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if UpdateUserStatItems has been successful
}
});
Update Multiple Statistics for Multiple Players
Use the following code to update multiple statistics for multiple players using the updating the strategy options.
- Unity
List<UserStatItemUpdate> updates = new List<UserStatItemUpdate>();
updates.Add(new UserStatItemUpdate
{
userId = "SomeUserId1"
statCode = "Kill",
updateStrategy = StatisticUpdateStrategy.OVERRIDE,
value = 5,
additionalKey = "SomeAdditionalKey1"
});
updates.Add(new UserStatItemUpdate
{
userId = "SomeUserId2",
statCode = "Death",
updateStrategy = StatisticUpdateStrategy.INCREMENT,
value = 2,
additionalKey = "SomeAdditionalKey2"
});
AccelByteServerPlugin.GetStatistic().UpdateManyUsersStatItems(updates.ToArray(), result =>
{
if (result.IsError)
{
// Do something if UpdateManyUserStatItems has an error
Debug.Log($"Error UpdateManyUserStatItems, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if UpdateManyUserStatItems has been successful
}
});
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:
- Create your OAuth Client and assign the necessary permissions to access the IAM service.
- Log in as a Client using the SDK.
- Initialize the OAuth 2.0 service using the following function:
- Golang
statConfigurationService := &social.StatConfigurationService{
SocialServiceClient: factory.NewSocialClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
Once completed, you can use the Golang SDK to create, read, update, or delete Statistics 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:
- Create your OAuth Client and assign the necessary permissions to access the Matchmaking service.
- Log in as a Client using the SDK.
Once completed, you can use the Python SDK to create, read, update, or delete Statistics 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:
- Golang
- Python
- C#
- Java
stat, err := socialService.CreateStat(namespace, body)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.social import create_stat
from accelbyte_py_sdk.api.social.models import StatCreate
result, error = create_stat(
body=StatCreate.create(
stat_code="<your-stat-code>",
name="<your-name>",
default_value=420,
set_by="CLIENT",
),
)
if error:
print(error)
StatConfiguration wStatConfig = new StatConfiguration(sdk);
Api.Social.Model.StatCreate createStat = new Api.Social.Model.StatCreate()
{
Name = "<stat_name>",
Description = "<stat_description>",
StatCode = stat_code,
SetBy = "SERVER",
Minimum = 0.0,
Maximum = 100.0,
DefaultValue = 50.0,
IncrementOnly = true,
SetAsGlobal = false,
Tags = new List<string>()
};
StatInfo? cStat = wStatConfig.CreateStat(
CreateStat.Builder
.SetBody(createStat)
.Build(sdk.Namespace));
StatCreate createStat = StatCreate.builder()
.name(name)
.description(description)
.statCode(statCode)
.setBy(setBy)
.minimum(minimum)
.maximum(maximum)
.defaultValue(default)
.incrementOnly(incrementOnly)
.setAsGlobal(setAsGlobal)
.tags(tags)
.build();
Delete a Statistic Configuration
Use the following function to delete a statistic configuration:
- Golang
- Python
- C#
- Java
err := socialService.DeleteStat(namespace, statCode)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.social import delete_stat
result, error = delete_stat(
stat_code="<your-stat-code>",
)
if error:
print(error)
StatConfiguration wStatConfig = new StatConfiguration(sdk);
wStatConfig.DeleteStat(
DeleteStat.Builder
.Build(sdk.Namespace, "<stat_code>"));
wStatConfig.deleteStat(DeleteStat.builder()
.namespace(namespace)
.statCode(stat_code)
.build());
Retrieve a Statistic Configuration by Stat Code
Use the following function to retrieve a statistic configuration:
- Golang
- Python
- C#
- Java
stat, err := socialService.GetStat(namespace, statCode)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.social import get_stat
result, error = get_stat(
stat_code="<your-stat-code>",
)
if error:
print(error)
StatConfiguration wStatConfig = new StatConfiguration(sdk);
StatInfo? gStat = wStatConfig.GetStat(
GetStat.Builder
.Build(sdk.Namespace, "<stat_code>"));
StatInfo gStat = wStatConfig.getStat(GetStat.builder()
.namespace(namespace)
.statCode(statCode)
.build());
Retrieve All Statistic Configurations
Use the following function to retrieve all statistic configurations::
- Golang
- Python
- C#
- Java
stats, err := socialService.GetStats(namespace, &limit, &offset)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.social import get_stats
result, error = get_stats(
offset=0,
limit=20,
)
if error:
print(error)
StatConfiguration wStatConfig = new StatConfiguration(sdk);
StatPagingSlicedResult? result = wStatConfig.GetStats(
GetStats.Builder
.SetLimit(10)
.SetOffset(0)
.Build(_Sdk.Namespace));
StatInfo gStat = wStatConfig.getStat(GetStat.builder()
.namespace(namespace)
.build());
Search for a Statistic Configuration by Keyword
Use the following function to search for a statistic configuration based on a keyword:
- Golang
- Python
- C#
- Java
stats, err := socialService.QueryStats(namespace, keyword, &limit, &offset)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.social import query_stats
result, error = query_stats(
keyword="<your-keyword>",
offset=0,
limit=20,
)
if error:
print(error)
StatConfiguration wStatConfig = new StatConfiguration(sdk);
StatPagingSlicedResult? result = wStatConfig.QueryStats(
QueryStats.Builder
.SetLimit(10)
.SetOffset(0)
.Build(_Sdk.Namespace, "<keyword>"));
QueryStats queryStats = QueryStats.builder()
.namespace(namespace)
.keyword(keyword)
.build();
StatPagingSlicedResult result = wStatConfig.queryStats(queryStats);
Update a Statistic Configuration
Use the following function to update a statistic configuration:
- Golang
- Python
- C#
- Java
stat, err := socialService.UpdateStat(namespace, statCode, body)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.social import update_stat
from accelbyte_py_sdk.api.social.models import StatUpdate
result, error = update_stat(
stat_code=stat_code,
body=StatUpdate.create(
name="<your-new-name>",
),
)
if error:
print(error)
StatConfiguration wStatConfig = new StatConfiguration(sdk);
StatUpdate updateStat = new StatUpdate()
{
Description = "Updated description."
};
StatInfo? uStat = wStatConfig.UpdateStat(
UpdateStat.Builder
.SetBody(updateStat)
.Build(sdk.Namespace, "<stat_code>"));
StatUpdate updateStat = StatUpdate.builder()
.description("Updated description.")
.build();
StatInfo uStat = wStatConfig.updateStat(
UpdateStat.builder()
.namespace(namespace)
.statCode(stat_code)
.body(updateStat)
.build());