Last active
June 2, 2018 01:12
-
-
Save AlexR1712/68da3c0a78d8839b87c34c4433f759d2 to your computer and use it in GitHub Desktop.
Time Activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Script for track user activity in page and out the page | |
var timeActiveOnSite = 0; // seconds | |
var timeInactive = 0; // seconds | |
var lastActivityDatetime; | |
window.setInterval(function(){ | |
if(document['visibilityState'] === 'visible'){ | |
timeActiveOnSite++; | |
lastActivityDatetime = Date.now(); | |
} else { | |
timeInactive++; | |
var timeDiff = Date.now() + (timeInactive * 1000) | |
if( (timeDiff - Date.now()) > 10*1000 ) { // 10 seconds inactity invokes alert | |
alert('User is inactive, clear session data!'); | |
} | |
} | |
},1000); | |
console.log('Last Activity Date time', lastActivityDatetime); | |
console.log('Seconds spended on site', timeActiveOnSite); | |
console.log('Seconds out the site', timeActiveOnSite); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment