Tracking Visitors in a Rich Media World, Part IV: Silverlight
| Gareth Hebbron
Silverlight and JavaScript play nice together, so making manual requests for each interaction you want to track via DCSMultiTrack should not be a problem, though it will be time consuming to go through and add all these calls yourself.
The interaction between Silverlight 2.0 and WebTrends logging has been simplified by using a custom class developed by WebTrends. All you need do is simply add the class to your project by either including it in your current file, or by adding a new Silverlight class library.
The class is called “DcsMultiTrack” and lives in the namespace “WebTrends”. This code is essentially a tunnel between the Silverlight and the JavaScript function “dcsMultiTrack”. The “Send” method is used with the same name / value pairs as you would if making a standard JavaScript call to dcsMultiTrack. Here is an example:
DcsMultiTrack multitrack = new DcsMultiTrack();
multitrack.Send(“WT.ti”, “PageTitle”, “dcsuri”, “/silverlightapp/search_button”);
The Send call will not fail if the application is embedded on a page where WebTrends tags are not available. And… here is the class code:
namespace WebTrends
{
using System;
using System.Net;
using System.Windows;
using System.Windows.Browser;
///
/// WebTrends Tracking function for Silverlight
///
public class DcsMultiTrack
{
///
/// Private value
///
private static bool hasDcsMultiTrack = false;
///
/// Initializes a new instance of the DcsMultiTrack class
///
public DcsMultiTrack()
{
if (!hasDcsMultiTrack)
{
try
{
string typeOfFunction = (string)HtmlPage.Window.Eval(“typeof(dcsMultiTrack)”);
hasDcsMultiTrack = (typeOfFunction == “function”);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
}
}
///
/// Gets or sets a value indicating whether or not dcsMultiTrack exists in JavaScript
///
public bool LoggingEnabled
{
get { return hasDcsMultiTrack; }
set { }
}
///
/// Issue log request to WebTrends
///
///
Name/value pairs eg:(“WT.ti”, “title”, “dcsuri”, “/silverlight_app/button1″) /// multiTrack.call(“WT.ti”, “title”, “dcsuri”, “/silverlight_app/button1″)
public void Send(params object[] args)
{
if (HtmlPage.IsEnabled && hasDcsMultiTrack && (args.Length % 2 == 0))
{
try
{
HtmlPage.Window.Invoke(“dcsMultiTrack”, args);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
}
}
}
}
Simple right? Any questions? Well there is one blringly obvious question; When do I make my Send call? In call these Rich Media Technologys yes we can make logging requests but when? And what do we put in them? What constitutes as a page view in an interface with no pages. This is a question we will focus on in our Workgroup.