Here is a JavaScript-based browser tab usage tracker that monitors when a user switches to or away from a specific tab, records the duration spent on the tab, and logs the total active time. This can be used in web apps to analyze user engagement.
Features:
-
Detects tab visibility using the
visibilitychangeevent. -
Records the time when the user switches to or away from the tab.
-
Logs total time spent on the tab.
-
Outputs time log directly in the browser for demonstration.
Deployment:
You can run this code in any HTML file in your browser, or integrate it into a web application to collect session behavior data.
Let me know if you’d like it to store data in localStorage, send it to a server, or run across multiple sessions.
Share this Page your favorite way: Click any app below to share.