Save user total active time after login in wordpress [closed]

You will want to use either a serverside method, adding a function or hook each time the user loads a page. The first time you check, you can set a cookie or session variable containing a timestamp to start the “active time” on the site. Each time they load a page, you can test for this variable and then using the current time to determine the total time spent on the site. The problem would be knowing when the active time ends.

The other option is to use JavaScript, if you really want to trigger it using mouse and key events. You can add a listener for keyup or mousemove for example which trigger a callback to update the time on site. You can then use an onbeforeunload event to update the time spent on the page.

A better option in my view is to use something like Google Analytics to track user engagement on your site. Another option is user tracking from HotJar.