{"id":13452449,"url":"https://github.com/atlassian/browser-interaction-time","last_synced_at":"2025-03-23T19:34:18.552Z","repository":{"id":33975109,"uuid":"163830439","full_name":"atlassian/browser-interaction-time","owner":"atlassian","description":"⏰ A JavaScript library (written in TypeScript) to measure the time a user is active on a website","archived":false,"fork":false,"pushed_at":"2024-04-07T08:37:34.000Z","size":5274,"stargazers_count":211,"open_issues_count":48,"forks_count":14,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-04-14T12:07:26.639Z","etag":null,"topics":["active","activity","browser","interaction","performance","time","tracking","typescript"],"latest_commit_sha":null,"homepage":"https://atlassian.github.io/browser-interaction-time/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atlassian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-02T11:06:00.000Z","updated_at":"2024-06-18T18:22:20.021Z","dependencies_parsed_at":"2024-06-18T18:22:04.493Z","dependency_job_id":"75f2bbff-e516-4049-8ba7-3ba8f57622fa","html_url":"https://github.com/atlassian/browser-interaction-time","commit_stats":{"total_commits":224,"total_committers":7,"mean_commits":32.0,"dds":0.6830357142857143,"last_synced_commit":"7fec9483c6c1c2f174506131e380514ec7aa8fa0"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fbrowser-interaction-time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fbrowser-interaction-time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fbrowser-interaction-time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fbrowser-interaction-time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atlassian","download_url":"https://codeload.github.com/atlassian/browser-interaction-time/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245159390,"owners_count":20570375,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["active","activity","browser","interaction","performance","time","tracking","typescript"],"created_at":"2024-07-31T07:01:24.443Z","updated_at":"2025-03-23T19:34:17.871Z","avatar_url":"https://github.com/atlassian.png","language":"TypeScript","readme":"\u003cp align=\"left\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/atlassian/browser-interaction-time/master/bit.png\" width=\"200\" /\u003e\n\u003c/p\u003e\n\n# browser-interaction-time\n\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/atlassian/browser-interaction-time/issues)\n[![license](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/atlassian/browser-interaction-time/master/LICENSE)\n[![Build Status](https://travis-ci.org/atlassian/browser-interaction-time.svg?branch=master)](https://travis-ci.org/atlassian/browser-interaction-time)\n[![npm](https://img.shields.io/npm/v/browser-interaction-time.svg)](https://www.npmjs.com/package/browser-interaction-time)\n[![SemVer](https://img.shields.io/badge/SemVer-2.0.0-brightgreen.svg)](http://semver.org/spec/v2.0.0.html)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![Greenkeeper badge](https://badges.greenkeeper.io/atlassian/browser-interaction-time.svg)](https://greenkeeper.io/)\n\nBrowserInteractionTime lets you track the time a user is active on your webpage while ignoring time spent on a different tab or with a minimized window. It also ignores the time spent while the user is idle on a web page meaning after a certain amount of time (idleTimeoutMs) without any user interactions (scroll, mousemovement etc) the time will stop until the next user interaction.\n\n## Importing BrowserInteractionTime\n\nYou can import the generated bundle to use the whole library like this:\n\n```javascript\nimport BrowserInteractionTime from 'browser-interaction-time'\n```\n\nAdditionally, you can import the transpiled modules from `dist/lib`:\n\n```javascript\nimport BrowserInteractionTime from 'browser-interaction-time/dist/lib/'\n```\n\n## API\n\n### Initialize\n\n```js\nimport BrowserInteractionTime from 'browser-interaction-time'\n\nconst browserInteractionTime = new BrowserInteractiontime({\n  timeIntervalEllapsedCallbacks: [],\n  absoluteTimeEllapsedCallbacks: [],\n  browserTabInactiveCallbacks: [],\n  browserTabActiveCallbacks: [],\n  idleTimeoutMs: 3000,\n  checkCallbacksIntervalMs: 250\n})\n```\n\n### Start timer\n\n```js\nbrowserInteractionTime.startTimer()\n```\n\n### Stop timer\n\n```js\nbrowserInteractionTime.stopTimer()\n```\n\n### Adding a callback that is executed on interval\n\n```js\nconst cb = {\n  multiplier: time =\u003e time * 2,\n  timeInMilliseconds: 1000,\n  callback: () =\u003e console.log('callback')\n}\nbrowserInteractionTime.addTimeIntervalEllapsedCallback(cb)\n```\n\n### Adding a callback that is executed on absolute time\n\n```js\nconst callbackData = {\n  timeInMilliseconds: 1000,\n  callback: () =\u003e console.log('callback')\n  pending: true\n}\nbrowserInteractionTime.addAbsoluteTimeEllapsedCallback(callbackData)\n```\n\n### Adding callback executed when browser tab becomes inactive\n\n```js\nconst callback = () =\u003e console.log('some callback')\nbrowserInteractionTime.addBrowserTabInactiveCallback(callback)\n```\n\n### Adding callback executed when browser tab becomes active\n\n```js\nconst callback = () =\u003e console.log('some callback')\nbrowserInteractionTime.addBrowserTabActiveCallback(callback)\n```\n\n### Set a mark on modified timeline (see https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark)\n\n```js\nbrowserInteractionTime.mark('a-mark')\nbrowserInteractionTime.mark('b-mark')\n```\n\n### Get marks by name (see https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark)\n\n```js\nbrowserInteractionTime.getMarks('a-mark')\n```\n\n### Set measure time between 2 marks (see https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure)\n\n```js\nbrowserInteractionTime.measure('a-measure', 'a-mark', 'b-mark')\n```\n\n### Get measure by name\n\n```js\nbrowserInteractionTime.getMeasures('a-measure') // Array of measures with name\n```\n\n### Get Time in Milliseconds\n\n```js\nbrowserInteractionTime.getTimeInMilliseconds() // number\n```\n\n### Check if timer is running\n\n```js\nbrowserInteractionTime.isRunning() // boolean\n```\n\n### Reset all times\n\n```js\nbrowserInteractionTime.reset()\n```\n\n### Cleanup event listeners and timers\n\n```js\nbrowserInteractionTime.destroy()\n```\n\n## NPM scripts\n\n- `npm t`: Run test suite\n- `npm start`: Run `npm run build` in watch mode\n- `npm run test:watch`: Run test suite in [interactive watch mode](http://facebook.github.io/jest/docs/cli.html#watch)\n- `npm run test:prod`: Run linting and generate coverage\n- `npm run build`: Generate bundles and typings, create docs\n- `npm run lint`: Lints code\n- `npm run commit`: Commit using conventional commit style ([husky](https://github.com/typicode/husky) will tell you to use it if you haven't :wink:)\n\n## Author\n\nMaximilian Heinz [@_meandmax_](https://twitter.com/_meandmax_)\n\n## Collaborators\n\n❤️ Logo Design by [Dominik Straka](http://www.dominikstraka.de/)\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlassian%2Fbrowser-interaction-time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatlassian%2Fbrowser-interaction-time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlassian%2Fbrowser-interaction-time/lists"}