• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple js module to detect when the user is really using your page

activity-detector

npm npm Build Status

This module helps you detecting when the user becomes idle (does not interact with the page for some time) or active in your page.

Install

$ npm install --save activity-detector

Or load it from unpkg:

<script src="https://unpkg.com/activity-detector/dist/activity-detector.min.js"></script>

How to use

Basic example

import createActivityDetector from 'activity-detector';

const activityDetector = createActivityDetector();

activityDetector.on('idle', () => {
	console.log('The user is not interacting with the page');
});

activityDetector.on('active', () => {
	console.log('The user is using the page');
});

Advanced options

Activity detector allows you to configure some parameters:

  • timeToIdle: number of milliseconds of inactivity which makes activity detector transition to 'idle' (30000 by default)
  • 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']
  • inactivityEvents: the list of events which make the activity detector transition from 'active' to 'idle' without waiting for timeToIdle timeout. By default: ['blur']
  • ignoredEventsWhenIdle: list of events to ignore in idle state. By default: ['mousemove']
  • initialState: can be "idle" or "active" ("active" by default)
  • 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)

For example:

const activityDetector = createActivityDetector({
	timeToIdle: 20000, // wait 20s of inactivity to consider the user is idle
	autoInit: false // I don't want to start the activity detector yet.
});

activityDetector.on('idle', handleUserIdle);

...
...

// I want to start the activity detector now!
activityDetector.init();

Instance methods

An activity detector instance has the following methods:

init(initialState = 'active')

Initializes the activity detector in the given state. This method should only be used if you created the activity detector with the autoInit option false.

This method receives the initialState param. It can be 'idle' or 'active' (default)

on(event, handler)

Registers an event listener for the required event

event can be 'idle' or 'active'.

handler must be a function.

stop()

Stops the activity detector and cleans the listeners.

Development

Run tests

$ npm install
$ npm test

More Repositories

1

ButtonMenu

ButtonMenu is an Android library created to build user interfaces based on buttons. This library has been implemented using Model View ViewModel pattern combined with an Android custom view that extends LinearLayout.
Java
440
star
2

SmsRadar

Android library created to listen incoming and outgoing SMS's
Java
390
star
3

TUDelorean

TUDelorean helps you test your time-dependent Objetive-C code allowing you travel anywhere in time.
Objective-C
281
star
4

secrets-manager

A daemon to sync Vault secrets to Kubernetes secrets
Go
171
star
5

TUScheduler

TUScheduler is a very simple iOS library that solves the problem of asynchronous testing in an elegant and robust way. Furthermore, TUScheduler allows you to decouple your code from the underlying concurrency API.
Objective-C
36
star
6

animated-circle-progress-view

Progress view that animates its state changes.
Java
35
star
7

VideoRecorderService

VideoRecorderService is a lightweight web-based service that offers a REST interface to easily manage the recording of screen videos.
Java
35
star
8

pouch

Tools to provision secrets using Vault with AppRole authentication method
Go
32
star
9

sdp-to-jingle-java

Java
27
star
10

ikusth

Threads dependency graph generator
Java
25
star
11

kube2lb

Dinamically configure load balancers to expose Kubernetes services
Go
22
star
12

TMAERecorder

AVAudioRecorder replacement which allows audio recording with real time sound filtering. Implemented using The Amazing Audio Engine.
Objective-C
20
star
13

hiphop-php

Source code transformer from PHP to C++
C++
18
star
14

programming-challenge-2

Solutions and writeups from participants of the Tuenti Programming Challenge 2
Java
17
star
15

android-deferred

Java
14
star
16

python-repoman

Repoman is a python library designed to automate repository operations in release processes.
Python
13
star
17

TMInstanceMethodSwizzler

Method swizzling library for Objetive-C
Objective-C
13
star
18

TMDebugConsole

TMDebugConsole is a simple in-app console to be used with Cocoa Lumberjack. It allows you to see your logs on the device, without needing to be paired with a debug session in XCode, using different colors for errors, warnings, and informative messages
Objective-C
9
star
19

ldap-expire-notify

ldap-expire-notify is a tool to notify your LDAP users when their password is about to expire. It supports several kind of notification channels.
Python
9
star
20

supernanny

Java
8
star
21

haproxy-docker-wrapper

Docker-friendly wrapper for haproxy
Go
7
star
22

pyflapjackevents

Pyflapjackevents is a small library that serializes Flapjack events for the Python language
Python
7
star
23

simtron

TypeScript
4
star
24

php-json-rpc

Tuenti's implementation of json rpc according to the json-rpc spec 2.0 excluding events and batches. It provides the implementation of the objects described in the implementation and a json-rpc client.
PHP
4
star
25

tuenti-star-validator

Submission validator and score calculator for #TuentiChallenge6's Tuenti Star challenge
OCaml
4
star
26

geoip

C
1
star
27

tuenti-php-sdk

Tuenti PHP SDK for Applications
PHP
1
star