Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best analytics for a PhoneGap application?

What's the best way to track user actions in a phonegap app? I'm using PhoneGap Build to build a pure JS/CSS/HTML Sencha Touch application, so I have access to nothing else. Google Analytics would only work for connected-activity, and I'm confident that much of my app use happens off the network.

What solutions are out there? I'd be willing to pay for something worth using.

like image 290
Stefan Kendall Avatar asked Dec 29 '11 22:12

Stefan Kendall


3 Answers

Since the accepted answer is invalid as that plugin doesn't exist anymore, I just wanted to mention the plugins I checked for this purpose. There are actually 3 (plus a few more in beta):

  1. https://github.com/phonegap-build/GAPlugin
  2. https://github.com/danwilson/google-analytics-plugin
  3. https://github.com/cmackay/google-analytics-plugin

Tough choice... I have been testing them separately and they all seem to do the job, so probably it's just a matter of preference based pretty much on how you like the way they are used.

None of them mention anything regarding queuing events while the device is offline and dispatching them once the network is available, but GAPlugin has a queue that gets dispatched based on a frequency you can set during initialization, so maybe it can work around the offline problem.

If anybody knows anything regarding this, comments are very welcome. I will try to test them on device once I get some time, cause the iOS simulator doesn't seem to allow me to turn off the wifi...

like image 148
Mike Garcia Avatar answered Nov 17 '22 16:11

Mike Garcia


You can write your own PhoneGap plug-ins (basically a JavaScript to Native code bridge). This would give you the freedom to use any of the current native solutions out there which do have offline support (Webtrends, GA, Flurry, ...).

See : http://wiki.phonegap.com/w/page/36752779/PhoneGap%20Plugins

You would have to create one JavaScript file and one Native file per platform you wanted to support. In your Native code you would do a call to your tracking vendor's SDK.

I used the Android example and just put this example together as a sample. Please be advised this wasn't tested at all or even put into an IDE. I simply edited the provided examples in notepad++ :-)

//Java

public class TrackingPlugin extends Plugin {
    public static final String ACTION="pageView";
    @Override
    public PluginResult execute(String action, JSONArray data, String callbackId) {
        Log.d("Tracking", "Plugin Called");
        PluginResult result = null;
        if (ACTION.equals(action)) {
            try {
                String pageTitle= data.getString(0);
                JSONObject res = new JSONObject();

                SOME_TRACKING_API.Track(pageTitle);

                res.put("status","OK");
                result = new PluginResult(Status.OK, res);
            } catch (JSONException jsonEx) {
                Log.d("DirectoryListPlugin", "Got JSON Exception "+ jsonEx.getMessage());
                result = new PluginResult(Status.JSON_EXCEPTION);
            }
        } else {
            result = new PluginResult(Status.INVALID_ACTION);
            Log.d("TrackingPlugin", "Invalid action : "+action+" passed");
        }
    return result;
}

//JavaScript

/**
 * @return Object literal singleton instance of Track
 */
var Track = function() {
};

/**
  * @param pageTitle The title for a new view
  * @param successCallback The callback which will be called when track call is done
  * @param failureCallback The callback which will be called when track call is done
  */
Track.prototype.pageView = function(pageTitle,successCallback, failureCallback) {
 return PhoneGap.exec(    
      successCallback,    //Success callback from the plugin
      failureCallback,    //Error callback from the plugin
      'TrackingPlugin',   //Tell PhoneGap to run "TrackingPlugin" Plugin
      'pageView',         //Tell plugin, which action we want to perform
      [pageTitle]);       //Passing list of args to the plugin
};

PhoneGap.addConstructor(function() {
    PhoneGap.addPlugin("Track", new Track());
});
like image 45
eSniff Avatar answered Nov 17 '22 16:11

eSniff


Note: This information appears to be out of date for newer versions of PhoneGap. Proceed with caution.

PhoneGap has released a semi-official Google Analytics plugin for utilizing the official Google Analytics SDKs for iOS and Android; for other platforms, you can rely on JavaScript.

Here's the blog post about it.

You can find it in this repository.

Here are the folders for:

  • iOS
  • Android
like image 1
Yahel Avatar answered Nov 17 '22 14:11

Yahel