4

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?

joepa37
  • 3
  • 4
  • 21

1 Answers1

2

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.

Val
  • 207,596
  • 13
  • 358
  • 360
  • Thanks for your answer, I am aware that the time tracking is not in the list of current available features; that's why I'm asking if there is any way to do it through for example using Transaction Spans or using pure JS. – joepa37 Mar 19 '21 at 13:54
  • Spans usually measure the time of single events. But using the [transaction API](https://www.elastic.co/guide/en/apm/agent/rum-js/current/transaction-api.html) you're free to measure the time taken by a series of events while the user is on your page. – Val Mar 22 '21 at 05:14