1.0.3 • Published 5 years ago

@studyportals/timespenttimer v1.0.3

Weekly downloads
8
License
-
Repository
-
Last release
5 years ago

Maintainability Test Coverage

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.

OptionTypeDescription
interval - default = 100number (milliseconds)The interval at which the timer will count. The minimal value is 10.
idleThreshold - default = 5000number (milliseconds)The amount of time of not interacting with page after which the user is considered idle.
onTickfunctionA callback that will be called after each timer interval.
onIdlefunctionA callback that will be called after a user goes idle.
1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago