# active-time-on-page

> Tracks active user time on page in seconds

Latest version **1.0.3** (published 2021-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install active-time-on-page
pnpm add active-time-on-page
yarn add active-time-on-page
bun add active-time-on-page
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-09-10 |
| First published | 2021-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Brandon Ho |
| Maintainers | bhsz |
| Keywords | tracking, time on page, user activity |

## Links

- npm: https://www.npmjs.com/package/active-time-on-page
- Repository: https://github.com/bhsz/time-on-page
- Homepage: https://github.com/bhsz/time-on-page#readme
- Issues: https://github.com/bhsz/time-on-page/issues
- npm.io page: https://npm.io/package/active-time-on-page

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2021-09-10
- 1.0.2 — 2021-09-05
- 1.0.1 — 2021-09-04
- 1.0.0 — 2021-09-04

## README

# Active Time on Page

Tracks active user time on page (ToP) in seconds.

<img src="./example.gif" style="border: 3px solid black" width="800" height="450" />

Example page can be found at [HERE](https://bhsz.me/AToP-example.html).

<br/>

# Installation

To use as vanilla Javascript, simply download and import `index.js` into your project.

To use with NPM, run `npm install active-time-on-page` from the command line.

<br/>

# API

### startTimerOnPage()

Starts timer on page. Listeners are added to the window's focus and blur events to toggle the timer.

### getTimeOnPage()

Returns active user ToP.

### clearTimerOnPage()

Clears the timer by using clearInterval.

<br/>

# Examples

Vanilla Javascript

```javascript
import { startTimerOnPage, getTimeOnPage } from "./index.js";

startTimerOnPage();

setInterval(() => {
	let ToP = getTimeOnPage();
	// Do something with ToP
}, 1000);
```

React and NPM

```javascript
import { startTimerOnPage, getTimeOnPage, clearTimerOnPage } from "active-time-on-page";

useEffect(() => {
	startTimerOnPage();

	let handler = setInterval(() => {
		let ToP = getTimeOnPage();
		// Do something with ToP
	}, 1000);

	return () => {
		clearTimerOnPage();
		clearInterval(handler);
	};
}, []);
```

<br/>

# Todo

<input type="checkbox" disabled /> Tests

---
_Source: https://npm.io/package/active-time-on-page · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
