In a previous post, we discussed some of the benefits of feature usage tracking using application analytics. In this post, we will dive deeper into the actual implementation of feature usage tracking in a WPF application. Instrumenting your first application with Telerik Analytics is always free (for up to 100 users), there is no risk to evaluate the service.

REGISTER FOR A TELERIK ANALYTICS ACCOUNT

The first thing that you will need is an analytics account. Visit the analytics dashboard login page to register for a free account if you haven’t already done so. Now it’s time to log into your account and get started. In this example we will be instrumenting a WPF RSS reader client. In the Get Started pane on the screen register your application, in my case I’ve named it MyRssReader.WPF and selected that the platform the application is running on is .NET:



It’s important to note that there are plenty of analytics monitors available in multiple technologies. In our case, because we’ve implemented a WPF application we’ve selected the .NET monitor for our application. The current downloadable monitors at the time of this writing are as follows:



Now that we’ve registered our application you are presented with a product key that is unique to your application. (Please note that the key in the screenshot below is fictional)

Product Key

ENABLING APPLICATION ANALYTICS IN A NEW WPF APPLICATION

If you are just getting started with green-field development, the Telerik RadControls WPF Application project template has been updated with a dialog specifically geared to help you integrate analytics. Simply copy the product key from the website and paste it into the textbox. Also ensure the “Integrate EQATEC Application Analytics” checkbox is checked:

Project Configuration

When Visual Studio generates the project, all references and monitor initialization code is added for you and you are ready to get started. You can take a look at the monitor initialization in the App constructor located in App.xaml.cs:

//The following code enables EQATEC Application Analytics for your project
var analyticsMonitor =
    Telerik.Windows.Analytics.TraceMonitor.Initialize(this,
           "A123B4CD56E7890123FG45HI67890J1K");

Many of the RadControls for WPF come pre-instrumented for application analytics. We will visit this topic in a future blog post, but for now you can read all about it in the documentation.

Because we want to do some custom feature tracking in this example, in App.xaml.cs, introduce a public static property so that we can access the analytics monitor from anywhere in the application (you will need to add a using statement to EQATEC.Analytics.Monitor to the file):

public static IAnalyticsMonitor Monitor { get; set; }

In the App constructor, assign the generated analyticsMonitor variable to this new static property:

Monitor = analyticsMonitor;

 

ENABLING APPLICATION ANALYTICS IN AN EXISTING WPF APPLICATION

In the Get Started pane of your dashboard, directly below your product key, you can see the step-by step instructions to enabling analytics in your registered application.

Download Monitor

The first step as indicated in the screenshot above is to download the analytics monitor for .NET. Once this is complete, unzip the contents of the file to a location of your choosing on your hard drive. Right-click on your project file and browse to add a reference to EQATEC.Analytics.Monitor.dll that you just downloaded.

Open App.xaml.cs and replace the code listing with the following (Note: change the namespace to the base namespace of your application):

using System;
using System.Linq;
using System.Windows;
using EQATEC.Analytics.Monitor;
 
namespace NewWPFApp
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public static IAnalyticsMonitor Monitor { get; set; }
        
        public App()
        {
            this.InitializeComponent();
 
        //create the analytics monitor with your product key
            Monitor = AnalyticsMonitorFactory
                    .CreateMonitor(
                            "A123B4CD56E7890123FG45HI67890J1K");
        }
 
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
 
            //start the analytics monitor
            Monitor.Start();
        }
 
        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);
 
            //stop the analytics monitor
            Monitor.Stop();
        }
    }
}

In the constructor we created an instance of the analytics monitor using the AnalyticsMonitorFactory, this value is then assigned to our static Monitor property so that the monitor can be accessed from anywhere in the application. We also overrid the OnStartup and OnExit methods to start and stop the monitor.

IMPLEMENTING CUSTOM FEATURE TRACKING IN OUR APPLICATION

To walk through this example, you will need to download the original source code to the WPF RSS Reader. This WPF client uses the RadControls for WPF Application template and controls, therefore if you don’t already have it installed, please download and install a trial.

The application we are going to instrument is a simple one, it reads the RSS feeds of the user’s favorite blogs and then provides the ability to dive into a specific article for viewing within the application. The favorite feeds are stored in an XML data file that is maintained through an administration screen.

In order to gain a better understanding of the behaviors of the users of our application we will add feature tracking to a few key areas of the application.  

