A few days ago Google announced “event tracking” for their Google Analytics platform. My account was invited to participate in this initial wave so I decided to take a look. The main reason of course is because of a keyword in their email they sent to me (emphasis mine):
“Event Tracking allows you to track interactions with Web 2.0 style content such as Flash, AJAX, Silverlight, social networking apps, etc.”
I have the script already running on my site for general analytics so I figured I’d whip up a quick sample to see how it might work with Silverlight. If you are in to analytics you may also want to check out Michael Scherotter’s webcast with WebTrends on some analytics techniques with Silverlight as well.
There are a bunch of existing techniques you can do today using existing analytics packages and scripts, but it is really nice to see movements toward recognizing unique characteristics of rich Internet application activities and the need for something more granular that represents user behavior rather than just a view. After all, “paths” for normal web browsing have been available for analytics for a long while…why should RIA have to suffer? The main reason is that no analytics packages have successfully managed yet to provide enough artificial intelligence to reflect on the behavior within the RIA. As RIA development becomes more mainstream in applications facing the consumers, it will be increasingly important to understand where/what the user’s are doing to discern better usability changes, etc.
Google calls their feature “event tracking” and enables a function on the existing script to track an event, much like a Windows event log (for those who are familiar with it). You provide a category and action, then optionally a label and value (where value is an integer value, generally going to be used I assume for counts of actions). The “action” doesn’t have to actually be an literal action such as “click” but something you can put together.
In my less-than-creative mind I just thought of putting together two category scenarios: media and e-commerce. My commerce actions would be: Add Item to Cart, Sample Music (i.e. a music store action), Start Checkout, Complete Order…all rolled up in a Commerce category. My Media category would include Play and Pause tracking. The signature of the event tracking method in Google is:
This would be called on your variable given to whatever your _getTracker() call was made with (mine is called pageTracker, using the default from the script).
NOTE: This post assumes you know some of the terminology from Google analytics offering. If you don’t, you can read about it at their Analytics page.
As you can see, in my sample I wasn’t concerned with the value parameter for now. Now in my Silverlight application I just created some lame looking XAML that would more generally be spread out throughout a typical application, but just for playing I put it in one place. Here’s the XAML:
On the relevant code I’ve wired up the buttons to the same event handler for simplicity and just looking at the name and content for what to do. Here’s what that looks like:
So you can see here at line 30 above is where the relevant code is. Using the HTML bridge, I can invoke a method on the hosting page and provide the arguments to it. That’s it! So what does this look like on the reporting side?
For a summary view of the categories you’ll get some decent information about the action:
But then when you also drill into a specific category, your label information will be viewable:
So that now using methods like this you could track specifically what is going on within your RIA. As I mentioned, you can do this with existing platforms today with being clever of how you track a “PageView” but it is nice to see a specific implementation for event-driven tracking. And this isn’t limited to just RIA, you can still (obviously) use this event tracking in your AJAX applications, static pages, whatever.
The Google links demonstrated how to implement this with ActionScript and Flash, but while they mentioned Silverlight, they didn’t provide a relevant sample. Luckily basically the steps are as easy as outlined here:
- Include the tracking script
- Decide what/when/where you want to track within your Silverlight application
- Use the HTML bridge (Html.Window.Invoke) to call out to the _trackEvent function
Again the relevant code for Silverlight is:
Have fun and hope this helps some!