This article assumes you already have a working app and that you have some familiarity with UML.

If you don’t, but would like to get started developing for Ubuntu Touch, head on over to developer.ubuntu.com. A good place to get started is the currency converter app tutorial. Once you’re done, come back and I’ll teach you how to improve your app like a pro.

Collecting data

In order for us to be able to test how our app performs, we need to be able to track what our users do. I’m going to be using Mixpanel, but you could use any service that has an HTTP API available (or roll your own).

Signup takes no time at all

Once you have a Mixpanel account, we can start coding! Make sure you have your Mixpanel token available — it can be found under Project Settings → Management

Mixpanel QML component

We are going to be using the excellent Mixpanel component by Artem Marchenko.

You can add it as a submodule if you’re using git, or you could just copy the src folder directly into your project.

The Mixpanel component is very simple, and I recommend that you read it through to get an idea of how it works.

In short, it takes any event data you feed it, base64 encodes it and sends it off to Mixpanel using their HTTP API.

To make use of it, all you have to do is create a Mixpanel component somewhere in your app where it will stick around for the duration of the session:

A few things to go over here:

mixpanelToken

This probably shouldn’t be committed to version control. If you’re just playing around, having this directly in your source is OK, but keep in mind that your token is secret — add it from an environment variable at build time instead.

userId

The Mixpanel component documentation doesn’t mention this, but you need to supply a unique ID to identify the device/user. Something to note is that it must be the same at each run, or it will appear as a different user in Mixpanel.

There are many ways you can get your hands on a unique ID. Theoretically, the device’s IMEI should be unique, but from what I’ve heard, that isn’t always the case, and it isn’t always available anyway. If you’re developing for Ubuntu Touch, another way is to use a push notification token, but that would require the user to have configured an Ubuntu One account first.

What I would recommend is to generate a uuid and store it somewhere to be used on subsequent runs. It’s not guaranteed to be unique, but it’s unique enough that the risk of a collision is astronomically small.