open-index/open-npm huggingface dataset:
npm package: @studyportals/timespenttimer
Description: A timer to track the amount of time someone was on your page or element
Author: samurai-pizza-cats
Latest version: 1.0.3

[![Maintainability](https://api.codeclimate.com/v1/badges/586d48b156b6fbd94c88/maintainability)](https://codeclimate.com/repos/5c6d8962aac1110286000001/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/586d48b156b6fbd94c88/test_coverage)](https://codeclimate.com/repos/5c6d8962aac1110286000001/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.

``` bash
# 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
```javascript
// 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. |