Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Tracking implementation  (Read 6983 times)
eco_bach
Courseware Beta
Sr. Member
***
Posts: 81


View Profile Email
« on: July 22, 2009, 04:17:02 »

In several projects I have worked on tracking logic has been requested by the client AFTER the site went live, ie tracking was never part of the original functional spec.
By tracking I mean all user interaction such as button clicks, form entries, and, if the site is composed of subsections, sections viewed, as well as client specific hardware-software data accessible via the Flash api.
For instance Google Analytics
http://www.insideria.com/2009/02/using-google-analytics-within.html

Can someone tell me if tracking can be easily implemented in a PureMVC application AFTER the project is complete, and if so, would any of the original 'actors'(proxies, mediators, controllers) have to be modified, or would they be supplemented with additonal actors?
For example, I assume it would make sense to have an additonal 'TrackingProxy' but not sure if existing mediators would need to be modified or if there was some other way.
Logged
stinkyian
Newbie
*
Posts: 4


View Profile Email
« Reply #1 on: July 23, 2009, 02:17:09 »

Well, the way I handle tracking is by having a tracker command that accepts a vo in the body of its notification with all the required data. The command calls the relevant methods in the tracking proxies (GoogleAnalyticsProxy, OmnitureProxy etc) for tracking events/page views etc.

We sometimes have to incorporate more than one tracking vendor in the same app so this approach works well in that way, only having one call to track stuff. In that way it's also easy to tweak what is tracked by the various tracking systems - for example only tracking errors in our GA account and not in the client Omniture account.

You will need to insert some code wherever you need to track something. Depending on how your app is structured that might be in a command that handles swfaddress and/or in mediators that deal with forms etc. Here's some examples of what our calls look like:

sendNotification( ApplicationFacade.TRACK, new TrackerVO( TrackerTrackType.PAGE_VIEW, address ) );

sendNotification( ApplicationFacade.TRACK, new TrackerVO( TrackerTrackType.EVENT, "", "Share", trackingTag) );

sendNotification( ApplicationFacade.TRACK, new TrackerVO( TrackerTrackType.EVENT, null, TrackerEventCategory.ERRORS, errorMsg ) );

Would be interested to hear how others approach this, as I'm sure someone may have a more elegant solution.

Ian
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: July 26, 2009, 10:37:23 »

How you approach it will depend on how your app already handles internal navigation.

If you have a formal navigation object and are using deep linking (for example see the common/model/vo/NavigationVO in the original code for the Sea of Arrows site: http://seaofarrows.com/srcview) you might already have a natural mechanism in place that just needs to be reworked a little.

In fact, I have Google Analytics on the site already, and have been thinking of adding internal tracking to it. Since the site uses deeplinking, There is only one URL and all the playlists and tracks are different html anchors. So as you go from track to track (automatically or by clicking), Google isn't notified, since its not another page load. So for this project, I will probably extend the existing navigation mechanism to make a call to Google's API with the info in the NavigationVO.

If you're using the StateMachine utility, it might be something that is triggered from the StateMachine.CHANGED notification, so that you can see people moving from state to state within the app. Another natural hook, but entirely tied to the implementation.

If you have no overall state management and are just wanting a generic hook into the user's interaction with the view, you could write an AbstractMediator class that extends Mediator and is the superclass for all other Mediators in your app. It would override onRegister to fetch a local reference to a TrackingProxy which exposes a track method. It would also add a protected track method that is then inherited by your Mediators.

In AbstractMediator:
:
protected var trackingProxy:TrackingProxy;
override public function onRegister():void
{
   trackingProxy = facade.retrieveProxy(TrackingProxy.NAME);
}

protected function track(action:String):void
{
   trackingProxy.track(action);
}
So then, in any Mediator

:
private function onSaveUpdatedProfile(event:Event):void
{
   this.track(TrackingConstants.UPDATED_USER_PROFILE); // track the action
   profileProxy.saveUpdatedProfile(profilePanel.profile); // do the actual work
}

Or, if you are mainly interested in tracking the flow of notifications within the system could always have your concrete Facade override the sendNotification method, causing a direct call to the trackingProxy.track method.

It would try to retrieve the TrackingProxy and if not null, call its tracking method. This is simple, but any notifications that are sent before the TrackingProxy is registered (i.e. STARTUP) just aren't tracked.

In ApplicationFacade:
:
override public function sendNotification( notificationName:String, body:Object=null, type:String=null ):void {
   var trackingProxy:TrackingProxy = this.retrieveProxy(TrackingProxy.NAME);
    if (trackingProxy != null) trackingProxy.track(notificationName);
    super(notificationName,body,type);
}

-=Cliff>
« Last Edit: November 22, 2009, 09:18:22 by puremvc » Logged
Pages: [1]
Print