{"id":13630474,"url":"https://github.com/tuenti/activity-detector","last_synced_at":"2025-04-06T06:13:45.887Z","repository":{"id":55541027,"uuid":"52147168","full_name":"tuenti/activity-detector","owner":"tuenti","description":"Simple js module to detect when the user is really using your page","archived":false,"fork":false,"pushed_at":"2020-12-22T23:31:06.000Z","size":19,"stargazers_count":139,"open_issues_count":7,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T05:08:26.432Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuenti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-20T09:59:51.000Z","updated_at":"2025-03-15T11:11:05.000Z","dependencies_parsed_at":"2022-08-15T02:50:41.121Z","dependency_job_id":null,"html_url":"https://github.com/tuenti/activity-detector","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuenti%2Factivity-detector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuenti%2Factivity-detector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuenti%2Factivity-detector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuenti%2Factivity-detector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuenti","download_url":"https://codeload.github.com/tuenti/activity-detector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441062,"owners_count":20939239,"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":[],"created_at":"2024-08-01T22:01:44.353Z","updated_at":"2025-04-06T06:13:45.868Z","avatar_url":"https://github.com/tuenti.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# activity-detector\n\n[![npm](https://img.shields.io/npm/v/activity-detector.svg)](https://www.npmjs.com/package/activity-detector)\n[![npm](https://img.shields.io/npm/l/activity-detector.svg)](https://www.npmjs.com/package/activity-detector)\n[![Build Status](https://travis-ci.org/tuenti/activity-detector.svg)](https://travis-ci.org/tuenti/activity-detector)\n\nThis module helps you detecting when the user becomes idle (does not interact with the page for some time) or active in your page.\n\n## Install\n```\n$ npm install --save activity-detector\n```\n\nOr load it from unpkg:\n```html\n\u003cscript src=\"https://unpkg.com/activity-detector/dist/activity-detector.min.js\"\u003e\u003c/script\u003e\n```\n\n## How to use\n\n### Basic example\n\n```javascript\nimport createActivityDetector from 'activity-detector';\n\nconst activityDetector = createActivityDetector();\n\nactivityDetector.on('idle', () =\u003e {\n\tconsole.log('The user is not interacting with the page');\n});\n\nactivityDetector.on('active', () =\u003e {\n\tconsole.log('The user is using the page');\n});\n```\n\n### Advanced options\n\nActivity detector allows you to configure some parameters:\n- `timeToIdle`: number of milliseconds of inactivity which makes activity detector transition to 'idle' (`30000` by default)\n- `activityEvents`: the user events which make activity detector transition from 'idle' to 'active'. The default list of activityEvents is `['click', 'mousemove', 'keydown', 'DOMMouseScroll', 'mousewheel', 'mousedown', 'touchstart', 'touchmove', 'focus']`\n- `inactivityEvents`: the list of events which make the activity detector transition from 'active' to 'idle' without waiting for `timeToIdle` timeout. By default: `['blur']`\n- `ignoredEventsWhenIdle`: list of events to ignore in idle state. By default: `['mousemove']`\n- `initialState`: can be `\"idle\"` or `\"active\"` (`\"active\"` by default)\n- `autoInit`: when `true` the activity detector starts just after creation, when `false`, it doesn't start until you call the `.init()` method (`true` by default)\n\nFor example:\n```javascript\nconst activityDetector = createActivityDetector({\n\ttimeToIdle: 20000, // wait 20s of inactivity to consider the user is idle\n\tautoInit: false // I don't want to start the activity detector yet.\n});\n\nactivityDetector.on('idle', handleUserIdle);\n\n...\n...\n\n// I want to start the activity detector now!\nactivityDetector.init();\n\n```\n\n### Instance methods\n\nAn activity detector instance has the following methods:\n\n#### `init(initialState = 'active')`\n\nInitializes the activity detector in the given state. This method should only be used if you created the activity detector with the `autoInit` option `false`.\n\nThis method receives the `initialState` param. It can be `'idle'` or `'active'` (default)\n\n#### `on(event, handler)`\n\nRegisters an event listener for the required event\n\n`event` can be `'idle'` or `'active'`.\n\n`handler` must be a function.\n\n#### `stop()`\n\nStops the activity detector and cleans the listeners.\n\n## Development\n\n### Run tests\n\n```\n$ npm install\n$ npm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuenti%2Factivity-detector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuenti%2Factivity-detector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuenti%2Factivity-detector/lists"}