Skip to content

Commit

Permalink
Merge pull request #5 from yarooze/master
Browse files Browse the repository at this point in the history
windowResize, visibilityChange
  • Loading branch information
TA3 authored Jun 25, 2024
2 parents d1ff2a1 + 144c722 commit 8f2acc9
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions userBehaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var userBehaviour = (function () {
timeCount: true,
clearAfterProcess: true, // todo
processTime: 15,
windowResize: true,
visibilitychange: true,
processData: function (results) {
console.log(results);
},
Expand All @@ -26,6 +28,8 @@ var userBehaviour = (function () {
scroll: null,
click: null,
mouseMovement: null,
windowResize: null,
visibilitychange: null
},
eventsFunctions: {
scroll: () => {
Expand All @@ -50,6 +54,14 @@ var userBehaviour = (function () {
},
mouseMovement: (e) => {
mem.mousePosition = [e.clientX, e.clientY, getTimeStamp()];
},
windowResize: (e) => {
results.windowSizes.push([window.innerWidth, window.innerHeight, getTimeStamp()]);
},
visibilitychange: (e) => {
results.visibilitychanges.push([document.visibilityState, getTimeStamp()]);
processResults();
// stop();
}
}
};
Expand All @@ -58,6 +70,7 @@ var userBehaviour = (function () {
function resetResults() {
results = {
userInfo: {
windowSize: [window.innerWidth, window.innerHeight],
appCodeName: navigator.appCodeName || '',
appName: navigator.appName || '',
vendor: navigator.vendor || '',
Expand All @@ -67,6 +80,7 @@ var userBehaviour = (function () {
time: { //todo
startTime: 0,
currentTime: 0,
stopTime: 0,
},
clicks: {
clickCount: 0,
Expand All @@ -76,7 +90,8 @@ var userBehaviour = (function () {
mouseScroll: [],
contextChange: [], //todo
//keyLogger: [], //todo

windowSizes: [],
visibilitychanges: [],
}
};
resetResults();
Expand Down Expand Up @@ -121,10 +136,20 @@ var userBehaviour = (function () {
if (user_config.mouseScroll) {
mem.eventListeners.scroll = window.addEventListener("scroll", mem.eventsFunctions.scroll);
}
//Window sizes
if (user_config.windowResize !== false) {
// mem.eventsFunctions.windowResize();
mem.eventListeners.windowResize = window.addEventListener("resize", mem.eventsFunctions.windowResize);
}
//Before unload / visibilitychange
if (user_config.visibilitychange !== false) {
mem.eventListeners.visibilitychange = window.addEventListener("visibilitychange", mem.eventsFunctions.visibilitychange);
}

//PROCESS INTERVAL
if (user_config.processTime !== false) {
mem.processInterval = setInterval(() => {
user_config.processData(result());
processResults();
}, user_config.processTime * 1000)
}
};
Expand All @@ -144,6 +169,10 @@ var userBehaviour = (function () {
window.removeEventListener("scroll", mem.eventsFunctions.scroll);
window.removeEventListener("click", mem.eventsFunctions.click);
window.removeEventListener("mousemove", mem.eventsFunctions.mouseMovement);
window.removeEventListener("resize", mem.eventsFunctions.windowResize);
window.removeEventListener("visibilitychange", mem.eventsFunctions.visibilitychange);
results.time.stopTime = getTimeStamp();
processResults();
}

function result() {
Expand Down

0 comments on commit 8f2acc9

Please sign in to comment.