Countly, Raspberry Pi, and Servos, Oh My!
Paul Brown • May 1, 2013 08:14 PM
TL;DR - I got a Raspberry Pi to do cool things when people use my iOS app. Watch the video below.
I can't even remember where I heard about Countly, but I signed up for my beta account with them on Oct 10, 2012, and probably shipped my app using their service shortly after that. One particularly cool feature (this isn't unique to Countly) is that I can track "events" that occur in my app. As I was developing the free version of Easy Grade, I wanted to know how many times users were prompted to buy, but did not buy, the In-App Purchase. So I made an event for this (as well as for how many ads are shown and how many times people actually do buy the In-App Purchase), and began obsessively watching that dashboard once the app was available in the App Store.
As I stared at the dashboard for longer than I care to admit, I looked at my Arduino and thought it'd be cool to make fun things happen, such as raising a flag or flashing an LED, in response to these events that I had defined. I did a quick search and came across a post about ZipWhip, which raises a flag with an Arduino every time they get a new customer (http://blog.zipwhip.com/2012/02/22/zipwhip-new-user-sign-up-flag/). I wrote some code for the Arduino that pulls from Countly's servers and parses the resulting JSON file, but it proved to be quite a challenge. Maybe I'm just too much of a novice at writing code in Processing (Arduino's language), but it just seemed like more work than it was worth.
Then a coworker got a Raspberry Pi, and I SSH'ed into it (with his permission, of course) and wrote a quick and dirty python script in about 15 minutes that did basically what I wanted, and I was sold. It's amazing how powerful a little tiny Ubuntu server can be! Oh, and Python makes it SUPER easy to parse JSON data. It was even pretty simple to get my servo spinning with the script, and after a bit of tweaking, I finally have something that is presentable. I've posted the code to GitHub here. It's still rough, so be kind! (and please offer suggestions for improvement)
Right now, my code is pretty specific in its use case. I don't have any immediate plans to make it more generic, but who knows what will happen. For now, though, it pulls the count for specific Events that I have defined in Countly, and takes certain actions based on what events are incremented:
Event Name: bannerViewDidLoadAd
iAds are successfully loaded - currently no action, since this number pretty much is always increasing
Event Name: clickedTheIAPCancelButton
Someone is presented with my In-App Purchase dialog and declines it - the servo spins for a time that is relative to the number of times this Event happens
Event Name: transactionComplete
Someone actually purchases the In-App Purchase - the servo spins, like before, but the Raspberry Pi also plays a "chaching" sound file through the audio output.
Here's a video of it actually working. Here it turns the flag and plays a sound, indicating that someone bought my In-App-Purchase:
In closing, I will say that Countly is a great product for mobile app analytics. Their support team is extremely responsive, the data feeds are easy to deal with, and those dashboards are just gorgeous. Every now and then the site seems a little bogged down, but hopefully those are just initial issues and will be resolved as time goes on. I **highly** recommend the service. Their url is [http://count.ly/](http://count.ly/). Also, it's worth noting that I only track this kind of user behavior data for users of Easy Grade Free who haven't upgraded yet. For paid users, I only track the very basic analytics data, like sessions and device/OS versions (so I know when it's acceptable to drop an old OS). And finally, I leave you with some photos of my contraption. I cut some cheap acrylic with a Dremel and hot-glued it together to serve as a prototype. Some day I hope to redesign it and print out a custom enclosure on a 3d printer. UPDATE (2013-05-03):
The servo that I'm using is the [ROB-09347 from Sparkfun](https://www.sparkfun.com/products/9347). And yes, I am currently using a coffee stirrer and a Post-It note as a flag.