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 of 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
User 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.
User Stats are also key building blocks of brainCloud’s Gamification features and can be created on the brainCloud portal.
Setting up your user Stats
Click the [+] plus icon at the upper-right corner of the list screen.
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 is required to use two accounts. Such as if they sign up to your app via Email, and later sign up a UniversalId, at some point, they might want to bring those two accounts together.
takePrimary - Will take the stat of the main account that survives the merge.
additive - Will sum the two stats together, and create a new value.
Depending on your app and the stat, either taking primary 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, this option will allow you to dynamically make stats from the API Explorer and your client app.
Writing the code
Now that you have 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);
});
}