react-time-tracker-hooks
v1.0.0
Published
React hooks to track time spent on components and send tracking data on unload/idle
Maintainers
Readme
⏱️ React Time Tracker Hooks
Track how long a user spends on components and send the data when the tab is closed or idle.
🚀 Install
npm install react-time-tracker-hooks
🧠 Usage
import {
TimeTrackerProvider,
useTimeTracker,
useSendTimeOnUnload
} from 'react-time-tracker-hooks';
function Dashboard() {
useTimeTracker('Dashboard');
return <div>Dashboard Page</div>;
}
function App() {
useSendTimeOnUnload('https://your.api/endpoint');
return (
<TimeTrackerProvider>
<Dashboard />
</TimeTrackerProvider>
);
}
✅ Features
Automatically tracks time on each component
Sends data when user goes idle, switches tab, or closes tab
Customizable API endpoint
No Redux required
📦 API
useTimeTracker(componentName) — start and stop time tracking
useSendTimeOnUnload(endpoint) — send tracking data on unload/idle
TimeTrackerProvider — must wrap your app