As a first step, we want to see if the users are actually using the menu system to switch between blog feeds. Since the application is delivered to the users with a couple of the most common feeds already in the data file, we are curious to see if they are actually using the application to read more than the first blog feed. The currently visible blog feed is switched in the application through the ChangeCurrentFeedCommand command. Open Commands\ChangeCurrentFeedCommand.cs file and append the following line of code to the Execute method:

App.Monitor.TrackFeature(
                   "MyRssReader.WPF.ChangeFeedCommandExecuted");

Next, we would like to see if users are actually drilling into individual articles to read. This functionality is implemented through the ChangeCurrentArticleCommand. Open Commands\ChangeCurrentFeedCommand.cs and add the following line of code to the Execute method of the class:

App.Monitor.TrackFeature(
            "MyRssReader.WPF.ChangeCurrentArticleCommandExecuted");

Another aspect of the application that we’d like to track would be the administration of the feeds. We can track the accessing of the screen through the Commands\GoToFeedAdminCommand.cs file by adding the following line of code to the Execute method:

App.Monitor.TrackFeature(
                  "MyRssReader.WPF.GoToFeedAdminCommandExecuted");

Finally, we can benefit from seeing how the users are actually using the administration screen. This screen is implemented with the RadDataForm control with custom commands that are wired up through a DataForm command provider. Our implementation of this command provider can be found in Commands\FeedAdminCommandProvider.cs. Let’s track saving of records by adding this code to the CommitEdit method of the class:

App.Monitor.TrackFeature(
           "MyRssReader.WPF.FeedAdminRecordSavedCommandExecuted");

Then append the following line of code in the Delete method of the class:

App.Monitor.TrackFeature(
          "MyRssReader.WPF.FeedAdminRecordDeletedCommandExecuted");

It will be interesting to see the comparison between how many people access the administration screen versus actually using it.
It’s now time to save the application code, run it and interact with it so that we can see some of the collected data within our dashboard.

VIEWING LIVE DATA

Now that we have run our application a few times and interacted with it, we are ready to take a look into the live data feed by logging into our analytics dashboard.

On the left hand menu, under the Developers Reports section you will find the “Live” item. Click on this item and you will be able to view the most up-to-date information provided from the installations of your application.

Live Data

When you click on the View link next to one of the application sessions, you can see more detailed information about how the application was used during that specific session.

Session Information

The user of this session switched feeds six times, drilled into a specific article 3 times, accessed the admin screen 3 times where they saved a couple feed records, and deleted one feed record. Some other helpful information gathered by the analytics monitor is the location of the user, as well as the operating system, default language and high level specifications of the user’s hardware. Such information can come in real handy when catering your application to the demographics of your users.

You can also access the application dashboard by clicking on the product name in the left-hand menu. The dashboard is a handy tool that lets you visualize the usage of your application at a glance. This visualization is also highly interactive where you can change the date range of data that you wish to have compiled for the report. In this case, let’s view the live data, in the lower right hand corner there is a “live” link that we can use to see our recent interactions with the application.

Dashboard

We can also see that the application encountered an exception. To view the details of the exception, click on Exceptions under Developers Reports, then click the “live” link in the lower-right hand corner. You will now see the exception that occurred be displayed in the grid, as well as the number of times that exception has been encountered.

Exception Grid

Click on the link in the Stack trace column to view the stack trace that will let you track down where the exception occurred in code, from the stack trace we can see that the exception occurred when an invalid link was entered by the user in the admin screen:

Exception Information

We will go further into exception tracking in a future blog post, but for now, isn’t it great that we know the details of an exception without having to wait until a user complained or filed a trouble ticket?

WRAP-UP

In this blog post we reviewed how to create a free Telerik Analytics account. We also showed how to enable application analytics in a new WPF application as well as in an existing WPF application. We then visited a sample WPF application and added feature tracking to key areas. After interacting with the application for a little while, we visited the analytics dashboard and reviewed the live data being received from the application. We were then able to get detailed information about the activity from a particular user session from the application. We accessed the application dashboard to see at a glance the usage information of the application and to also see the indicator that an exception had occurred. We then accessed the exception report and pulled the stack trace to find out where the application failed.

Empowering applications with analytics helps you get unprecedented insight into the actual usage of your application. Feature usage tracking is just a small part of a world of data that you can easily gather from your application. Stay tuned to this blog to learn more about the benefits of Application Analytics.

Remember that instrumenting your first application with Telerik Analytics is always free (for up to 100 users), there is no risk to evaluate the service, register for an account today!

EQATEC Application Analytics by Telerik

 


About the Author

Carey Payette

is a Developer Advocate. You can follow Carey on Twitter @careypayette or read her personal blog at www.codingbandit.com.

Comments

Comments are disabled in preview mode.