Skip to main content
All CollectionsPortal Pages
Design | Statistics Rules | User Statistics
Design | Statistics Rules | User Statistics

Measure and track progress of your end-users

Paul Winterhalder avatar
Written by Paul Winterhalder
Updated over 5 years ago

Design

User Statistics are used to track basic statistics that relate to a single user. These are useful to track any lifetime per-user metric that you might need. For example, you can get a sense where your user is focusing his effort in your app, which features he is using the most (or least), and any other long-term stats you may want to track. 

User Statistics also work well in conjunction with Design | Gamification | Milestones to create progressive objectives to improve player retention.
Note that User stats are not automatically reset across a patch, so if Design is looking at these stats to validate behavior change after a Design adjustment, then stats can be reset to the Initial Value for all active users on the stats page. Stats can also be tweaked via user Monitoring.

Implementation

Player stats are stored on the server in key + value pairs, and are accessed via a custom set of operations for maximum performance and concurrency safety. 

Player Stats are also a key building blocks of brainCloud’s Gamification features, and can be created on the brainCloud portal.

Setting up your user Stats

  • Click the [Add Item] button with the plus icon.

  • Enter the name, category, description and type of stat. Stats can be Long or Double values.

  • Set the Minimum Value and Maximum Value range for your app. It is recommended to add range that makes sense for your app, rather than use the theoretical Max and Min long and double values. 

  • Set the Initial Value of the stat. This value can be negative, or greater than zero. For example, if you had a stat to track a user's reputation, it could go start at 1000, and decrement or increment over time. 

  • The Merge Action is what occurs when a user requires to fuse to accounts together. Such as if the sign up to your app via Email, and later signed up a UniversalId, at some point, they might want to bring those two accounts together.

  1. takePrimary - Will take the stat of the main account that survives the merge.

  2. additive - Will sum the two stats together, and create a new value.

Depending on your app and the stat, either takePrimary or additive will make more sense. For example, if you are tracking how many miles a user walked, it would make sense to add those two values together. However, if tracking how fast a user runs, adding two run speeds together wouldn't quite make sense. Unless your end-user did double their pace 😄

  • Be sure to click [Save]!

You don't have to manually create each stat

On the Design | Core App Info | Advanced Settings page you will find the options for "Generate User Statistic Rule Enabled" and "Generate App Statistic Rule Enabled." When enabled, these option will allow you to dynamically make stats from the API Explorer and from your client app.

Viewing, Creating and Editing Stats via the API Explorer

  • If you new to the API Explorer, check out this Help Page for more info.

  • Select [Service]: PlayerStatistics and [Operation]: ReadAllUserStats to view your created stats.

  • Select [Service]: PlayerStatistics and [Operation]: IncrementUserStats to add to your stats.

  • Select [Service]: PlayerStatistics and [Operation]: ProcessStatistics to edit stats with more advanced grammar. Find out more about the options you have with ProcessStatistics in the API Reference.

  • If you enabled "Generate User Statistic Rule Enabled," try creating some new stats in the API Explorer.

  • And before you go, you can also check out and edit all stats an individual player's stats via the Monitoring | User Monitoring | Statistics page.

Writing the code

Now that you created user stats, you will want to increment them in your app.

In your client code

  • Add the brainCloud client to your app.

  • Pair the client with the dashboard.

  • Authenticate your user into brainCloud.

  • Request the current stats with the ReadAllUserStats API call.

  • Increment every stat by 5 with the IncrementUserStats API call.

  • Log the results for debugging.

private BrainCloudWrapper _bc;
private string _wrapperName = "default";
void Start() {
    // Unity
    GameObject go = new GameObject();
    _bc = go.AddComponent<BrainCloudWrapper>();
    _bc.WrapperName = _wrapperName; // optionally set a wrapper-name
    _bc.Init(); // extra data, such as: _appId, _secret and _appVersion, is taken from the brainCloud Unity Plugin.
    DontDestroyOnLoad(go); // keep the brainCloud game object through scene changes
   
    _bc.AuthenticateAnonymous((response, cbObject) => { ReadUserStats(); });
}

Dictionary<string, object> statList = new Dictionary<string, object>();
private int incrementAmount = 5;
void ReadUserStats() {
    _bc.PlayerStatisticsService.ReadAllUserStats((response, cbObject) => {
        var jsonMessage =
            (Dictionary<string, object>) BrainCloud.JsonFx.Json.JsonReader.Deserialize(response);
        var jsonData = (Dictionary<string, object>) jsonMessage["data"];
        var statistics = (Dictionary<string, object>) jsonData["statistics"];
        foreach (var stat in statistics)
        {
            statList.Add(stat.Key, (int)stat.Value + incrementAmount);
        }

        IncrementUserStats();
    });
}

void IncrementUserStats()
{
    _bc.PlayerStatisticsService.IncrementUserStats(statList, (response, cbObject) =>
    {
        Debug.Log("Stats Incremented: " + response);
    });
}

Did this answer your question?