Introduction
Here, we will add the power of application insights to your application with a customized telemetry, captured as per your business needs instead of the standard data.
- Web Client Telemetry.
- Custom telemetry.
Follow the below steps to add application insights to your application,
Step 1
Open the project in Visual Studio.
Step 2
Right click on your Website and click “Add Application Insights Telemetry”.
In the “Add Application Insights to Project” Window, select the option to add “New Application Insights Resource”.
After Visual Studio finishes adding the Nuget Packages for “Application insights," if we run the project, it will start logging the telemetry data for the Web Application.
Adding Web Client Telemetry
To add web client analytics, we will need to add some JavaScript code in the pages we want to track.
Step 1
Open the Default.aspx page, switch to “Source” view and add the following script after line 3.
- <script type="text/javascript">
- var appInsights = window.appInsights || function(config)
- {
- function s(config)
- {
- t[config] = function()
- {
- var i = arguments;
- t.queue.push(function()
- {
- t[config].apply(t, i)
- })
- }
- }
- var t = {
- config: config
- },
- r = document,
- f = window,
- e = "script",
- o = r.createElement(e),
- i, u;
- for (o.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", r.getElementsByTagName(e)[0].parentNode.appendChild(o), t.cookie = r.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) s("track" + i.pop());
- return config.disableExceptionTracking || (i = "onerror", s("_" + i), u = f[i], f[i] = function(config, r, f, e, o)
- {
- var s = u && u(config, r, f, e, o);
- return s !== !0 && t["_" + i](config, r, f, e, o), s
- }), t
- }(
- {
- instrumentationKey: "KeyID for your Application Insight Resource"
- });
- window.appInsights = appInsights;
- appInsights.trackPageView();

Add the script to all the pages in the project at the same place.
Now, publish the project to the same “Azure Web sites”.
Browse the Website and hit all the pages. Keep the “Default.aspx” running for some time.
Now open the “Application Insights” resource from Visual Studio or from Azure Portal.
Click on “Diagnostic search” to open the Diagnostics blade:

In the search option, enter “Default.aspx”. Click “Filters” button, check “Page View” and uncheck all other options.

Now close the filter blade and come back to the Diagnostics blade.
It will list “PageView” Web client data for your Web Application. You can select the individual pages to see the details of the request
Adding Custom Telemetry
Open “CustomEvents.aspx.cs” file from the project.
Add reference to the Application Insights namespace in the code,
- using Microsoft.ApplicationInsights;





RajaPosted Jun 27, 2016, 12:31 AM
Good One...
Vignesh ManiPosted Jun 26, 2016, 4:39 PM
Nice
Debasis SahaPosted Jun 25, 2016, 2:53 AM
Nice one..
Santhakumar MunuswamyPosted Jun 24, 2016, 11:58 PM
Thank you for nice article
Prasanna MuraliPosted Jun 24, 2016, 9:41 PM
Nice one..
Bhuvanesh MohankumarPosted Jun 24, 2016, 12:38 PM
Good one