Measuring user interaction time with website

With current APIs, is there any way to measure how long a user has been interacting with the website (not just with a single page)?

That would be useful to decide when to trigger a push notification prompt, a newsletter signup prompt, etc. That would increase the likelihood that a website display the prompt at the right moment, after some interaction, and not as soon as a user lands on a website.

I guess you could store a timestamp of the visitor’s arrival in sessionStorage.

you could store a timestamp of the visitor’s arrival in sessionStorage

That would not measure the actual interaction time with your website… Idle, not using the PC or the browser, visiting other sites on other tabs, etc.

That’s why we need an API to measure the actual interaction time.

Chrome recently shipped Idle Detection.

As far as I know, there is no single API that would directly tell you how long the user has interacted with a website as a whole, but there are different APIs that can be used together to enable a library that can answer that question more or less reliably.