Trigger A Function When The User Goes Idle – idle-tracker

Category: Javascript | April 22, 2022
Author:roderickhsiao
Views Total:130 views
Official Page:Go to website
Last Update:April 22, 2022
License:MIT

Preview:

Trigger A Function When The User Goes Idle – idle-tracker

Description:

A small idle tracker library that tracks user interactions on the webpage and fires a callback function if the user goes idle.

Default events the library listens for:

  • change
  • keydown
  • mousedown
  • mousemove
  • mouseup
  • orientationchange
  • resize
  • scroll
  • touchend
  • touchmove
  • touchstart
  • visibilitychange

How to use it:

Install the library with package managers.

# Yarn
$ yarn add idle-tracker
# NPM
$ npm install idle-tracker --save

Import the idle-tracker.

import IdleTracker from 'idle-tracker';

Or load the umd version of the idle-tracker in the document.

<script src="dist/umd/index.js"></script>
<script src="dist/umd/active-events.js"></script>

Create a new Idle Tracker and specify the timeout, callback function, and active events.

var idelTracker = new Tracker({
    timeout: 3000,
    onIdleCallback: idleFunction,
    throttle: 500
    events: activeEvents.default
});

Start the idle tracker and done.

idelTracker.start();

Changelog:

04/22/2022

  • Release 0.1.2: Fixed false implicit type from DEFAULT_CALLBACK

03/31/2022

  • Release 0.1.1

09/09/2020

  • Release 0.0.8: Expose original event to callback function

09/02/2020

  • Release 0.0.7

03/13/2019

  • Fix function not removed on end

You Might Be Interested In:


Leave a Reply