28 February 2009 - 11:40 PM / by Dominic Pettifer. 1 Image for Add Silverlight Tracking to your Google Analytics. 1 Comment for Add Silverlight Tracking to your Google Analytics.
Technical Article - Use this handy JavaScript to add Silverlight Tracking to Google Analytics, and see what percentage of your users have Silverlight installed, including which versions.
If you run a website and haven't hooked up Google Analytics yet (or any other form of user tracking/web analytics system) then what's wrong with you!? GA is a very powerful tool that gives you detailed information about your visitors. Simply add a piece of JavaScript your websites footer, and it lets you see how many visits, total page views, average page views per user, what pages they are going to, how long they're staying on your site, plus many more besides.
You can also track visitor's browser capabilities, such as which Browser, version, screen resolution, colour depth, operating system and whether they have Java Applets and Flash enabled/which versions etc. Useful to know if you're deciding on a minimum screen resolution to support for your next website, or whether to continue supporting IE6, for example. Basically, you'll gleam a lot more information than from just looking at your server logs.
Unfortunately, there is no Silverlight tracking built into GA yet, but it does let you do your own custom logging. Add the following JavaScript somewhere in your site (external script file for instance):
function getSilverlightVersion()
{
var version = 'No Silverlight';
var container = null;
try
{
var control = null;
var product = 'Silverlight';
if (navigator.userAgent.indexOf("Linux") != -1)
{
product = "Silverlight (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;
}This Silverlight tracking code comes from Grant Archibald's blog, many thanks to him for providing this excellent function. You don't need to be using Silverlight on your website to use this function, and has no dependencies with Google Analytics, it could be used with any analytics engine as all it does is return a string. I've made a minor change, it returns "No Silverlight" instead of a blank string when Silverlight is not installed on the user's computer so we can filter Silverlight stats in GA, as we'll see later on.
Now in the footer of your website where your Google Analytics tracking code is set up, add the line pageTracker._setVar(getSilverlightVersion()); just before the line pageTracker._trackPageview(); so it looks something like this:
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-2689687-37");
pageTracker._setVar(getSilverlightVersion());
pageTracker._trackPageview();
} catch(err) {}
</script>Now wait until next day, and you should start to see some results in the 'User Defined' section under 'Visitors'. You may have other user defined values here so use the filter box to filer on the word 'Silverlight'.
The Google Analytics API does seem quite powerful, allowing you to track custom events whenever the user does something within the web page, and not just page visits. For instance, you can track when a user presses the Play, Stop & Pause functions on a video player, or track how often they try to drag 'n' drop widgets/gadgets around the page.
I recently added this code to a website I worked on, Borders Health In Hand. The tracking code has only been installed for a few days, so the sample is only from about 400 visitors, but we're seeing around 14.4% of users with Silverlight 2.0 installed, and 5.3% with version 1.0.
Bearing in mind this is a very mainstream, non tech-savvy, government website in the UK, so 14.4% isn't a bad showing for Silverlight 2.0, but is long way away from the 85% of our visitors with Flash installed (although Flash 10 only accounts for 40%). It'll be interesting to see usage stats for my own website. They should be higher given the unique audience (mainly .NET developers). I'll add the tracking code and report back.
Hi there
Ever since we started using this there has been a massive increase in the statistics for Visitors -> Browser Capabilities -> Flash Versions -> (not set). The number of people with a Flash version that is not set has jumped to around 85%.
Do you know what might be causing this and/or how to fix it?
Cheers!
James
Posted on 8 January 2010 - 1:04 AM / by James
Silverlight Usage Statistics from Google Analytics. (from the blog Add Silverlight Tracking to your Google Analytics )
Red Bull gives you wings....that generate huge amounts of downforce #F1
about 18 hours ago from Twitterrific.vampire { -webkit-box-shadow: none; -webkit-box-reflection: none; } #cssjokes
7:44 PM July 30th from Echofon@edhenderson lol, lets get a trending topic going - .gangster .wrapper { color: #000; width: 150%; text-decoration: bling; } #cssjokes
7:36 PM July 30th from Echofon@weblivz I think the petition should be resubmitted but with security stuff taken out, as that's what the response purely focused on
6:13 PM July 30th from Echofon@weblivz I still think Chrome Frame can come to the rescue here, still keep their old browsers + legacy systems, no retraining costs etc.
6:12 PM July 30th from Echofon