0

I want to calculate the total active time of the user after user login in wordpress site.

For this i am using the following hook in my custom plugin:

add_action('wp_login', 'save_login_time', 10, 2); 

Here i want to check weather the user is active(by mouse events and keypress events) or not.

If user is active, i want to calculate the time and if the time is greater than 2 minutes then i want to store that time details and save the data in another table.

I have no idea how i can put jquery on perticular hook.

I want you to give me an overview that how can i do this functionality in my site?

closed as too broad by Jacob Peattie, rudtek, bosco, cjbj, Rick Hellewell Apr 11 at 22:03

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

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.

  • thanks for your answer but i want total user active time after login and that time i want to save in my custom table. I have checked the google analytics it just displaying the reports of user activity. Can i take the value from google analytics and save that value in my db? – Wordpress Learner Apr 8 at 13:24
  • 1
    You can use most of the Analytics data, but you'd have to use or write a library to connect to the Analytics API – Alexander Holsgrove Apr 8 at 15:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.