Padmaja
Padmaja

Reputation: 31

Using application insights REST API for reading custom events

We have a custom event put in place on page which tracks the link clicks on given page to app insights. And with the REST API we would like to get the frequently accessed links from app insights. How can we build the Query to get this analytics data, any sample on reading custom events available?

Thanks

Upvotes: 0

Views: 1321

Answers (1)

John Gardner
John Gardner

Reputation: 25168

if you open the Application Insights Analytics website for any resource, there's some "Common Queries" examples right on the front page. one of them is called "Usage" and if you click it it will show you this one:

//What are the top 10 custom events of your application in the past 24 hours?
customEvents 
 | where timestamp >= ago(24h)
 | summarize dcount(user_Id), count() by name
 | top 10 by count_ 
 | render barchart

which:

  1. queries customEvents,
  2. filtering to the last 24 hours (timestamp >= ago(24h)),
  3. does a summary of the distinct count of users (dcount(user_Id)) and the total number of events (count()), grouped by the event name (by name),
  4. then filters to the top 10 by the _count field created from the summarization (top 10 by count_)
  5. and then renders it as a bar chart (render barchart)

there are many other examples on the analytics home page as well.

Edit to add: You can easily query any custom properties or metrics that you send as well. the customDimensions and customMeasurements fields in each event type are json typed fields, and if there's no spaces in the names, you can just use dot notation to grab values. if the field has names/special characters, use brackets and quotes:

customEvents 
 | where timestamp >= ago(1h)
 | extend a = customDimensions.NameOfFieldWithNoSpacesOrSpecialCharacters
 | extend b = customDimensions["Field with spaces"]
 | extend duration = customMeasurements["Duration (ms)"]
 | project a, b, duration
 | limit 10 

(you don't need to use extend, you can use the fields however you want this way, with extend or project or summarize or any other functions or anything else. i just used extend for the example here.)

Upvotes: 2

Related Questions