Note: Remember you can click/touch over the images in order to enlarge them.
Implementing your own statistics is incredibly useful since you can customize and track all the data you want, you can track any action in your game and create reports based on the data you have captured, reports that will be very useful to analyze game status, players behavior and to make decisions based on your findings.
By combining SQL Reporting Services with Web API 2, you can create a cross platform system.
The only other required component is the actual client which will send the data, in Unity we can take advantage of the WWW class to build the message and post the data to the server.
First, in the server project, we implement a class to handle our data, in this case, we created "
GameSessionStatsModel", since we are tracking per session data.
Then we implement the actual Controller, we named it "
We now proceed to implement the Post action.
In this action, we mark the parameter with
[FromBody] because we have the data in the body of the message we receive, you could have it with
[FromUri] instead in case you are sending the data in the URL.
Now, if you are using Unity, you can take advantage of coroutines, and the WWW class.
In this method, we create an instance of the
WWWForm, we specify that the
Content-Type is going to be in json format with the
To add the field we need to send, we use the
.AddFields methods of the
WWWForm instance object,
the name of the
string must match the exact name of the properties in the class
GameSessionStatsModel implemented before.
Then we build the URL we need to send, by default Web API 2 will be
Since our controller class is named "
GameStatsController" our URL will be
Note: Replace serverurl with your correct URL.
Then, we create an instance of the WWW class, we send the URL and the form as parameters in the constructor, and we use the
yield keyword to execute the request and wait for a response to be received, since in our code we are constantly updating data, we also use
WaitForSeconds, with the desired amount of seconds, in this case we are using 5 seconds for testing purposes.
Now, let's go to the reports.
Use the Business Intelligence templates to create a Reporting project in Visual Studio, and create a new empty report.
|Design Mode |
|Preview Mode |
In this case, we created a report to see how many sessions exist for each single platform we send data from.
Hopefully it has been useful to you.