{"id":1311,"date":"2013-09-03T12:02:13","date_gmt":"2013-09-03T18:02:13","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=1311"},"modified":"2013-08-28T06:14:07","modified_gmt":"2013-08-28T12:14:07","slug":"how-to-collect-statistics-in-your-phonegapcordova-application","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/1311","title":{"rendered":"How to collect usage statistics in your phonegap\/cordova application"},"content":{"rendered":"<p>My company recently wrote a couple of mobile applications. Since one is for consumer use (search for &#8216;8z neighborhood&#8217; 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.<\/p>\n<p>I asked a <a href=\"http:\/\/www.mobilerealtyapps.com\/\">mobile app vendor<\/a> we&#8217;ve worked with what they used for usage stats, and they said <a href=\"http:\/\/www.flurry.com\/\">Flurry<\/a>. I also looked at <a href=\"http:\/\/www.google.com\/analytics\/features\/mobile.html\">Google Analytics, Mobile<\/a>&#8211;this is a <a href=\"http:\/\/www.quora.com\/Flurry-vs-Mixpanel-vs-Google-Mobile-Analytics-who-wins-Why\">nice q&amp;a explaining the major players<\/a> in the mobile analytics market. We didn&#8217;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.<\/p>\n<p>Flurry is zero cost, but <a href=\"http:\/\/www.lyricsfreak.com\/s\/stevie+ray+vaughan\/crossfire_20131659.html\">nothing&#8217;s free<\/a>&#8211;they want your data and you grant them a <a href=\"http:\/\/www.flurry.com\/analytics_tos.html\">&#8220;right, for any purpose, to collect, retain, use, and publish in an aggregate manner&#8221;<\/a>\u00a0all data collected from your application. I&#8217;ve seen similar TOS from most of the free analytics vendors, so this was no surprise.<\/p>\n<p>To use Flurry with cordova\/phonegap, and with plugman, I was ready to <a href=\"\/wordpress\/archives\/1207\">plugmanify<\/a> an <a href=\"https:\/\/github.com\/jfpsf\/flurry-phonegap-plugin\">existing Flurry phonegap plugin<\/a>. Luckily, someone else had <a href=\"https:\/\/github.com\/CarsonF\/flurry-phonegap-plugin\">already done it<\/a>. All I had to do was <a href=\"https:\/\/github.com\/8zrealestate\/flurry-phonegap-plugin\">update the plugin<\/a> to work with Cordova 2.9, and to use the latest IOS7 compatible Flurry library.<\/p>\n<p>After you install the plugin (I recommend doing so in an <code>after_platform_add<\/code> hook script), you simply add this to your code after the <code>deviceready<\/code> event fires: <code>window.plugins.flurry.startSession(sessionkey)<\/code>. I inject the session key <a href=\"\/wordpress\/archives\/1197\">using a hook script<\/a>, 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\u00a0<a href=\"https:\/\/issues.apache.org\/jira\/browse\/CB-4591\">supposed to change<\/a>)\u00a0I had to put some logic in the javascript to call <code>startSession<\/code> with the appropriate key:<\/p>\n<pre> App.config.flurryid = \"\";\r\n    if (window.device &amp;&amp; window.device.platform) {\r\n        if (window.device.platform == \"Android\") {\r\n            App.config.flurryid = \/*REP*\/ 'notreallyanandroidflurryid' \/*REP*\/ ;\r\n        }\r\n        if (window.device.platform == \"iOS\") {\r\n            App.config.flurryid = \/*REP*\/ 'notreallyaniosflurryidxxx' \/*REP*\/ ;\r\n        }\r\n    }<\/pre>\n<p>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).<\/p>\n<p>Don&#8217;t fly blind when you release your phonegap\/cordova mobile app&#8211;use Flurry or something simliar.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My company recently wrote a couple of mobile applications. Since one is for consumer use (search for &#8216;8z neighborhood&#8217; in the App Store\/Google Play if you live in Colorado or [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47,57,7,60,33],"tags":[],"class_list":["post-1311","post","type-post","status-publish","format-standard","hentry","category-8z","category-android","category-mobile-technology","category-phonegap","category-useful-tools"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1311"}],"version-history":[{"count":6,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1311\/revisions"}],"predecessor-version":[{"id":1317,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1311\/revisions\/1317"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}