Analytics and Logging Ideas

A couple weeks back I threatened to start making more regular posts. This is a threat I make from time to time and sometimes, like now, I actually follow through with it. In that same post I also alluded to some of the ways I’ve been using Parse and Dropbox while developing my game and that’s what I wanted to write about today.

First, Parse. I just want to touch on it briefly. Parse is primarily used to store / sync your app’s data in the cloud but offers an assortment of additional features to make things like push notifications and in app purchase easier to implement. It does these things well, but I’m using the data storage mechanism to create custom analytics. Parse encapsulates arbitrary key-value pairs in PFObjects which can be easily pushed up to their servers in near real time assuming you have an active network connection. Okay so perhaps this is an obvious use case, but I’m using PFObjects to note an assortment of information about each level that’s being played in the game I’m working on. It’s super easy to add a name, score, game-time, wall-time, result, etc., etc. to an object and store it for each attempt made on a level. I can then filter and analyze these results using their dashboard and see how long it takes a player to complete a level, or if they’ve giving up, got killed, etc., etc. Whatever information I feel is valuable is stored and easily accessible as I iterate over game and level design. Very easy to use and extensible. Plus it’s free (up to a point). Free is nice.

Okay next I really wanted to talk about how I used Dropbox to enable logging from multiple devices. So my problem was this: I needed to debug several devices simultaneously and it’s a bit of a pain to do this in Xcode especially when those devices may not be in the same room / city / state. I think TestFlight and maybe some others offer remote logging but these solutions weren’t exactly what I needed. Specifically I needed to start a multiplayer match with N-players and have an individual log created by each of the players in the match and deposited in a central location so I could reconcile any differences between them. I also needed this information as soon as the match completed.

It turns out that I was able to use Dropbox to do exactly this. I put together a demonstration project on github that you can grab and follow along if you like. Once you have that, head over to dropbox’s developer page and add a new app. Set up your app using the Dropbox API with Files & Datastores limited to its own private folder. I called mine QSLog. I don’t think you can reuse that name but if not it doesn’t really matter. Call it whatever. The important bits are the App key and App secret that you’ll find after you create the app. Copy those values and update the corresponding defines at the top of QSAppDelegate.m. Also replace db-appkey in QSLog’s URL Types with db-whateveryouractualappkey is. So far we’re pretty much following this basic Dropbox tutorial.

At this point you should be able to compile and run the app from Xcode. When you do, it should present you with a Dropbox connect screen. Log in and then check the console in Xcode for the User ID, accessToken, and accessTokenSecret. Take these values and again update the corresponding defines at the top of QSAppDelegate.m. Lastly change line 18 QSLog-Prefix.pch to #define HAVE_DROPBOX_TOKENS 1. Recompile and run the app again. Tap some of the Log Event buttons. When your ready tap the Upload / Reset button. That should upload a history of the button presses and reset the log. You should have a folder for your app in your Dropbox/Apps folder containing this log. And you should be able to run this app from any device and have the logs appear in the same folder.

Voila! Which is French for… Ta Da!

Okay a couple final thoughts. First, you really don’t want this in any shipping code. Actually I’m not even sure you want it in test code for an extended period of time. And second, the logging class in the sample project is really simple and you’ll probably want to replace it with something a little better. This is just something I whipped up for demonstration purposes.