1.0.3 • Published 5 years ago
@studyportals/timespenttimer v1.0.3
Time Spent Timer
Time Spent Timer is a package that helps tracking how much time a user is actually spending using a certain page or functionality.
Setup & commands
The following commands can be used to setup, run and test this package.
# install dependencies
npm install
# serve with hot reload at localhost:8080
npm start
# build for production with minification
npm run build
# run unit tests
npm run test
#run test coverage report
npm run test-coverage
Usage
Please find an example usage of Time Spent Timer below.
Code example
// Initializes a timer with an optional configuration object
const timeSpentTimer = new TimeSpentTimer({
interval: 100,
idleThreshold: 5000,
onTick: () => {
console.log('Tik tok');
},
onIdle: () => {
console.log('User is not interacting with the page');
}
})
// Starts the timer
timeSpentTimer.init();
// Get the current time spent
const timeSpent = timeSpentTimer.TimeSpent;
Configuration
The TimeSpentTimer
constructor optionally takes a configuration object as a parameter. Also all configuration parameters are optional.
Option | Type | Description |
---|---|---|
interval - default = 100 | number (milliseconds) | The interval at which the timer will count. The minimal value is 10 . |
idleThreshold - default = 5000 | number (milliseconds) | The amount of time of not interacting with page after which the user is considered idle. |
onTick | function | A callback that will be called after each timer interval. |
onIdle | function | A callback that will be called after a user goes idle. |