【问题标题】:Calculate total time user has done activities on page like mousemove in jquery计算用户在页面上完成活动的总时间,例如 jquery 中的 mousemove
【发布时间】:2016-09-22 12:55:36
【问题描述】:

请帮助我。我必须找到用户在页面上完成活动的总时间,如鼠标移动、按键等。我想获得该页面被使用的有用时间。 我已经编写了一些代码来计算页面打开的总时间以及用户关注该页面的时间。

计算此有用时间的另一种方法是计算页面上的总空闲时间,对此没有进行任何操作(我的意思是鼠标移动、按键)。 有用时间=总页面打开时间-总空闲时间

请帮忙 这是代码。

var start, end, openingtime, pagefocustime = 0;
    $(document).ready(function(){       
      start = performance.now();

      $(window).on('blur', function() {
        end = performance.now();
        pagefocustime += end - start
      })

      $(window).on('focus', function() {
        start = performance.now();
      })
       
        $(window).on('beforeunload',function(){           
                end = performance.now();
                pagefocustime += end - start
                console.log("Exact Page Focused Time : ");
                console.log(pagefocustime);                       
                openingtime = end-start;
                console.log("Total Page Read Time : "+ openingtime);
        });           
});

请帮忙。 提前致谢。

【问题讨论】:

    标签: javascript jquery html angularjs


    【解决方案1】:

    这就是答案。将此代码与上述代码一起使用。

    function setup() {
    		this.addEventListener("mousemove", resetTimer, false);
    		this.addEventListener("mousedown", resetTimer, false);
    		this.addEventListener("keypress", resetTimer, false);
    		this.addEventListener("DOMMouseScroll", resetTimer, false);
    		this.addEventListener("mousewheel", resetTimer, false);
    		this.addEventListener("touchmove", resetTimer, false);
    		this.addEventListener("MSPointerMove", resetTimer, false); 
    		startTimer();
    	}
    	
    	setup(); 
    	 
    	function startTimer() {
    		timeoutID = window.setTimeout(goInactive, 10000);
    	}
    	 
    	function resetTimer(e) {
    		window.clearTimeout(timeoutID);
    	 
    		goActive();
    	}
    	 
    	function goInactive() {
    		idletime = idletime + inactivetime;
    	}
    	 
    	function goActive() {      
    		startTimer();
    	}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 2019-08-29
      相关资源
      最近更新 更多