Beginning a simple stats gathering app in Django

I just pushed a commit to my worksheet generator website containing a new app: something I’m calling “tobystats.” (Guess what my first name is.) The idea is simple: to try and collect the kind of stats that I’d like to have as I think about intentionally growing the site to be useful to more than just myself. (I mentioned the idea already.)

What stats would I like to collect?

In all honesty, this is probably a poorly-conceived project. I mean, I don’t know what I want to know. I do know that I’d like to start working on my landing page and create something of a conversion funnel to attract new users.

To that end, I’d like to know how many people who visit my site either 1) log in (they’re returning users and wouldn’t have clicked through, anway) or 2) click through to a “learn more” or “try it free” page.

Eventually, the same app should also be used for something akin to event logging. I’d like to know how many total worksheets the site has made. (It would be fun to celebrate a thousand worksheets made, or whatever) as well as counting other events. This is not something I’ve added, yet, but will.

How am I doing this?

The goal is to be able to add a single line to the views of pages that I’d like to track. Right now, that line is:

from tobystats import tobystats

tsid = tobystats.process_request(request, 'LandingPage')

And then the tsid string that’s returned is passed through to the template. (tsid stands for “tobystats id”), where it’s appended in the query string in links, like this:

<a href="example.com/link/blah.html?tsid={{ tsid }}">Example link!</a>

So, the idea is simple: when the process_request() function is called, it checks if there’s a tsid already associated with the URL. If there isn’t, we assume this is the first page that’s been loaded and create a new SiteVisit object (SiteVisit is the model I’m using to store the basics of a single visitor–eventually I’ll use some kind of IP geo-lookup to get the city and country of origin and store it there as well) and a PageView is created for that specific page, storing only the name of the page visited (this seemed to make more sense to me thatn URLs) and the date and time. Lastly, the tsid (a random five-character string) is generated and associated with the SiteVisit and returned to the view that called it.

If there’s already a tsid in the query string, it’s even simpler: look up the SiteVisit with the corresponding tsid and create a new PageView object associated with it. Job done!

I still have to make a dashboard

So far, all of the stats reporting available to me is the number of site visits and the number of those which were successful logins (the idea is that we’re going to only worry about what happens to visitors who don’t login–they’re the ones at whom the messaging is directed).

There’s a lot more to look at: how many visitors are identified by django-user-agents as bots (turns out that, within moments of uploading my stats, I was seeing referer spam), how many of the non-bots clicked through to the “learn more” page. If each step in the signup/initiation process is logged, it would be interesting to see how any people get fatigued by it and at what point. (Also, with geo-lookup, I could skip a step in the signup process).

It’s just a start

I’m sure there is more I can do–see the comment above about using geo-lookup for IP addresses. However, it was important to me to push something to the production site as soon as possible to just get a baseline for current usage. After all, if I don’t measure now, how will I know how many more visits are coming?

Also–and this may be the point of the whole thing–it’s nice to have a coding project to tinker with as I have time.

It doesn’t have to be on your phone

After completing the django girls workshop — I still want to do the part with authentication — I’ve been looking for a ‘minor’ project to code as a web app. (That’s in quotes, because I think they all grow.)

I’d thought about a beer calculator — for brewing, how much grain to how much water, that sort of thing — but there are plenty of good ones out there.

And then I realized, in my lifetime (not that long!) we’ve gone from assuming things will be websites (“Ha, you could call it ‘myidea.com’!“) to assuming they’ll be apps (“That’d be a great app!“) But that’s probably because we read more about apps.

I’d had the idea for the Fantasy Pilgrimage for a while. Of course I imagined it as an app — after all, I think like many other people — but there was nothing to say that it would have to be.

Here’s the idea (of course, read the page on Fantasy Pilgrimage). But, it seems like a rough draft of the site would be a success if it could do a few basic things:

  1. Use the Google authentication service
  2. Connect to Google Fit to get fitness data.
  3. Calculate total distance traveled since a given date, towards a total.
  4. Display that as a percentage.

Of course, with time, I’d like to use Google Maps and display the progress. But, hey, first thiings first.