# Sunday, August 10, 2008

Tracking Silverlight And Moonlight Enabled Browsers via Google Analytics

In this post I will briefly discuss using Google Analytics in conjunction with Silverlight, to track the version installed and your application usage patterns.

Following on from Nikhil Kothari's blog entry on Tracking Silverlight-enabled Browsers via Analytics I have made a few tweaks to the original JavaScript that can be placed at the end of your HTML document after pageTracker has been initialised to provide for the following.

  • A change from the old __utmSetVar function in the urchin.js tracking to the new pageTracker._setVar in ga.js version for the following reasons.
  • A check for Linux to distinguish between Moonlight usage versus Silverlight.

Based on this information it may help you further refine your Silverlight strategy based on your visitors e.g.

  • The split in visitor numbers between Silverlight Version 1 or 2. Important in terms of:
    • Install experience.
    • Documentation on why the user should upgrade (Features/Differences).
    • What messages should be displayed to the user of an older Version 1.0 client.
    • Compatibility with the upcoming Silverlight 1.0 for Mobile which will initially only support Version 1.
  • Determine the cross platform use of your application.
  • The possible need to cater for font availability across different operating systems.

Also as indicated in the comments of Nikhil's blog post Jeff Wilcox has a great post Using Google Analytics with rich (managed) web applications in Silverlight that explores how to integrate tracking within your Silverlight application.

<script type="text/javascript">
 
function getSilverlightVersion() {
 
    var version = '';
 
    var container = null;
 
    try {
 
        var control = null;
 
        var product = 'Silverlight';
 
        if ( navigator.userAgent.indexOf("Linux")!=-1) product="Moonlight";
 
        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 = product + '/2.0'; }
 
            else if (control.isVersionSupported('1.0')) { version = product + '/1.0'; }
 
        }
 
    }
 
    catch (e) { }
 
    if (container) {
 
        document.body.removeChild(container);
 
    }
 
    return version;
 
}
 
if ( pageTracker )
 
    pageTracker._setVar(getSilverlightVersion()); 
 
</script>
Comments are closed.