-2

I have a program which uses eventStart: new Date.getTime(); when the document is loaded and when user completes some section and click continue to go to next section I have setup the function to track the end time getting the eventEnd: new Date.getTime(); now I fall in to a unique situation to track the idle Time for so I can properly calculate the total time taken by the user to finish the section. Any help or documentation regarding this would be appreciated. Thanks.

user3886408
  • 1
  • 1
  • 3
  • 3
    what does idle time mean? do you want to subtract the time taken for the page to load, or simply find the difference between two numbers? – dandavis Aug 08 '14 at 19:07
  • Yes, Idle time means Inactive time (no mouse movement or keyboard activity). – user3886408 Aug 08 '14 at 20:33

1 Answers1

1

Depends on what you are calling idle time.

Check for user activity

You can use the mousemove event on the document.body and see if the user is interacting with the page at all. (I'd also check for tap and keyboard events, as users can scroll that way too.)

This can't, however, detect if the user is sitting there reading something without touching mouse or keyboard.

Is this tab the current one

There is a recommended API to see if the current window/tab is active, but that has limited support. There is a discussion here.

Community
  • 1
  • 1
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74
  • To offset the fact that users do have to stop moving mouse's or typing sometimes, you could set a set amount of time that needs to pass before the user can even be considered "idle" and only care about storing/reporting this somewhere after that has occurred. Maybe 30 seconds of no activity whatsoever would constitute "idle". But if you are doing this to time how long a user does to complete intermediary tasks, then every second counts. – Unome Aug 08 '14 at 19:58
  • Anybody have some code Regarding this to implement a functional approach. may be i can take a look at it. – user3886408 Aug 08 '14 at 20:34