I'm trying to calculate the time span between two requests/pageViews in Application Insights. The goal is to calculate the time spent on a page. I know that AI has the autoTrackPageVisitTime
setting, but this is not turned on, unfortunately.
My initial try was to join the request table with itself
requests | join kind=inner requests on session_id, $left.timestamp < $right.timestamp
, but my understanding is that joining with less than is not supported.
Anyone else has an idea of how I can calculate the time between two consecutive requests for each session?
EDIT: In pseudo-terms:
- Find first request where page/name = 'page1'
- Find the next request where sessionId equals the first one
- Calculate the duration between the two requests
- Calculate the avg duration across all sessionIds.
I'm not entirely sure if you always want to track from a specific page, but if you are looking for averages you shouldn't need to worry about individual page timings.
If you are looking for the average page timings across the site, then you just need the earliest time the session was active, the last time, and the number of pages visited over that time period. Dividing the time difference by page count gives the average. You can then call
summarize
again to get the overall average.Note- I'm subtracting 1 from the page count because I don't have the time between the last page was opened and when they left.
Code:
If you are looking for the time spent on a specific page based on the user's next pageview, then your initial idea of joining the table to itself wasn't bad, but we can execute it a bit differently to avoid the < join.
avg
functions with .summarize
can give you the overall average.Code: