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.
Related Posts:
- Customizing subject in comment notification e-mails
- jQuery function didn’t work in my plugin
- How to prevent plugins from loading jQuery
- How do I add $_SESSION[”] to my wordpress page?
- update_post_meta is not working for me when I use e.preventDefault for update button
- Plugin Hook: Get posts
- How to get site homepage from plugin?
- Woocommerce attatch files and custom input meta to cart items and then to order
- Remove H1 title in admin post edit screen
- What are the differences between WPINC and ABSPATH?
- How can I see all the actions attached to an “add_action” hook?
- Pass PHP variable to javascript
- Showing Notifications While Activating Plugin
- HELP: Integrating WP with raw PHP code once published button is hit
- OOP: Display warning and deactivate the plugin if PHP version is less than 5.4
- Loading class files via autoload method
- Determine plugin name from within plugin_action_links filter
- WordPress plugin installation
- Get image URL from media library in input
- How to prevent action in ajax request, when in admin side?
- merging an array to an existing array using add_filter
- How to create popup same as wordpress popup feature
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- I would like to use create a function in my custom plugin to tell WP to use a different header
- template_redirect not being called when using ajax
- Getting media library popup in custom plugin admin page
- Create or Update thousands of woocommerce products via PHP
- send_headers don’t work on wordpress multisite
- Placement of Code in Plugin for hooking `save_post`
- Handling jQuery Component Collision
- publish_post plugin hook doesn’t always pass $post->post_content
- how to include a simple jquery file into a wordpress plugin
- What are the benefit in adding hook in the init() hook?
- Reposition Woocommerce Message
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- add_action in functions.php, do_action in plugin?
- Escape when echoed
- Scope for PHP Variables Assigned in functions.php or a plugin
- How to correctly detect accessing wp-content/uploads?
- Plugin exceeds memory limit
- How to initialize something in unit test before the init hook being called?
- Check if email address exists front end with AJAX in a plugin
- add action for displaying posts using a shortcode
- Write to / remove from default .htaccess file from plugin?
- ‘wp_login’ action hook not working with wp-login.php file
- Update Option Error: Notice: Undefined index
- Pass a php string to a javascript variable
- Plugin Development sqlite or WordPress’ database
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- Remove rewrite rules generated by plugin during deactivation
- How to trigger $_GET request within admin plugin page?
- How to generate video out of images via WordPress plugin
- How can I get WordPress to save comments in markdown format?
- WooCommerce get_price returning wrong price when used via ajax
- How to ‘clone’ a wp plugin to make small changes
- Open Post Thumbnail in New Child Theme File in WordPress
- How to pull code snippet from functionality plugin?
- Where should I save an API key of my user when installing my plugin?
- Prevent a plugin from being automatically activated
- Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
- Programatically download a plugin
- Redirecting to home page after login as custom role WordPress
- Add keywords meta to index.php page
- Custom form action to handle data inside a plugin
- Where (or when) should I register a new taxonomy?
- Self deactivate plugins after an action occurs
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- Notepad sticky plugin
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- WP Post Template – Templates in own folder
- Any hook for pre-plugin-update -either bulk or single plugin update
- Avoid class name collision when using third party libraries in plugins?
- wordpress plugin is not activating from widget
- Best approach to fetch data from wp options to js file or php file
- Edit Yoast SEO breadcrumbs output [closed]
- Adding a slider captcha to the comment system
- How to put JQuery/Ajax inside shortcode?
- Error with Image Slide plug-in/ s3slider in WP
- How would I go about creating a user ranked post popularity page?
- wordpress site | All-in-one-cufon IE Issue
- How to get all of the activate_plugin action parameters?
- Redirection of users away from wp-admin (but not administrators)
- Using a custom plugin to capture input data via Ajax and PHP
- WordPress function not being called from jQuery method
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- Using a post-signup hook to get user details
- Ajax contact form widget plugin data not insert in database
- code is working properly in Core PHP but writing coding in WordPress
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- wp_get_post_terms is difference obj model than the one in rest api response
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Image upload and download from front-end
- Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]
- wp_remote_get() returns 403 while file_get_contents() does not
- How to output CMB2 select options from repeated groups select elements?
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- Get Time Taken By Each Action Hook in WordPress
- 306 MB of wp_options occupied by WordPress SEO Plugin, is that normal? [closed]
- Are functions in main plugin file called before function bound to register_activation_hook runs?