Search

Project Summary

Using analytics software for your website is normally a straight forward task, you add a few lines of code and actions are captured through the java script functions that are been created by the analytic software provider. This however is different in Silverlight applications. In Silverlight, Java Script on your page cannot talk to you your code in Silverlight by itself, i.e. your Java Script code would not know if you click on a link in your Silverlight application. Therefore, you need to specifically tell your Java Script code actions like clicking link has happened by calling it from your Silverlight Application.

Complete step by step tutorial can be found on Silverlight Tips here: http://www.silverlighttips.com/?tag=/event+tracking

Visit Q&A for this specific project at Silverlight Forums here: http://silverlightforums.com/showthread.php?p=3976#post3976.

Releases

Download the latest release for this project from here: http://silverlighttracking.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=39550.

Development Summary

1. Creating a tracking class

The tracking class is defined in your Silverlight project, it receives tracking parameter from anywhere in your Silverlight code and passes the parameters to a Java Script function to be sent to the analytics software using this method:

public void Track(string trackingCategory, string trackingResourceLabel, string trackingAction)
{
    category = trackingCategory;
    resourceLabel = trackingResourceLabel;
    action = trackingAction;
    SendTracking();
}

2. Creating a Java Script function for calling "pageTracker._trackEvent"

This function simply calls the tracking function you need to call in order to pass the parameters from your website to the tracking tool. i.e. in Google Analytics it is:

function trackEvent(category, action, opt_label, opt_value) 
{   
    pageTracker._trackEvent(category, action, opt_label, opt_value);
}

3. Calling Tracking class from your code and passing tracking values

Here we now pass the parameters as string value to our Tracking class. Here I used variables of type enum to achieve a more tidy and consistent code.

tracking.Track(Enums.TrackingCategories.Homepage.ToString(), Enums.TrackingGenericLabels.ClickButton.ToString(), Enums.TrackingActions.Click.ToString());
Last edited Feb 10 2010 at 10:32 AM by d4moon, version 13
Updating...
© 2006-2012 Microsoft | Get Help | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2012.1.11.18365