useIdleTimeout
A Vue 3 composable that provides an easy way to track user inactivity on your website and execute a callback function when the user becomes idle.
INFO
A plugin to know the amount of time a user has spent on your website
Demo
isIdle: false
Wait 5 seconds without any actions to see the dialog popup
Callback
ts
type IdleTimeoutCallback = (payload: {
isIdle: boolean
eventType?: string
}) => void
Options
ts
interface IdleTimeoutStrictOption {
/** @default document.body */
element?: HTMLElement | Document
/** @default 60 * 1000 * 5 --> 5 minutes */
timeout?: number
/** @default false */
once?: boolean
/** @default true */
immediate?: boolean
}
Actions
Start
Start tracking user - needed for SSR when immediate
option is set to false (execute it on client side)
ts
idleTimeout.start()
Pause
Will pause the timeout and events, can't be executed when the timeout has expired
ts
idleTimeout.pause()
Resume
Resume the instance will reinit the timeout
ts
idleTimeout.resume()
Reset
Reset the timeout of the instance like a restart
ts
idleTimeout.reset()
Destroy
Will destroy the instance and stop tracking
ts
idleTimeout.destroy()