Welcome to Silverlight Analytics
SilverlightAnalytics lets you harness the power of Google Analytics in your Silverlight application. Now you can track web stats such as button clicks, mouse-over's, events, page views, or anything else you might want without having to call Invoke(). If you are unfamiliar with Google Analytics and web reporting in general,
you might want to check out this article, which mentions Silverlight Analytics.
Using SilverlightAnalytics In Your Application
Using
Silverlight Analytics is easy. First you'll need to make sure your webpage is using the new Google Tracking code (ga.js). Then you need to reference SilverlightAnalytics.dll in your project. Third, you need to think up some good categories and actions to track and create enumerators for both. Silverlight Analytics will use the names of each enumerator value (i.e. ToString()) when it sends an event to Google.
Tracking button clicks in your Silverlight Control
The following example demonstrates how to use
Silverlight Analytics to track when the Pause button is clicked on a UserControl.
The JavaScript Part
a little snippit of your tracking code... somewhere in your HTML
// somewhere in your HTML
var pageTracker = _gat._getTracker("your-code"); // <---- pageTracker is what we use!!!
An example C# User Control
An example that calls the library
using SilverlightAnalytics;
// categories
public enum MyCagetories
{
Video,
Music
}
// some actions
public enum MyActions
{
Play,
Pause
}
public partial class TestControl : UserControl
{
// tracker for this control
private SilverlightAnalytics.EventTracker<MyCategories, MyActions> videoTracker;
public TestControl()
{
// create a new instance of our tracker using the Video category
this.videoTracker = new SilverlightAnalytics.EventTracker<MyCategories, MyActions>(MyCategories.Video);
}
// The Click event for some button
private void PauseButton_Click(object sender, RoutedEventArgs e)
{
// track when the user clicks on this button!
this.videoTracker.TrackEvent(MyActions.Pause );
}
}
Tracking Page Views in your Silverlight Control
You can use easily track a page view as well. For example, if you have buttons that link to files or other web pages you would like to track.
public void TrackPageview()
{
Analytics analytics = new Analytics();
analytics.TrackPageview("/my/page");
}
What is Event Tracking?
Event Tracking is a fairly recent addition to
Google Analytics. Event Tracking lets you track actions on a single page. For example, if you had a video player, you could track the number of times a user hits the "Pause" or "Play" button, or the number of times a user views a video past 1 minute. Another example could be a "1-5 Start Rating" control; using Event Tracking you could track time a user rates a page, but not have it count as a separate page view.
Super-Quick Example
This example tracks an Event
public void TrackEvent()
{
EventTracker<MyCategories, MyActions> videoTracker =
new EventTracker<MyCategories, MyActions>(MyCategories.Video);
// now call it!
videoTracker.TrackEvent(MyActions.Pause);
}
Additional Reading
Here are some links that document the Google Analytics API