Telemetry for Indie Games: Posting Basic Data

If want to find out how to implement a quick telemetry system, or just want to me nosey about how I used Django to create a telemetry system for Polyology, then this post is for you.


One of the various tag lines is “Django makes it easier to build better Web Apps more quickly and with less code.” which I can’t help but agree with. It does take some time to setup and learn but once you know Django you’ll be able to quickly create and extend your telemetry system. It has solid documentation and a lovely tutorial for getting you started on their website (disclaimer – This article was written using Django 1.4).

Uploading data from the game

Below is a small snippet of javascript code for uploading some bit of information, some thing like a player has loaded a level, restarted or quit your game. It ties in some situational information, the set and level, where the event occurred. Then it’s a fairly trivial matter of sprinkling your code with PostTelemetry calls in suitable places, and you can extend it with new telemetry without changing any web server code.

function PostTelemetry(statName)
    var formData = new FormData();
    formData.append("levelset", gLevelSystem.GetLevelSet())
    formData.append("level", gLevelSystem.GetLevelName())
    formData.append("stat", statName);

    var xmlhttp = GetXMLRequest();"POST", "/telemetry/", true);

Handling the data on the server

Django lets you define models, layouts of how information will be defined, this is a quick model for some generic telemetry. In this case it’s just a couple of short reference strings and an integer (and a cheeky increment function for later on).

class Telemetry(models.Model):
  levelset = models.CharField(max_length=32)
  level = models.CharField(max_length=32)
  stat = models.CharField(max_length=32)
  value = models.IntegerField()

  def increment(self):
    self.value = self.value + 1;

Then when a post comes in simply increment the existing telemetry, if it doesn’t exist add a new one.

def telemetry(request):
  if request.method == 'POST':
    _set = request.POST['levelset']
    _level = request.POST['level']
    _stat = request.POST['stat']
    if (_set and _level and _stat):
        query = Telemetry.objects.get(levelset=_set, level=_level, stat=_stat)
      except ObjectDoesNotExist:
        newTelem = Telemetry(levelset=_set, level=_level, stat=_stat, value = 1)

Administrating the data

If you add a quick Admin class, saying what is displayable and filterable

class TelemetryAdmin(admin.ModelAdmin):
  list_display = ('stat', 'levelset', 'level', 'value')
  list_filter = ('stat', 'levelset', 'level')

Django will give you a admin site, setting you add, edit, delete telemetry as well as filtering and sorting.

Django Admin Site


So that’s it, that’s most of the code for the telemetry, and you can just add new post calls and everything is just handled. Every indie dev out there should have a simple, extensible web framework for telemetry. If you don’t have one, I’d try Django and see what you think.

Finally I’d like to thank Mark Tully for introducing me to Django in the first place.