• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

js统计网页在线时间的脚本

2022-2-5 17:01| 发布者: 菜鸟教程小白| 查看: 259| 评论: 0|原作者: [db:作者]|来自: [db:来源]

摘要: 分析用户行为时,某网页停留时间可能会是个可参考的数据 由后台分析函数取一个合理值作为在线时间
每xxxxx毫秒检测一次是否在线,
TR_COUNT次之后设定改用户为假死状态(即不在当前页面活动,afk..)
当页面关闭时把停留时间送出,

/**//* ----------------------------------------------------------------------------
* Script Name: online.js
* Last Modified: 2008-4-13 22:25
* Author: meyu
* Copyright (c) 2008
* Purpose: 跟踪在线时间
* ----------------------------------------------------------------------------*/

function TR_XMLHttpObject(url)...{
    this.XMLHttp=null;
    this.url=url;
    this.init=function()...{
        if(window.XMLHttpRequest)...{
            this.XMLHttp=new XMLHttpRequest();
        }else if(window.ActiveXObject)...{
            this.XMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    };
    this.init();
    this.sendData=function(param)...{
        with(this.XMLHttp)...{
            open('GET',this.url+(param||''),true);
            send(null);
        }
    };
}
if(/flag=flush/i.test(window.location.search))...{
    var TR_COUNT=0;
    var TR_x=new TR_XMLHttpObject(window.location.href.replace(/&?(?:flush_count=)(d+)/i,
        function(a,d)...{
            TR_COUNT=parseInt(d);
            return "";
            })
    );
    function send()...{
        TR_COUNT++;
        if(TR_COUNT < 120)...{
            TR_x.sendData('&flush_count='+TR_COUNT);
        }
    }
    window.setInterval(send,30000);
    window.onunload=function()...{TR_x.sendData('&flush_count='+TR_COUNT);};
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap