Skip to main content

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

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

Post a Comment

Popular posts from this blog

Host a static website on Google Drive (in 5 easy steps)

You need to host a static website but don't have the time, money or resources to set up a web server.  Perhaps you're learning to code or just doing a demo. Here's a way to set up a web site at no cost, in just a few minutes. Step 1. Create a new folder in Google Drive. From Google Drive, Click 'Create', select 'Folder' and enter the folder name. (I chose 'hybrid' for this example, but you can choose anything you want). Step 2. Share the folder. First select the folder you created (displayed in the folder list), then click the sharing icon. In the Sharing Settings popup, go to the 'Who has access' section and click 'Change' The Visibility options pop up will appear. Change the Visibility option to 'Public on the web'.  Although set by default, make sure that 'Access' is set to 'Can view'. Click 'Save'. The folder is now shared. Click D...

How to get the BBC iPlayer running when you live outside of the UK

(subtext: Get the World's most famous detective on your favourite browser) The new series of Sherlock has started on the BBC. If you live outside of the UK and you are too impatient to wait for your local TV content provider to host it for you - then fear not !! These simple instructions will get you up and running. In addition to the iPlayer you can access most of the other UK TV channels using the same method. Note: you can use the same method to access content in other countries - such as Hulu in the U.S. How it works:  In simple terms, the BBC iPlayer, like other players, perform a check to determine whether your internet access is originating from the UK.  So the trick is to ensure that your access to the BBC website will originate from the UK. First you are going to use a free piece of open source software that was designed to keep your internet access anonymous. You will add a setting that will ensure that the software makes use of servers in the UK whenever ...

Skip the grunt work: Use AI to turn raw data into Slides (Part 1)

Scenario You've got to create a presentation using data from multiple CSV files. Typically, this means merging files into a single spreadsheet, generating charts, and copying everything into your presentation—an absolute time sink! Let’s fix that. Here’s a free, no-code approach using Google Workspace tools and a sprinkle of automation. This is Part 1 of a two-part series. The Problem Simplified: Multiple CSV files in a consistent format (I used stock data). The goal: Combine into one Spreadsheet for easy analysis and charting. How: Instead of manual copy-pasting, we’ll automate the process using Google Apps Script and Chat-GPT for code generation. What You'll Need: Google Apps account: A free Gmail account will work perfectly. Access to Google Drive , Google Sheets , and Google Slides. Chat-GPT 's free edition for code snippets. Step-by-Step Solution: 1. Collect your data Upload the CSV files to Google Drive. Copy the Drive folder ID. The folder ID is the part of the URL ...