It's life Jim, but not as we know it

2011-02-05

Quick start: Add Google Analytics to your Adobe AIR application in 4 easy steps



Preamble
I've been an advocate of Adobe AIR since I used the eBay "San Dimas" application (AIR was called Apollo, San Dimas became eBay Desktop). The potential to modern, build rich and smart client applications that have all the benefits of a web application (automated application updates) but the elegance and simplicity of a desktop application (native desktop integration) is a great option for developers who want to build modern client/server applications.
Recent developments by Salesforce (database), Amazon (email) and Google (XMPP) only strengthen the value of using AIR for rich client applications backed by cloud based Enterprise services. (AIR doesn't solve everything and modern browsers such as Chrome and Safari have comparable capabilities through their support for HTML5 ).

One of the downsides of using Adobe AIR, and Flash in general, has been the lack of support for Google Analytics. It was something that we severely lacked when we built the desktop gadgets at Oracle (for Siebel and CRM OnDemand). While we could track the downloads from the Oracle site, there was very little else that we could do (short of putting logic into the gadgets themselves to writeback to a web service) to track basic statistics such as how often a gadget was used, what features were used etc.
Lately I've been working with Adobe AIR for Android and have the same requirements for mobile application development.

The wait is over...
The recent addition of the AS3 library for Google analytics now enables any AIR/Flash developer to add Google analytics to their code and gain the same insight that web developers have enjoyed for years. And the other good news is, it is just as easy to add tracking to your mobile or desktop application as it is for a traditional web application.

Get up and running in 4 easy steps

1. Download the tracking library here

2. Add two import statements (tracking class, interface that the GATracker implements) and declare a tracking variable


com.google.analytics.GATracker;
com.google.analytics.AnalyticsTracker;

public var tracker:AnalyticsTracker;

3. Initialise the tracking variable with your Google Analytics tracking token (replace "UA-123-4567" with your own token).


private function onComplete():void
{
tracker = new GATracker( this, "UA-123-4567", "AS3", false );
}

4. Start tracking.


public function onButtonClick():void
{
tracker.trackPageview( "/hello/world" );
}

In this example, every time a user clicks the button, a virtual pageview of "hello world" is sent to the Google Analytics tracking servers.

That's it, you're done!! Of course in your mobile or desktop application you don't have pages etc., but the great thing is that the mechanism is so flexible that you can choose to implement based on your own needs. I used the simple URL scheme to map specific modules and actions.

This post is just enough to get you started. If you want more information, the Google Project can be found in the Google Projects Labs section here.

Brilliant work by the folks who worked on this !! Many thanks !!

2 comments:

  1. Hi, I am trying to implement this to an air desktop project and can't make it work. I found the following statement in GA's site and now I am not sure if this will work.

    Currently, Flash tracking is available for any Flash content embedded in a web page. Tracking of data sent from Adobe Air, Shockwave, or via the Flash IDE (e.g. using Test Movie) is not supported at this time.

    Any thoughts would be very appreciated.

    juanpbm@gmail.com

    ReplyDelete
  2. It's been a while since I've used Adobe AIR so I couldn't comment on the status of the GA library.
    If you cannot find any open sourced hacks out there on github there are two possible work arounds

    1) use the Google Analytics REST API (you will have to use OAUTH2 to access the API) . I found a good post here: http://www.visualab.org/index.php/using-google-rest-api-for-analytics

    2) Adobe AIR could wrap JavaScript - so you could use the regular JS code that you post on web pages and embed that in your AIR project. However, I haven't used that feature since the the days when AIR was called Apollo so it might not be the best approach.

    ReplyDelete