I think that a lot of people make use of Google Analytics for their site statistics. I am one of those Google Analytics users. You can easily dive into the statistics. Like checking the amount of visitors that have support for Java or Flash. But sadly Google still doesn’t track the support of Silverlight. So I though let’s dive into getting some statistics about Silverlight support in Google Analytics.
How to track custom data in Google Analytics?
You can easily track custom data. You can do things just like
this. A very simple track would be something like:
pageTracker._trackPageview("/tracking/tryout");
How to check support for Silverlight?
The check for Silverlight support isn’t that difficult as well. You will just need to reference
Silverlight.js. And after that there will be a new function available called Silverlight.isInstalled. This function accepts a string which contains the version number. We can use it like this.
Silverlight.isInstalled('1.0');
or
Silverlight.isInstalled('2.0');
Combined: check for Silverlight support and tracking in Google Analytics
The combination of both the Google Analytics tracking with Silverlight support will looks like this (make sure you change the location of Silverlight.js and your Google Analytics tracking code).
<script type="text/javascript" src="/Javascript/Silverlight.js">
</script>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxx-x");
pageTracker._trackPageview();
var hasSilverlight = Boolean(window.Silverlight);
var hasSilverlight1 = hasSilverlight && Silverlight.isInstalled('1.0');
var hasSilverlight2 = hasSilverlight && Silverlight.isInstalled('2.0');
if (hasSilverlight1) {
pageTracker._trackPageview("/silverlightsupport/v1/support");
}
else {
pageTracker._trackPageview("/silverlightsupport/v1/nosupport");
}
if (hasSilverlight2) {
pageTracker._trackPageview("/silverlightsupport/v2/support");
}
else {
pageTracker._trackPageview("/silverlightsupport/v2/nosupport");
}
</script>
How does it look like?
Content Drilldown - /silverlightsupport/v1
Support: 50%
No support: 50%

Content Drilldown - /silverlightsupport/v2
Support: 49%
No support: 51%

The statistics say that about 50% of the visits I get have support for Silverlight 1 and 2. But it’s important to know these stats are just from one days data. For real statistics you need at least weeks or maybe even months of data.
PS. Sorry for the bad code-snippets. I have always been using the very nice
Live Writer plugin from Steve Dunn. But this plugin doesn’t work anymore in the latest version of Live Writer.
Update February 25th 2009: Szabi has written an
excellent addition to this article.
Thanks for the correction.
I changed the link to your blog.
Regards
Peter Loebel
Switzerland
That's really a nice article. That's more specially related to event tracking in applications. Good to know this functionality of GA. I will keep it my mind for my next RIA project.
Thanks for your script, it's really helpful, but my opinion is that tracking Silverlight support as virtual pageviews isn't the best solution. Event trackig looks far more better and events don't distort pageview charts.
So I made a little modification and posted it here: http://helloszabi.com/post/81116183/silverlight-tracking-with-google-analytics
Cheers,
Szabi