> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart on statistics

> PlayFab Statistics quickstart shows how to define a statistic, write player values, and read results using the SDK to bootstrap progression tracking.

# Quickstart statistics

In this guide, we're going to see how to set up the development environment for the Statistics service. We're also going
to learn how to create a quick leaderboard from our website [Game Manager](https://developer.playfab.com).

## Prerequisites

We're going to need a PlayFab account to use the PlayFab Statistics service. For instructions to create an account,
see [Authentication](/services/playfab/identity/dev-identity/authentication/aad-authentication).

## Creating a Statistic

We're going to select Progression on the left menu.

<img src="https://mintcdn.com/microsoft-4404708b/N3T1ucKV7zIMBudj/images/playfab/player-progression/statistics/game-manager-main-menu.png?fit=max&auto=format&n=N3T1ucKV7zIMBudj&q=85&s=f8afb627f579da6ba1f9677d3296a3ee" alt="PlayFab Statistics main menu" width="1280" height="900" data-path="images/playfab/player-progression/statistics/game-manager-main-menu.png" />

We now select Statistics tab from the upper menu.

<img src="https://mintcdn.com/microsoft-4404708b/N3T1ucKV7zIMBudj/images/playfab/player-progression/statistics/statistic-menu.png?fit=max&auto=format&n=N3T1ucKV7zIMBudj&q=85&s=78393c583a8ff1afaf920b9bde60eaa7" alt="PlayFab Statistics add statistic" width="1280" height="900" data-path="images/playfab/player-progression/statistics/statistic-menu.png" />

After that, we're going to go "New Statistic" button and create our statistic definition.

<img src="https://mintcdn.com/microsoft-4404708b/N3T1ucKV7zIMBudj/images/playfab/player-progression/statistics/new-statistic.png?fit=max&auto=format&n=N3T1ucKV7zIMBudj&q=85&s=16b828e676d1bede541bcb9331dbe133" alt="PlayFab Statistics Usage" width="1239" height="888" data-path="images/playfab/player-progression/statistics/new-statistic.png" />

Here we're able to configure every aspect of the statistic. Learn more about the parameters available and
how to create statistics here:

* [Create Basic Leaderboard](/services/playfab/player-progression/statistics/create-basic-statistics).
* [API Reference](/services/playfab/player-progression/statistics/api-reference)

The final result should be like this.

<img src="https://mintcdn.com/microsoft-4404708b/N3T1ucKV7zIMBudj/images/playfab/player-progression/statistics/stat-result.png?fit=max&auto=format&n=N3T1ucKV7zIMBudj&q=85&s=1c145637328915af6a2a81ef56ecccd8" alt="PlayFab Statistics final result" width="1872" height="822" data-path="images/playfab/player-progression/statistics/stat-result.png" />

## Setting up the environment

Here we're going to learn how to set up the developer environment to use the C# SDK, but the concepts
presented here can also work with other SDKs or plain HTTP requests.

## Setting TitleId and DeveloperSecretKey

DeveloperSecretKey is needed when authenticating as Title Entity.

```C# theme={null}
PlayFabSettings.staticSettings.TitleId = ""; // Change this value to your own titleId from PlayFab Game Manager
PlayFabSettings.staticSettings.DeveloperSecretKey = ""; // Change this to your title's secret key from Game Manager
```

## Creating a title and getting the secret key

* Log in to [https://developer.playfab.com/](https://developer.playfab.com/)
* Create a title
  * Find the Title ID in the API Features section under settings.
* Generate secret key:
  * Cog next to title name in top left of title view
  * Title Settings
  * Secret Keys
  * New secret key

Here's how the UI looks like when you find the Secret Key section within Game Manager.

<img src="https://mintcdn.com/microsoft-4404708b/N3T1ucKV7zIMBudj/images/playfab/player-progression/statistics/secret-keys.png?fit=max&auto=format&n=N3T1ucKV7zIMBudj&q=85&s=864e20d34e00d5eb96b9a392c7cc8e0b" alt="PlayFab Statistics keys" width="2541" height="1152" data-path="images/playfab/player-progression/statistics/secret-keys.png" />

## Login as Title

For write operations we recommend using the TitleEntity from your game server, this method is going to return the `AuthenticationContext` that is
going to be used across all the requests we made.

```C# theme={null}
public static async Task<PlayFabAuthenticationContext> LoginAsTitleEntity()
{
    GetEntityTokenRequest request = new GetEntityTokenRequest()
    {
        Entity = new PlayFab.AuthenticationModels.EntityKey()
        {
            Id = PlayFabSettings.staticSettings.TitleId,
            Type = "title",
        },                
    };

    PlayFabResult<GetEntityTokenResponse> entityTokenResult = await PlayFabAuthenticationAPI.GetEntityTokenAsync(request);

    PlayFabAuthenticationContext authContext = new PlayFabAuthenticationContext
    {
        EntityToken = entityTokenResult.Result.EntityToken
    };
    
    return authContext;
}
```

## Login as Player (create Player)

Log in as the player for read operations directly against PlayFab APIs. This method is going to return the `AuthenticationContext` that is
going to be used across all the requests we made.

```C# theme={null}
private static async Task<PlayFabAuthenticationContext> LoginAsPlayer(string customId = "GettingStartedGuide")
{
    LoginWithCustomIDRequest request = new LoginWithCustomIDRequest { CustomId = customId, CreateAccount = true };

    PlayFabResult<LoginResult> loginResult = await PlayFabClientAPI.LoginWithCustomIDAsync(request);

    return loginResult.Result.AuthenticationContext;
}

```

## Set the display name property for an entity

In order to have the `DisplayName` property available as part of the response of the Get Statistics APIs,
we need to execute the following code per each entity that we have created. This process is going to map the entity to the custom
display name of the game.

```C# theme={null}
private static async Task UpdateEntityDisplayName(PlayFabAuthenticationContext context, string customId)
{
    SetDisplayNameRequest request = new SetDisplayNameRequest()
    {
        AuthenticationContext = context,
        DisplayName = customId,
        Entity = new PlayFab.ProfilesModels.EntityKey()
        {
            Id = context.EntityId,
            Type = context.EntityType,
        },
    };

    PlayFabResult<SetDisplayNameResponse> updateNameResult = await PlayFabProfilesAPI.SetDisplayNameAsync(request);

}
```

## See also

* [Create basic statistics](/services/playfab/player-progression/statistics/create-basic-statistics).
* [Doing more with statistics](/services/playfab/player-progression/statistics/doing-more-statistics).
* [Seasonal statistics](/services/playfab/player-progression/statistics/seasonal-statistics).
* [Add contextual data to statistics](/services/playfab/player-progression/statistics/metadata-statistics).
* [Transactional writes](/services/playfab/player-progression/statistics/transactional-writes)
* [API reference](/services/playfab/player-progression/statistics/api-reference).
* [Limits](/services/playfab/player-progression/statistics/limits-statistics).
* [Quota](/services/playfab/player-progression/statistics/quota-statistics)
* [Statistics meters](/services/playfab/pricing/meters/statistics-meters).


## Related topics

- [PlayFab Statistics overview](/services/playfab/player-progression/statistics/index.md)
- [Create a basic statistic](/services/playfab/player-progression/statistics/create-basic-statistics.md)
- [Quickstart](/services/playfab/economy-monetization/economy-v2/quickstart.md)
- [Quickstart on leaderboards](/services/playfab/community/leaderboards/quickstart-leaderboards.md)
- [Tournaments & Leaderboards quickstart](/services/playfab/community/leaderboards/tournaments-leaderboards/quickstart.md)
