Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Using Application Insights with a new Windows Store App

, 15 Apr 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
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 Ap

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 mention in one of his latest blog posts and you are creating a new application, this is much similar for you. Click the Add Application Insights to Project drop down, 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(<span style="color: #006080">"license key from ApplicationInsights.config"</span>);

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 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

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

    <span style="color: #008000">// Navigate to the appropriate destination page, configuring the new page</span>
    <span style="color: #008000">// by passing required information as a navigation parameter</span>
    var groupId = ((SampleDataGroup)e.ClickedItem).UniqueId;
    <span style="color: #0000ff">this</span>.Frame.Navigate(<span style="color: #0000ff">typeof</span>(SplitPage), groupId);
}

We are simple 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Gordon W Beeming
Software Developer Derivco
South Africa South Africa
Gordon Beeming is a Software Developer at Derivco in the sunny city of Durban, South Africa. He spends most his time hacking away at the keyboard in Visual Studio or with his family relaxing. He is a Visual Studio ALM Rangers, Visual Studio ALM MVP and Friend of Red Gate. His blog is at 31og.com and you can follow him on Twitter at twitter.com/gordonbeeming
 
http://31og.com
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 16 Apr 2014
Article Copyright 2014 by Gordon W Beeming
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid