How to add Silverlight version detection to Google Analytics

by APIJunkie 15. May 2009 06:35

One of the things that are currently missing from Google Analytics is Silverlight detection. Normally this type of information would appear under the browser capabilities section, the same section that lists Flash and Java versions. While I'm sure this will change eventually, it is something that can be very useful to web sites hosting Silverlight applications today.

In order to bridge this detection hole here is a simple solution that would plug this information into Google analytics.

The solution is based on 2 things:

1. Custom visitor segments  - Google Analytics allows us to create user defined values that can be stored and reported upon.

2. Silverlight JavaScript detection code - Code that allows you to detect the installed Silverlight version on the client's browser.

Awhile back I showed how to detect/report the current Silverlight version in JavaScript. Combining this code with Google analytics code to report user defined values is fairly simple. The following code is a rough example that would do the trick:


// Google analytics include files


<script type="text/javascript">

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "' type='text/javascript'%3E%3C/script%3E"));



// Report Silverlight version to Google analytics


<script type="text/javascript">

var pageTracker = _gat._getTracker("UA-xxxxx-x");

pageTracker._setVar('SLVersion ' + getSilverlightVersion() );




1. Remember to replace UA-xxxxx-x with your Google analytics code in the code example.

2. The information you report to Google analytics will appear under user defined values in the visitors section.

3. You can use Advanced Segments to integrate your user defined values into other reports.

4. There is normally a time delay in Google analytics reporting so it might take a few hours before you start to see the effects of your new code.

Good Luck!


Silverlight | How To | Google | Analytics


5/15/2009 7:09:34 AM #


Trackback from DotNetShoutout

How to add Silverlight version detection to Google Analytics


5/15/2009 7:18:32 AM #


Trackback from

How to add Silverlight detection to Google Analytics

5/17/2009 4:44:57 PM #

Mark Monster


Nice approach to track the Silverlight Version. I implemented a different version in February by using trackPage. I've seen a different approach making use of trackEvent as well.


Mark Monster

Mark Monster Netherlands

5/24/2009 10:53:05 PM #


Hi Mark,

Just checked out your great post. You definitely present a good solution to the problem.

However there are 2 main points that we differ in:

1. Personally I prefer to track events and not page views. This way I don't create artificial page views that modify my stats in Google analytics.

2. I don't like using Silverlight.isInstalled because it's inefficient and can easily be replaced with more efficient detection code.

Best regards,


APIJunkie United States

7/7/2009 1:33:32 PM #


Pingback from

Silverlight install base breaches 50% «  Programmer Payback

8/19/2009 10:15:17 PM #


This is excellent, i have just implemented it in my first Silverlight project


8/28/2009 12:41:15 AM #


Pingback from

Twitter Trackbacks for
        How to add Silverlight version detection to Google Analytics

8/31/2009 1:32:39 AM #


Pingback from

How to Programmatically detect Silverlight version? « Ramani Sandeep

Comments are closed

About the author

Name of author

I was first wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

  James Bacon