My company recently wrote a couple of mobile applications. Since one is for consumer use (search for ’8z neighborhood’ in the App Store/Google Play if you live in Colorado or the Bay area and want to check it out), I wanted to know what type of users were downloading and installing it, what was being used, and other general usage statistics.

I asked a mobile app vendor we’ve worked with what they used for usage stats, and they said Flurry. I also looked at Google Analytics, Mobile–this is a nice q&a explaining the major players in the mobile analytics market. We didn’t want anything complicated, just basic stats with the possibility of collecting further information in the future, so I went with the vendor recommendation. Flurry also works with the two platforms we were targeting: IOS and Android, as well as many others.

Flurry is zero cost, but nothing’s free–they want your data and you grant them a “right, for any purpose, to collect, retain, use, and publish in an aggregate manner” all data collected from your application. I’ve seen similar TOS from most of the free analytics vendors, so this was no surprise.

To use Flurry with cordova/phonegap, and with plugman, I was ready to plugmanify an existing Flurry phonegap plugin. Luckily, someone else had already done it. All I had to do was update the plugin to work with Cordova 2.9, and to use the latest IOS7 compatible Flurry library.

After you install the plugin (I recommend doing so in an after_platform_add hook script), you simply add this to your code after the deviceready event fires: window.plugins.flurry.startSession(sessionkey). I inject the session key using a hook script, because I wanted a different key for stage and production builds, and also for each device platform (Flurry requires the latter). Because hooks only get the root directory as context (although this is supposed to change) I had to put some logic in the javascript to call startSession with the appropriate key:

 App.config.flurryid = "";
    if (window.device && window.device.platform) {
        if (window.device.platform == "Android") {
            App.config.flurryid = /*REP*/ 'notreallyanandroidflurryid' /*REP*/ ;
        }
        if (window.device.platform == "iOS") {
            App.config.flurryid = /*REP*/ 'notreallyaniosflurryidxxx' /*REP*/ ;
        }
    }

Although I have not used any of the more specific event tracking, the basic statistics are a great start (including new users, retained users, device versions, etc).

Don’t fly blind when you release your phonegap/cordova mobile app–use Flurry or something simliar.

6 thoughts on “How to collect usage statistics in your phonegap/cordova application

  1. Dmitry says:

    Looks like what I`m looking for but I tried to use it and failed. Can you give a working sample that shows how to use all the functions of the plugin?

  2. moore says:

    Hi Dmitry,

    I’m happy to try to help, but don’t have time to put together an example that uses all the functions.

    What functions failed? What version of Cordova are you using?

  3. Dmitry says:

    Hi,

    I`m using Android, PhoneGap 3.1.0 and JQM. At first I use this:

    Flurry.startSession(‘BRN**********8PV’);

    And it works because I see session data in Flurry!

    Then I tried to add this:

    1.Flurry.logPageView();

    2.1 Flurry.logEvent(‘Footer navigation’);

    2.2 or Flurry.logEventWithParameters(‘Footer navigation’, {button: “Done”});

    2.3 or Flurry.logEventWithParameters(‘Footer navigation’, ‘{button: “Done”}’);

    But none of them works as I see NO data in Flurry.

    The only thing I see is Events log session is:

    Session Time

    Version

    Details

    12/02/13 13:23:18 +0700
    1.3.5 (Android)

    1) uncaught

     

    That`s it :-(

    What am I doing wrong?

  4. Dmitry says:

    Dan? Are you here?

  5. Dmitry says:

    I think I`m just wrong with the usage syntax because there where no samples except the startSession function…

  6. moore says:

    Hi Dmitry,

    Sorry, I didn’t check this comment regularly.

    I am.afraid I have only used the startsession call, and none of the other methods. It is possible that you are using the wrong syntax, but also.possible that the underlying java has changed and the js API hasn’t kept up.

    From a brief examination of your code, I suspect the latter.

    Please file a github issue and include your version of Android as well. I can’t say when someone will get to it, though.

Leave a Reply

Your email address will not be published. Required fields are marked *

 


© Moore Consulting, 2003-2010 +