简体   繁体   中英

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.

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...

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());
});

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:

It all gets so tricky when you talk about offline analytics. Two things pop out at me.. The first being, and I'm not sure if your app is for iOS or Android but Apple has rejected apps because the "app" was nothing more than a wrapper around a mobile website. That is more related to the fact that those apps didn't utilize any core device functionality (no native code).

Second, I realize you mentioned you wanted to stay away from native code but have a look at the GA Mobile SDK. You'll see that GA actually has a method of tracking and saving analytics while a device is offline. When the app has network connectivity, the analytics are then sent to the GA server. This would be a trade off for you, use a little native code but save time because you didn't have to roll your own solution. Cheers!

http://code.google.com/apis/analytics/docs/mobile/overview.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM