Articles

Tracking user activities inside your application with the Tracker

In every campaign we create we implement some mechanism to measure what the user is doing with and within our application. After all, we want to see the results and be able to have a good analysis of the application’s efficiency. We use a variety of techniques, depending on the client’s wishes: Google analytics, webtrends, dmfacts or a custom implementation where we log stuff via our custom logging framework.

What all these implementations have in common is the necessity to be able to track stuff from within flash in a generic way. We only want to do a little customization for every application, while using the same method to track or log stuff in every application. For this purpose we created the nl.dpdk.log.statistics package.

In essence, the only thing we have to track is a unique identifier for the action we want to measure. We use a human readable string for this, which uses some application specific naming convention like “button_client_url, button_register, button_login, enter_lobby, enter_main” etcetera.
When using this in code, we want to be able to use this from every class in our application. Therefore we chose a static implementation that can be reached and called from everywhere in our application’s code.

//track the click on the button where you are sent to the client's website
//this code is most probably called in an event handler for the button click.
Tracker.track("button_client_url");
 
//somewhere else..
Tracker.track("enter_lobby");

The ITracker interface needs to be implemented by a concrete class that provides the tracking behaviour. ITracker contains this method:

function track(what : String) : void;

An implementation of this interface will implement this method the way that best suits your tracking mechanism.

The only thing that is left to do is to configure the Tracker class itself with an instance of ITracker, which is an implementation that is specific for our application. This will probably be done in your main application class. The nl.dpdk.log.statistics package contains 2 default implementations; one using flash remoting and the other one javascript.

/* 
Set the default javascript tracker (an ITracker implementation), which calls a javascript method in the html container. 
In this case, the js method 'trackMe'. 
The argument in each Tracker.track() call is passed to the 'trackMe' method
*/ 
Tracker.setTracker(new JavascriptTracker('trackMe'));
Tracker.track("hello world from flash to javascript's 'trackMe()' method");

The ITracker that is set on Tracker is the JavascriptTracker. Tracker delegates the tracking to the implementation of ITracker, which handles all further logic to make the measurement. In this case, the JavascriptTracker uses flash.external.ExternalInterface to make a call to a javascript method defined in the html page where our flash movie is in. The javascript method that is called might very well route the request to a javascript implementation like webtrends, or some other implementation that you are using. It might look something like this:

function trackMe(what){
   alert("trackMe received something from flash: " + what);
   //and the routing to webtrends here...
}

It’s very easy to create your own implementation of an ITracker, where you add your own logic. You can use stuff like:

  1. sending xml somewhere
  2. using alternate methods of sending or storing the information
  3. adding more information in the ITracker implementation like resolution, bandwidth measurement, time etc
  4. making calls to multiple tracking systems while just making one call to Tracker.track()
  5. Dynamically add the names of events you would like to measure eg: Tracker.track(”button_” + i)

And all the time, Tracker.track() encapsulates the mechanism by which the application tracks it’s information. Your classes do not know anything about javascript, remoting or whatever implementation you are using. They just track stuff :)

Don’t be the one that has to tell your client that you do not know what has happened in his campaign. Use a mechanism to track your user’s activity. We do!

1 Response to “Tracking user activities inside your application with the Tracker”


  1. 1 Ian

    I’m right on the edge of writing some set of classes like this myself. I’m sick of having to go back and dig up information on tracking suites that I’m only called on to use at most once every few months. It would be so much easier to do flash tracking if I had a generic interface for making calls.

Leave a Reply