1

How can I use Azure Application Insights to track time spent by a user on webpage. In the javascript of the webpage, there is a chunk of code from application insights which we have to copy. I want to understand what

 r=["Event","Exception","Metric","PageView","Trace","Dependency"]

means...Are there more parameters we can add to track some other stuff. Like if I wanted to track how long a user was on a webpage, how would I track that?

Deepak Kumar
  • 1,669
  • 3
  • 16
  • 36
Aparna
  • 835
  • 2
  • 23
  • 47
  • is it possible to find out the time spent by a user on a web page using azure insights? How did you solve this problem? – Deepak Kumar May 13 '19 at 07:12

2 Answers2

3

This functionality is built into the JavaScript SDK.

By setting autoTrackPageVisitTime: true, the time a user spends on each page is tracked. On each new PageView, the duration the user spent on the previous page is sent as a custom metric named PageVisitTime. This custom metric is viewable in the Metrics Explorer as a "log-based metric".

You can find the documentation for it here.

You pass the autoTrackPageVisitTime preference in the configuration object when creating your application insights instance.

const appInsights = new ApplicationInsights({ config: {
  connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
  autoTrackPageVisitTime: true,
  /* ...Other Configuration Options... */
} });
TheCascadian
  • 485
  • 3
  • 14
  • I don't see autoTrackPageVisitTime as a property in the configuration. I figured it would be an option of Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions aiOptions= new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions(); – David Mar 25 '21 at 20:50
  • If you do a word search, you can find "autoTrackPageVisitTime" on the page I linked. Please note that this is for the JavaScript SDK and is not compatible with ASP.net Core. – TheCascadian Mar 26 '21 at 22:15
1

You have to use Custom Metrics

Do your metric calculation using SO thread & pass it on like below to Application Insights.

appInsights.trackMetric("userstaytime", 42.0);