统计pv和uv

(function () {

    var req, UID, ot;

    var expDays = 30;

    var exp = new Date();

    var isRefresh;

    exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));

    init();

    function init(a) {

        setUp();//启动cookies

        if (!window.remote_ip_info) {

            var s = document.createElement('script');

            s.onload = pullRequest;

            //加载新浪IP库

            s.type = 'text/javascript';

            s.src = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js';

            document.body.appendChild(s);

            s = null;

        }

 

        //检查脚本是否加载成功,否则重载

        ot = setInterval(function () {

            !!window.remote_ip_info ? clearInterval(ot) : init()

        }, 1500);

    }

    /*后台处理

    function pullRequest() {

        // 后台处理的文件地址

        var url = "http://t1.tuancity.com/analysis/rev.php";

            // 获取当前的网址

        var link = window.location.href;

            // 获取上页地址

        var oldlink = document.referrer;

            // 获取当前访问页的标题

        var titleName = document.title;

            // 屏幕分辨率

        var screen = window.screen.width + "*" + window.screen.height;

        // 异步请求发送

        $.ajax(

           {

               url: url + "?id=" + escape(link) + "&oldlink=" + escape(oldlink) + "&title=" + escape(titleName) + "&s=" + screen + "&p=" + remote_ip_info.province + "&c=" + remote_ip_info.city + "&guid=" + TY.storage.getCookie('GUID') + "&wwc=" + TY.storage.getCookie('WWHCount') + "&wwh=" + TY.storage.getCookie('WWhenH') + "&uv=" + TY.storage.getCookie('UVCount'),

               type: 'post',

               //data: { id: escape(link), oldlink: escape(oldlink), title: escape(titleName), s: screen, p: remote_ip_info.province, c: remote_ip_info.city,guid:TY.storage.getCookie('GUID'),wwc:TY.storage.getCookie('WWHCount'),wwh: TY.storage.getCookie('WWhenH'),uv: TY.storage.getCookie('UVCount')},

               success: function (data) {

 

               }

           });

    }

    // Cookies

    function setUp() {

        TY.storage.setCookie('GUID', Who(), false, exp);

        Count();

        CountUv();

        When();

    }

    function Who() {

        var GUID = TY.storage.getCookie('GUID');

        if (GUID == null||!GUID) {

            GUID = function () {

                return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {

                    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);

                    return v.toString(16);

                }).toUpperCase();

            };

            return GUID()

        }

        return GUID;

    }

 

    //访问时间

    function When() {

        var rightNow = new Date();

        var WWHTime = 0;

        WWHTime = TY.storage.getCookie('WWhenH');

        WWHTime = WWHTime * 1

        var lastHereFormatting = new Date(WWHTime);

        // 访问时间记录

        var intLastVisit = (lastHereFormatting.getYear() * 10000) + (lastHereFormatting.getMonth() * 100) + lastHereFormatting.getDate();

        var lastHereInDateFormat = "" + lastHereFormatting;

        var dayOfWeek = lastHereInDateFormat.substring(0, 3);

        var dateMonth = lastHereInDateFormat.substring(4, 11);

        var timeOfDay = lastHereInDateFormat.substring(11, 16);

        var year = lastHereInDateFormat.substring(23, 25);

        var WWHText = dayOfWeek + ", " + dateMonth + " at " + timeOfDay;

        TY.storage.setCookie("WWhenH", rightNow.getTime(), false, exp);

        return WWHText;

    }

 

    // 访问次数统计pv

    function Count() {

        var WWHCount = TY.storage.getCookie('WWHCount')

        if (WWHCount == null) {

            WWHCount = 1;

        }else {

            WWHCount++;

        }

        TY.storage.setCookie('WWHCount', WWHCount, false, exp);

        return WWHCount;

    }

    //访问uv次数。

    function CountUv() {

        var UVCount = TY.storage.getCookie('UVCount');

        var oldtime = TY.storage.getCookie('WWhenH');

        var newtime = new Date();

        var olddateMax = (parseInt(oldtime / 1000 / 60 / 60/24)+1)*24 * 3600 * 1000;

        if (UVCount == null) {

            UVCount = 1;

        }else {

            if (newtime>olddateMax)

                UVCount++;

        }

        TY.storage.setCookie('UVCount', UVCount,false, exp);

        return UVCount;

    }

}());

转载于:https://www.cnblogs.com/yyhuqd/p/6116662.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值