:::: MENU ::::

Adding application insights in windows store apps

Application insights gives 360 view of your application. With the application insights you can get the full picture with customizable dashboards that track application health alongside adoption metrics and app crash data. (From application insights documentation).

For this purpose we will need:

– A Subscription to Microsoft Azure.

– Visual Studio 2013 or later.

So here is step by step guide:

  1. Create an Application Insight resource in azure

From Azure portal create an application insights resource where telemetry from your app will be analyzed and presented to you. You will find the instrumentation key in properties option and that key is required while configuring application and SDK in your app and send all tracking data to the resource that is associated with that instrumentation key.

  1. Add the application insights SDK to your app

In Visual Studio, add the application insight SDK to your project. In Universal windows app you have to repeat the process to both windows and windows phone project. You can get the SDK from Nuget (here is link).

As shown in above image(if your app is universal app)

1) You can choose phone or windows project to which you want to install package.

2) Write that command to install package.

Now Create the ApplicationInsights.config file to the root of your project and get instrumentation key of resource from portal and put in that config file. You can see where you can get instrumentation key in first image. Here is sample ApplicationInsights.config looks like.

Now set the properties of ApplicationInsights.config file as below;

Now its time to write some cs code to track usage or performance of your application. First enable the network access by checking the internet capabilities in Package.appxmanifest file.

Now lets write code:

In App.xaml.cs file:

Add following initialization code in constructor (you can add anywhere you want where code executes). For the universal application you have to add for the both project.

Now run your application and then it starts to send the telemetry data to the azure resource. Go to azure portal and refresh the application insight resource application then you starts to see the insights. There are different types of collectors in insights during initialization which send different type of data like PageView, Session, Metadata etc. and by default all collectors are enabled but you can customize it as per your need.

Above you can see couple of collectors enabled to track different types of data and here you can choose the collectors as per your need.

Along with this basic data you can also track other event or behavior by using following methods.

  1. TrackPageView
  2. TrackEvent
  3. TrackMetric
  4. TrackException
  5. TrackRequest
  6. TrackTrace
  7. TrackDependency

For more about these methods and its implementation check official documentation.

Tracking and Sending custom telemetry data

You can also track and send customize telemetry data by using following API. Below example is taken from azure official documentation post.

Create an instance of TelemetryClient class as shown above. In this example event type data is captured and it is customized base upon its type and send the metrics associated with that event.

Tracks the event when user win the game and this tracked event/data in named as “Win Game”. So now in app insights resource in azure you can start to see metrics of this event once this event got fired.

This method tracks the metrics i.e some value which is grouped by the name “Queue Length”. You can use this method where you have to track numeric values.

You can also attach properties and metrics to any telemetry tracking methods. Here in example.

Properties are string values that you can use to filter your telemetry in the usage reports. In this example game name is provided as properties value. If you have multiple games and you want to capture usage/popularity of each game you can implement such technique.

There’s a limit of about 1k on the string length. (If you want to send large chunks of data, use the message parameter of TrackTrace.)

Metrics are numeric values that can be presented graphically. In this example score of game is captured.

Since Properties and Metrics are dictionary type you can add multiple data related to that event.

So in summary we can say that when user win a game application insights track that event withe the name “Win Game” and along with that event data it send other game data and metrics associated with that event i.e. game name that user own and their score. Now in azure you can see that “Win Game”event is captured and inside that event you can view game name, its score, their relation etc. in awesome dashboard. You can use interactive tools to filter and segment data or drill down into particular event instances for details.

You can do a lot more with application insights this is only sneak peak of what you have to do to add application insights service in windows store apps. For more content go here.

Happy Coding 🙂