Web analytics tools provide information around browser capabilities amongst several other things, which allows understanding the specific audience for your web site from a technology perspective. I use Google Analytics on my site, and the reports I get include information about Flash availability, and specific versions. I am hoping the analytics tools will soon be updated to cover Silverlight out-of-the-box (hint, hint...). My curiousity around this was triggered by an email thread yesterday, and I wanted to see if I could somehow report Silverlight installs manually to the analytics engine, and then look at the stats through their reporting interface.
After a little poking around, I found that Google Analytics has support for reporting a user-defined field. They have an API that becomes available after you have included their script (urchin.js). The specific method of interest here is __utmSetVar (strange ... naming seems to indicate it's an internal API), but its clearly documented for this purpose. Here is the script you can use on your page:
function onLoad() {
var version = getSilverlightVersion();
if (version) { __utmSetVar(version); }
}
function getSilverlightVersion() {
var version = '';
var container = null;
try {
var control = null;
if (window.ActiveXObject) {
control = new ActiveXObject('AgControl.AgControl');
}
else {
if (navigator.plugins['Silverlight Plug-In']) {
container = document.createElement('div');
document.body.appendChild(container);
container.innerHTML= '<embed type="application/x-silverlight" src="data:," />';
control = container.childNodes[0];
}
}
if (control) {
if (control.isVersionSupported('2.0')) { version = 'Silverlight/2.0'; }
else if (control.isVersionSupported('1.0')) { version = 'Silverlight/1.0'; }
}
}
catch (e) { }
if (container) {
document.body.removeChild(container);
}
return version;
}
Basically this detects the presence of Silverlight, and if its available, it records the version as the value of the user-defined field. Now your analytics reports will have one of three values: "(not set)", "Silverlight/1.0" or "Silverlight/2.0".
<aside>For those wondering, I didn't use Silverlight.js from the SDK and its Silverlight.isInstalled helper. Instead wrote the script myself. The Silverlight helper doesn't cache version info by creating the control once. So if you check for both 2.0 and 1.0, you'll end up creating two plugin instances, which is wasteful. Its certainly possible to have a different implementation of the isInstalled helper that is smarter.</aside>
One gotcha: Google's analytics engine only supports one user-defined variable you can use (not sure why). So if you are already using it, you're out of luck. Alternatively you can combine multiple bits of information into the single variable, and then use the ability to define multiple analytics profiles and associate some regex-based filtering rules per profile to split your combined user-defined field for reporting purposes.
I have added this script to my site for experimentation - will see how it plays out over the next few days. It will be interesting to see a few things: what sort of numbers I get, and what is the makeup of my audience, do the numbers match the overall Silverlight deployment stats I see, and last but not least, hopefully get some sense of satisfacation from seeing the technology I've work on getting out there in the real world. :-)
I should mention that I am no analytics expert. However, I am impressed with the kind of information I now get since I deployed it on my site. Just reading a bit on this last night, the concept at play here is called "segmentation" or visitor classification. There are complete books devoted on analytics such as Google Analytics 2.0. Fascinating! I've added it to my reading list.
If there are other ways of accomplishing this sort of thing, I'd love to hear about them. For example, I also noticed that 'urchinTracker', the same API used to invoke analytics in the first place, has an overload which can be used to track all sorts of events, and user activity on the page (such as clicking on the Silverlight install prompt), and it could be twisted to track particular browser capabilities as well. The nice thing about that possible approach is it doesn't eat up the single user-defined variable.
Update, 4/14/08: Updated the script to work for Silverlight 2.
Posted on Thursday, 10/4/2007 @ 12:16 PM
| #
Silverlight