During development of the current group of Flash applications on macromedia.com, I was assigned the task of developing a system where our apps could log events with Omniture, which Macromedia uses for an analytics platform.
Omniture is a client-based analytics platform that uses information stored in both JavaScript variables and the user's cookie to track a user's progress through a site, giving business insight into how to create better user experiences.
My recent experience developing Flex applications for use internally at Macromedia prompted the Flex team to ask if I was interested in writing an article and developing an accompanying demo to show Flex users how they could implement a client-based analytics platform from a Flex app.
For this article, I built the demo on a Flex installation running on top of JRun. If you're using a different application server, you will need to make a few changes to the host file, but everything else should function properly.
Analytics platforms generally involved using a JavaScript and cookies-based method of tracking a user's progress through a site. This worked reasonably well before the days of RIAs. When a user loads a single HTML page, that page can forward its data to the analytics platform, wait for the response from the vendor's server, and update the user's cookie. There's no need for further communication between the client and the service: You don't need to worry about conflicting HTTP requests. You don't need to worry that the process is asynchronous.
Flash and Flex-based RIAs change that, however. When developing an RIA, you might need to log information many different times as the user navigates within a single form or view. This seems like an ideal scenario for a web service, which your application can use to transfer data very easily from client to server. However, for a variety of reasons, many vendors (including Omniture) have not yet completed the transition from the older JavaScript and cookie-based approach to the more up-to-date web services approach or something similar. Additionally, many business owners are reluctant to switch to a completely new method for logging site views. They've used the old system for years and don't see the need to switch yet. Thus, developers must sometimes build something workable using an outdated approach, even though they know a better solution is available.
I wanted to create a small demo app that would demonstrate an approach to implementing analytics in a Flex app. For this purpose, the app didn't need to be complicated (in fact, the simpler the better) and I only wanted to illustrate the basics. I also wanted to make my code as reusable as possible to save time and effort for other developers. Drawing on my experience developing Flash apps for macromedia.com, I anticipated the following list of possible issues developers would face when using a JavaScript-based logging system from Flex:
I'll address questions 1 and 2 outside the realm of Flex and MXML. They involve modifying JavaScript and creating a host file that isolates the vendor's code in its own inline frame, or iframe. Questions 3, 4 and 5 are best addressed through best object-oriented practices within Flex using MXML and ActionScript. As I discuss the demo I created, I work from the outside to the inside: I start with JavaScript modifications, move to the hosting template, and then discuss the two ActionScript classes.