What to Track?
This question requires a bit of thought. Since we can track basically anything in the game, it would be wise to prioritize what matters.
As a game developer, I want to know if the player is having the best experience possible. In this case, I want to know if my players are able to complete the levels. If everyone stumbles at the first level, that means it’s too difficult.
Here’s some things we might want to track for this game:
- Player wins/losses: Recorded as an increasing counter. This helps us see how many wins/losses occur – if players are losing too much, might be too hard!
- Level starts & completes: Also recorded as increasing counters. This helps us know if players actually make it to the various levels and complete them. This is different from wins/losses, because a player might just quit the game upon seeing a “You lose” message, and not complete the level or start a new one.
More advanced stuff
- Where monsters escape: You can use Playtonic to record the 2d coordinate points where the monsters escape past the screen. It would be displayed as a heatmap, allowing us to see where most players fail to kill the monsters.
- Dynamic tweaking: Using variables stored on the Playtomic server (called GameVars), we can dynamically change the speed of the monster and/or the speed of our projectiles without recompiling our game. This is a huge advantage for game developers who have shipped a game to the App Store, but don’t want to wait for days to push a new update.
In this tutorial, we’re just going to focus on the basic metric tracking. We may cover the more advanced stuff in a future tutorial, if there’s enough time & interest!
Code for Basic Metric-Trackers
To track player wins, open Cocos2DSimpleGameAppDelegate.m
and import Playtomic.h at the top of the file:
Then add the following line of code to the bottom of the loadWinScene method:
// Track level win (as custom metric) [[Playtomic Log] customMetricName:@"YouWin" andGroup:nil andUnique:NO];
As you can see, logging an integer count metric is as simple as this single line of code, specifying the name of the metric!
Similarly, to track player losses, add the following line of code to the bottom of the loadGameOverScene method:
// Track level loss (as custom metric) [[Playtomic Log] customMetricName:@"YouLose" andGroup:nil andUnique:NO];
Next to track level completes, add the following code to the top of the levelComplete method:
// Track level restart [[Playtomic Log] levelCounterMetricName:@"LevelComplete" andLevelNumber:_curLevelIndex andUnique:NO];
Finally let’s track level starts. A good place to do this is in the method where the game displays a “Get ready” screen for a few seconds when the level begins.
Open up NewLevelScene.m, and import Playtomic.h at the top of the file:
Then inside the init method for the NewLevelLayer add the following line of code:
// Track level win (as custom metric) [[Playtomic Log] customMetricName:@"GetReady" andGroup:nil andUnique:NO];
Time to Play!
Give the game a couple of spins in the emulator. Then log into your Playtomic dashboard, click on the game you added, and look at the Level Metrics and Counter Metrics. Voila, your data is there!
Here’s the link to the live stats of the game (using my own SWFID, GUID and API Key). I made it public so everyone can have a look at it.
Take your time, explore your own data and try to understand what causes it. Look at the different game metrics that you chose to track.
Where to Go From Here?
Hooray! You just acquired the “analytics” mindset of designing games. Keep this with you as you design future games. Playtomic’s iOS documentation explains itself well: read it and you’ll understand very quickly how to implement all the other cool features.
Feel free to download the entire project here, or check out my Github repo. Be sure to replace the SWFID, GUID and API_KEY with your own. If you haven’t got your own, refer to the “Initializing the Components” part of this tutorial to learn how to set up Playtomic.
Note that in my version, I also modified the game rule: upon killing 5 monsters, you progress to the next level.
For further experimentation, have a look at this popular open source game made with Cocos2D. I integrated some cool stuff, like 2d heatmaps and game variables. Download the entire project and look under the hood.
The project will help you understand:
- My analytics mindset.
- How to set up some of the more advanced stuff.
Note: be sure to use your own SWFID, GUID and API KEY.
Hope to see you in my next tutorial. In the meantime, join in the forum discussion below. And have a final chocolate :]
This is a post by Ben Chong, an aspiring iOS game developer living in Indiana.