Elasticsearch APM RUM Time on page / Session duration

890 Views Asked by At

Is there a way to make APM Real User Monitoring (Javascript agent) keep track of how long the user spent on the page?

I am currently using Elasticsearch v7.11.2

I am aware that the time tracking is not in the list of current available features; is there is any way to do it through, for example using Transaction Spans or with pure JS?

1

There are 1 best solutions below

2
On

RUM mainly returns the following data/metrics:

  • Page load metrics
  • Load time of Static Assets (JS, CSS, images, fonts, etc.)
  • API requests (XMLHttpRequest and Fetch)
  • Single page application navigations
  • User interactions (click events that trigger network activity)
  • User-centric metrics (Long tasks, FCP, LCP, FID, etc.)
  • Page information (URLs visited and referrer)
  • Network connection information
  • JavaScript errors
  • Distributed tracing
  • Breakdown metrics

Time on page is not one of them. Also, there might be other metrics more interesting than time on page, such as average session duration and dwell time.

Since each transaction contains a duration in microseconds...

      "transaction" : {
        "duration" : {
          "us" : 17385392
        },

...you can use well-known JS techniques for detecting when a user lands on a page and when she leaves, and then you can leverage the Transactions API, in order to measure the time taken by a series of events while the user is on your page.