Sleep tracker JS is a component for tracking user inactivity on a web application. This component manages several pages opened

Get started

const sleepTrackerInstance = sleepTracker({
    timeout: 60, // in minutes, By default is 30 minutes
    delayCallAwake: 10
sleepTrackerInstance.on("beforeasleep", function() {
    // Open modal to ask if user is awake ! If ok call sleepTrackerInstance.awake();
sleepTrackerInstance.on("awakened", function() {
    // User indicate on other page he awake. If modal is open, you can close it
sleepTrackerInstance.on("awake", function() {
    // Execute code to indicate to the server user is awake
sleepTrackerInstance.on("asleep", function() {
    // Execute code because user is asleep. example logout, black screen, ...


You can use this CDN link

<script src="[email protected]/dist/sleeptracker.min.js"></script>


npm install @guillaumebonnaire/sleep-tracker-js

import sleepTracker from '@guillaumebonnaire/sleep-tracker-js';


Options of component

Option name Description Type Default Value
timeout time out when user is considered comme asleep. In minutes int 30
timeoutBeforeAsleep Minutes before time out when application ask if user is awake. In minutes int 2
detectActivity If component detect activity like keydown, scroll, focus boolean true
delayCallAwake Delay between 2 trigger event “awake”. In minutes int 5
keyStorage Key used to store data in localStorage string based on hostname
onload on load event function (Object: component) null
oninit on init event function (Object: component) null
debug debug mode, verbose all event triggered on console boolean false

functions of component

Function name Description Syntax Return
on Function to defined a function triggered by the component on(String: event, Function: callback) avoid
asleep Function to indicate user is asleep asleep() avoid
wakeup Function to indicate user is wakeup wakeup() avoid
awake Function to indicate user is awake awake() avoid
isAwake Function to check if user is awake isAwake() boolean

Events of component

Event name Description Syntax
asleep Triggered when user is asleep function (Object: component)
beforeasleep Triggered some minutes before time out will be trigger function (Object: component)
wakeup Triggered when user is wakeup (before asleep) function (Object: component)
awake Triggered when user is awake (activity) function (Object: component)
awakened Triggered when user is awakened (trigger is beforeasleep is triggered) function (Object: component)
init Triggered when component is init function (Object: component)
load Triggered when component is loaded function (Object: component)


View Github