Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Using Application Insights with a new Windows Store App

0.00/5 (No votes)
18 Feb 2014 1  
How to use Application Insights with a new Windows Store app

If you haven't heard or read about Application Insights, you should go to MSDN and read up on all the awesomeness that you can get by using this new feature of VSO. You can also take a look at the Channel 9 series on Application Insights for Visual Studio Online by Charles Sterling.

Also, see Using Application Insights with an existing Windows Store App for an example of adding Application Insights to an existing application that could already be in the store.

Create a New Application

If you you have the Application Insights Tools for Visual Studio installed that Brian Harry mentions in one of his latest blog posts and you are creating a new application, this is very similar for you. Click the Add Application Insights to Project dropdown, that will make sure you are authenticated to VSO.

image_thumb[1]

Once done, you will be able to choose which VSO account you want to connect to and then you can click Configure to choose the application name (if you haven't created an application in Application Insights yet, just type the name and one will be created for you automatically).

image_thumb[3]

At this point, the application is opened in your default browser.

image_thumb[8]

and a solution is created like:

image_thumb[10]

Changing App Configuration

All applications (at the moment) new or current will get the error below if you haven't already changed the Platform of your store application.

image_thumb[12]

To get rid of this message and put Application Insights in a state where you can start logging application usage, you will need to change the configuration of your app to not be Any CPU.

Open Configuration Manager

image[29]

Set the platform to x86, x64, or ARM

image

Initializing Application Insights

Open the App.xaml.cs file and at the end of the App() method, add the following code:

Microsoft.ApplicationInsights.Telemetry.WindowsStore.ClientAnalyticsSession.Default.Start
("license key from ApplicationInsights.config");

As the snippet mentions, you need to grab the license key (aka: instrumentation key) from the ApplicationInsights.config.

image

At this point, you can run your application and you will get some basic information like the Operating System, Screen Resolution and a view metrics like session time. You'll need to wait about 15 minutes for the information to display on your dashboard, but it will look something like below.

clip_image002

To see the data, head over to the Usage Tab on VSO Application Insights:

image

Logging App Feature Usage

Because I am using a new application, I will just log which of the groups the user clicks into. To do this (if you are using the Split Page Application), navigate to ItemsPage.xaml.cs file and change the ItemView_ItemClick method to be like below:

/// <summary>
/// Invoked when an item is clicked.
/// </summary>
/// <param name="sender">The GridView (or ListView when the application is snapped)
/// displaying the item clicked.</param>
/// <param name="e">Event data that describes the item clicked.</param>
void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
    var properties = new Dictionary<string, object>() 
    {{"Title", ((SampleDataGroup)e.ClickedItem).Title}};
    Microsoft.ApplicationInsights.Telemetry.WindowsStore.ClientAnalyticsChannel.Default.LogEvent
    ("Store/ItemView", properties);

    // Navigate to the appropriate destination page, configuring the new page
    // by passing required information as a navigation parameter
    var groupId = ((SampleDataGroup)e.ClickedItem).UniqueId;
    this.Frame.Navigate(typeof(SplitPage), groupId);
}

We are simply logging that the Item Click event was fired and logging the title of the group that was clicked. This when you click around in the sample app will log to Application Insights as you click around and generate some data. To see the features that were logged, head over to Event Insights under the Features tab.

image

Conclusion

It's really simple to get started with Application Insights and get that feedback from your application when it's out there in the wild.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here