流量統計分析---百度流量統計js破解


   最近准備實現一個流量分析的系統的,所以就研究了國外和國內的網流流量分析系統。數據分析首先是收集用戶數據,就把百度和google前台收集數據的源碼進行了還原分析,發現前台js還干了這么多事情,真讓人驚嘆。下面是代碼,供做流量分析的同行門參才一下。百度全部完成且測試通過,google完成了60%.完成后也一起貼出來,供大家參考。

百度流量分析js代碼如下:

 

 

(function () {
    var c =
    { id: "22b5f4c756a2ab0c32b32d4a8f79ab2f",
        dm: ["vmall.com"], etrk: [],
        js: "tongji.baidu.com/hm-web/js/",
        icon: '',
        br: false,
        ctrk: true,
        align: 1,
        nv: -1,
        vdur: 1800000,
        age: 31536000000,
        se: [
        [1, 'baidu.com', 'word|wd', 1, 'news,tieba,zhidao,mp3,image,video,hi,baike,wenku,opendata,jingyan'],
        [2, 'google.com', 'q', 0, 'tbm=isch,tbm=vid,tbm=nws|source=newssearch,tbm=blg,tbm=frm'],
        [4, 'sogou.com', 'query', 1, 'news,mp3,pic,v,gouwu,zhishi,blogsearch'],
        [6, 'search.yahoo.com', 'p', 1, 'news,images,video'],
        [7, 'yahoo.cn', 'q', 1, 'news,image,music'],
        [8, 'soso.com', 'w', 1, 'image,video,music,sobar,wenwen,news,baike'],
        [11, 'youdao.com', 'q', 1, 'image,news,,mp3,video'],
        [12, 'gougou.com', 'search', 1, ',movie,,,,,video'],
        [13, 'bing.com', 'q', 2, 'images,videos,news'],
        [14, 'so.com', 'q', 1, 'video,news'],
        [15, 'jike.com', 'q', 1, 'news,image,video'],
        [16, 'qihoo.com', 'kw', 0, ''],
        [17, 'etao.com', 'q', 1, 's,8'],
        [18, 'soku.com', 'keyword', 2, 'a']
        ]
    };
    var true_g = true, null_h = null, false_i = false;
    function setcookie_k(a, b, d) {
        var e;
        d.i && (e = new Date, e.setTime(e.getTime() + d.i));
        document.cookie = a + "=" + b + (d.domain ? "; domain=" + d.domain : "") + (d.path ? "; path=" + d.path : "") + (e ? "; expires=" + e.toGMTString() : "") + (d.N ? "; secure" : "");
        //alert(document.cookie);
    };

    (function () {
        function a() { if (!a.e) { a.e = true_g; for (var b = 0, d = e.length; b < d; b++) e[b]() } }
        function b() {
            try {
                document.documentElement.doScroll("left");
            }
            catch (d) {
                setTimeout(b, 1);
                return
            }
            a();
        }
        var d = false_i, e = [], f;
        document.addEventListener ? f = function () { document.removeEventListener("DOMContentLoaded", f, i); a() } :
        document.attachEvent && (f = function () { document.readyState === "complete" && (document.detachEvent("onreadystatechange", f), a()) });

        (function () {
            if (!d) if (d = true_g, document.readyState === "complete") a.e = true_g;
            else
                if (document.addEventListener)
                    document.addEventListener("DOMContentLoaded", f, i), window.addEventListener("load", a, i);
                else if (document.attachEvent) {
                    document.attachEvent("onreadystatechange", f);
                    window.attachEvent("onload", a);
                    var e = false_i;
                    try { e = window.frameElement == null_h } catch (l) { }
                    document.documentElement.doScroll && e && b();
                }
        })();
        return function (b) { a.e ? b() : e.push(b) };
    })().e = false_i;

    function SeessionStorage_m(a, b)
    { if (window.sessionStorage) try { window.sessionStorage.setItem(a, b) } catch (d) { } }

    function GetSessionStorage_n(a) {
        return window.sessionStorage ? window.sessionStorage.getItem(a) : null_h
    };
    //在a指定的url中取指定變量的值
    function GetKeyWordFromURL_o(a, b) {
        //
        var d = a.match(RegExp("(^|&|\\?|#)(" + b + ")=([^&#]*)(&|$|#)", ""));
        return d ? d[3] : null_h;
    }
    //刪除url中的http協議和端口號
    function DeleteHttpAndPortForURL_p(a) {
        var b;
        return (b = (a = a.match(/^(https?:\/\/)?([^\/\?#]*)/)) ? a[2].replace(/.*@/, "") : null_h, a = b) ? a.replace(/:\d+$/, "") : a;
    };
    //q=瀏覽器版本
    var q = /msie (\d+\.\d+)/i.test(navigator.userAgent), r = navigator.cookieEnabled, s = navigator.javaEnabled(),
     t = navigator.language || navigator.browserLanguage || navigator.systemLanguage || navigator.userLanguage || "",
     u = window.screen.width + "x" + window.screen.height,
     v = window.screen.colorDepth;

    //圖片請求向服務器提交數據
    function PostDataToServer_w(a, b) {
        var d = new Image, e = "mini_tangram_log_" + Math.floor(Math.random() * 2147483648).toString(36);
        window[e] = d;
        d.onload = d.onerror = d.onabort = function ()
        { d.onload = d.onerror = d.onabort = null_h; d = window[e] = null_h; b && b(a) };
        d.src = a
    };
    //增加對象事件
    function EventAdd_x(a, b, d) {
        a.attachEvent ? a.attachEvent("on" + b, function (b) { d.call(a, b) }) : a.addEventListener && a.addEventListener(b, d, i)
    };
    var y;
    //兼容控制本地方法
    function LocalStor2_z() {
        if (!y) try {
            y = document.createElement("input"), y.type = "hidden", y.style.display = "none",
            y.addBehavior("#default#userData"), document.getElementsByTagName("head")[0].appendChild(y);
        } catch (a) { return i }
        return true_g
    };

    c.se.push([14, "so.360.cn", "q", 1, ",news"]);
    c.se.push([14, "v.360.cn", "q", 1, "so"]);

    var A = 0, EnterTime_C = (new Date).getTime(),
        HttpProtocol_D = window.location.protocol == "https:" ? "https:" : "http:",
        SendToServerValue_E = "cc,cf,ci,ck,cl,cm,cp,cw,ds,ep,et,fl,ja,ln,lo,lt,nv,rnd,sb,se,si,st,su,sw,sse,v,cv,lv,u,api".split(",");

    function F() {
        if (typeof window["_bdhm_loaded_" + c.id] == "undefined")
            window["_bdhm_loaded_" + c.id] = true_g, this.a = {}, this.b = [], this.j = {}, this.f = 0,
            this.Start_G();
    }

    F.prototype = {
        //360瀏覽器 17是360. ok
        Is360_D: function () {
            var a = "";
            try {
                external.twGetVersion(external.twGetSecurityID(window)) && external.twGetRunPath.toLowerCase().indexOf("360se") > -1 && (a = 17)
            }
            catch (b)
            { }
            return a;
        },
        //a是否是b的二級域名 ok
        IsSecondDomainName_k: function (a, b) {
            var a = a.replace(/:\d+/, ""), b = b.replace(/:\d+/, ""), d = a.indexOf(b);
            return d > -1 && d + b.length == a.length;
        },
        //a和b的域名是否相同
        IsHaveSameDomainName_q: function (a, b) {
            a = a.replace(/^https?:\/\//, "");
            return a.indexOf(b) == 0;
        },
        //二級域名或者是相同域名
        IsHaveSameDomainNameIn_d: function (a) {
            for (var b = 0; b < c.dm.length; b++)
                if (c.dm[b].indexOf("/") > -1) {
                    if (this.IsHaveSameDomainName_q(a, c.dm[b]))
                        return true_g;
                }
                else {
                    var d = DeleteHttpAndPortForURL_p(a);
                    if (d && this.IsSecondDomainName_k(d, c.dm[b]))
                        return true_g;
                }
            return false_i;
        },
        //在指定的查找二級域名,找不到返回window.location.hostname
        FindSeconDomainNameUseHostNameIn_o: function () {
            for (var a = window.location.hostname, b = 0, d = c.dm.length; b < d; b++)
                if (this.IsSecondDomainName_k(a, c.dm[b]))
                    return c.dm[b].replace(/(:\d+)?[\/\?#].*/, "");
            return a;
        },
        //當前網站是否和指定域名列表中的相同,相同返回域名,不同則返回“/”
        FindDomainNameUseHrefIn_p: function () {
            for (var a = 0, b = c.dm.length; a < b; a++) {
                var d = c.dm[a];
                if (d.indexOf("/") > -1 && this.IsHaveSameDomainName_q(window.location.href, d))
                    return d.replace(/^[^\/]+(\/.*)/, "$2") + "/";
            }
            return "/";
        },
        //頁面進入方式確定 2=從指定搜索引擎進入的頁面 1=第一次進入時沒有存儲值或者刷新直接進入的頁面超過半小時 4=域名進入且刷新頁面時不超過半小時 3=從其它模塊過來,但不是指定域名
        PageEnterType_F: function () {
            if (document.referrer)
                for (var a = 0, b = c.se.length; a < b; a++) {
                    if (RegExp(c.se[a][1]).test(DeleteHttpAndPortForURL_p(document.referrer))) {
                        var d = GetKeyWordFromURL_o(document.referrer, c.se[a][2]) || "";
                        //2=google 14=so.com 17=etao.com
                        if (d || !(c.se[a][0] != 2 && c.se[a][0] != 14 && c.se[a][0] != 17)) {
                            c.se[a][0] == 1 && document.referrer.indexOf("cpro.baidu.com") > -1 && (d = "");
                            this.a.se = c.se[a][0];
                            //所在搜索引擎的頻道
                            for (var b = this.a, e = c.se[a], a = 0, f = e[3] == 2 ? e[1] + "/" : "", j = e[3] == 1 ? "." + e[1] : "", e = e[4].split(","), l = 0, B = e.length; l < B; l++)
                                if (e[l] !== "" && RegExp(f + e[l] + j).test(document.referrer)) {
                                    a = l + 1;
                                    break;
                                }
                            b.sse = a;
                            this.a.sw = d;
                            return 2;
                        }
                    }
                }
            else {
                //C=當前時間 A=進入時存儲的時間 半小時
                return EnterTime_C - A > c.vdur ? 1 : 4;
            }
            d = false_i;
            return (d = this.IsHaveSameDomainNameIn_d(document.referrer) && this.IsHaveSameDomainNameIn_d(window.location.href) ? true_g : this.IsSecondDomainName_k(DeleteHttpAndPortForURL_p(document.referrer) || "", window.location.hostname)) ? (EnterTime_C - A > c.vdur ? 1 : 4) : 3;
        },
        //cookie中取值,否則去瀏覽器存儲中取值,無值時返回空
        getData: function (a) {
            try {
                var b, d = RegExp("(^| )" + a + "=([^;]*)(;|$)").exec(document.cookie);
                // alert(d);
                //cookie值為空進入,cookie有相關值直接返回。無值時到瀏覽器中去取值
                if (!(b = d ? d[2] : null_h)) {
                    var e;
                    //會話中讀取
                    if (!(e = window.GetSessionStorage_n(a)))
a:
                    {
                        if (window.localStorage) {
                            var f = window.localStorage.getItem(a);
                            if (f) {
                                var j = f.indexOf("|"), l = f.substring(0, j) - 0;
                                //未過期取值
                                if (l && l > (new Date).getTime())
                                { e = f.substring(j + 1); break a }
                            }
                        } else if (LocalStor2_z()) try {
                            y.load(window.location.hostname);
                            e = y.getAttribute(a); break a
                        } catch (B) { }
                        e = null_h;
                    }
                    b = e
                } return b
            } catch (M) { }
        },
        //存儲值,cookie必存,本地和session選擇存儲。 本地格式: 一年后的時間|當前時間
        setData: function (a, b, d) {
            try {
                if (setcookie_k(a, b, { domain: this.FindSeconDomainNameUseHostNameIn_o(), path: this.FindDomainNameUseHrefIn_p(), i: d }), d) {
                    var e = new Date; e.setTime(e.getTime() + d || 31536E6);
                    try {
                        if (window.localStorage) b = e.getTime() + "|" + b, window.localStorage.setItem(a, b);
                        else
                            if (LocalStor2_z())
                                y.expires = e.toUTCString(), y.load(window.location.hostname), y.setAttribute(a, b), y.save(window.location.hostname);
                    } catch (f) { }
                }
                else
                    SeessionStorage_m(a, b);
            } catch (j) { }
        },
        //清空cookie值且刪除會話和localstorage值
        RemoveCookieAndLocalValue_H: function (a) {
            try {
                if (setcookie_k(a, "", { domain: this.FindSeconDomainNameUseHostNameIn_o(), path: this.FindDomainNameUseHrefIn_p(), i: -1 }), window.sessionStorage && window.sessionStorage.removeItem(a), window.localStorage)
                    window.localStorage.removeItem(a);
                else
                    if (LocalStor2_z())
                        try {
                            y.load(window.location.hostname), y.removeAttribute(a), y.save(window.location.hostname)
                        } catch (b) { }
            } catch (d) { }
        },
        // 處理存儲值並更改傳到服務端的值
        ProStorageValue_K: function () {
            var a, b, d, e, f;
            A = this.getData("Hm_lpvt_" + c.id) || 0;
            b = this.PageEnterType_F(); //第一次進入返回1

            //頁面進入類型
            a = b != 4 ? 1 : 0;
            //localstorage中取
            if (d = this.getData("Hm_lvt_" + c.id)) {
                //存儲大於30天
                for (e = d.split(","); EnterTime_C - e[0] > 2592E6; )
                    e.shift();
                f = e.length < 4 ? 2 : 3;
                for (a === 1 && e.push(EnterTime_C); e.length > 4; )
                    e.shift();
                d = e.join(",");
                e = Math.round((e[e.length - 1] - 0) / 1E3)
            }
            else
                d = EnterTime_C, e = "", f = 1;
            //localstorage中存儲
            this.setData("Hm_lvt_" + c.id, d, c.age);
            //sessionstorage中存
            this.setData("Hm_lpvt_" + c.id, EnterTime_C);
            d = EnterTime_C == this.getData("Hm_lpvt_" + c.id) ? "1" : "0";
            //c.nv=-1,該值不變
            if (c.nv == 0 && this.IsHaveSameDomainNameIn_d(window.location.href) && (document.referrer == "" || this.IsHaveSameDomainNameIn_d(document.referrer)))
                a = 0, b = 4;

            this.a.nv = a; this.a.st = b; this.a.cc = d; this.a.lt = e; this.a.lv = f;
        },
        //生成到達服務端的數據
        GenerateValueToServer_w: function () {
            for (var a = [], b = 0, d = SendToServerValue_E.length; b < d; b++) {
                var e = SendToServerValue_E[b], f = this.a[e];
                typeof f != "undefined" && f !== "" && a.push(e + "=" + encodeURIComponent(f))
            } return a.join("&");
        },
        //准備發到服務端的共它其它數據 ok
        ReadyOtherValue_L: function () {
            this.ProStorageValue_K();
            this.a.si = c.id;
            this.a.su = document.referrer;
            this.a.ds = u;
            this.a.cl = v + "-bit";
            this.a.ln = t;
            this.a.ja = s ? 1 : 0;
            this.a.ck = r ? 1 : 0;
            this.a.lo = typeof _bdhm_top == "number" ? 1 : 0;
            var a = this.a, b = "";
            if (navigator.plugins && navigator.mimeTypes.length) {
                var d = navigator.plugins["Shockwave Flash"];
                d && d.description && (b = d.description.replace(/^.*\s+(\S+)\s+\S+$/, "$1"))
            }
            else if (window.ActiveXObject)
                try {
                    if (d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))
                        (b = d.GetVariable("$version")) && (b = b.replace(/^.*\s+(\d+),(\d+).*$/, "$1.$2"))
                } catch (e) { } a.fl = b;
            this.a.sb = this.Is360_D();
            this.a.v = "1.0.34";
            this.a.cv = decodeURIComponent(this.getData("Hm_cv_" + c.id) || "");
            this.a.api = 0;
            a = window.location.href;
            this.a.cm = GetKeyWordFromURL_o(a, "hmmd") || "";
            this.a.cp = GetKeyWordFromURL_o(a, "hmpl") || "";
            this.a.cw = GetKeyWordFromURL_o(a, "hmkw") || "";
            this.a.ci = GetKeyWordFromURL_o(a, "hmci") || "";
            this.a.cf = GetKeyWordFromURL_o(a, "hmsr") || "";
        },
        //入口
        Start_G: function () {
            var a = this;
            try {
                //處理其它上傳數據
                a.ReadyOtherValue_L();
                //進入類型不一樣,調用方法不一樣。第一次輸入域名進入為1,第二次未超過半小時nv=0
                //只有頁面進入方式為4時,才需要處理歷史數據
                //a.RemoveOldValueAndSaveNewValue_l(".*");
                a.a.nv == 0 ? a.PostSessionStorageDataToServer_J() : a.RemoveOldValueAndSaveNewValue_l(".*");
                a.LoadLogo_z();
                a.LoadJS_B();

                a.AddEventForDocumentObject_n && a.AddEventForDocumentObject_n();

                a.AddMouseupAndBeforeUnloadEventForDocument_m && a.AddMouseupAndBeforeUnloadEventForDocument_m();

                a.h = new AddFoucsAndBlureEventForWindow_G;
                //alert("gg");
                EventAdd_x(window, "beforeunload", a.StartToServer_I());
                if (a.Pro_hmtValue_C()) {
                    var b = window._hmt;
                    if (b && b.length)
                        for (var d = 0; d < b.length; d++)
                            a.j[d] = b[d];
                    //
                    a.j.push = function () { a.t.apply(a, arguments) };
                    window._hmt = a.j;
                }
                //未定義時則提交數據到服務端,或者_bdhm_autoPageview=true時,則提交數據到服務端
                if (typeof window._bdhm_autoPageview === "undefined" || window._bdhm_autoPageview === true_g)
                    a.a.et = 0, a.a.ep = "", a.SendDataToServer_c();
            }
            catch (e) {
                b = [], b.push("si=" + c.id), b.push("n=" + encodeURIComponent(e.name)),
                b.push("m=" + encodeURIComponent(e.message)),
                b.push("r=" + encodeURIComponent(document.referrer)),
                PostDataToServer_w(HttpProtocol_D + "//hm.baidu.com/hm.gif?" + b.join("&"));
            }
        },
        //計算時間並發送數據到服務端
        StartToServer_I: function () {
            // event.returnValue = "";          
            var a = this;
            return function (event) {
                //alert("ss");
                a.a.et = 3;
                a.a.ep = (new Date).getTime() - a.h.r + "," + ((new Date).getTime() - a.h.g + a.h.s);
                a.SendDataToServer_c();
            }
        },
        //發送數據到服務端
        SendDataToServer_c: function () {
            var a = this;
            a.a.rnd = Math.round(Math.random() * 2147483647);
            a.a.api = a.a.api || a.f ? a.a.api + "_" + a.f : ""; //0_
            var b = HttpProtocol_D + "//hm.baidu.com/hm.gif?" + a.GenerateValueToServer_w();
            //處理當前值,並保存到會話中作為未發送數據。
            a.a.api = 0; a.f = 0;
            //存儲未發送值到sessionstorage中
            a.ProParamUValueAndSave_A(b);
            PostDataToServer_w(b, function (b) { a.RemoveOldValueAndSaveNewValue_l(b) });
        },
        //流量的logo
        LoadLogo_z: function () {
            if (c.icon != "") {
                var a, b = c.icon.split("|"), d = "http://tongji.baidu.com/hm-web/welcome/ico?s=" + c.id;
                a = (D == "http:" ? "http://eiv/" : "https://bs/") + ".baidu.com" + b[0] + "." + b[1];
                switch (b[1]) {
                    case "swf":
                        var e = b[2], b = b[3], d = "s=" + d, f = "HolmesIcon" + C;
                        a = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="' + f + '" width="' + e + '" height="' + b + '"><param name="movie" value="' + a + '" /><param name="flashvars" value="' + d + '" /><param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" name="' +
f + '" width="' + e + '" height="' + b + '" src="' + a + '" flashvars="' + d + '" allowscriptaccess="always" /></object>';
                        break;
                    case "gif": a = '<a href="' + d + '" target="_blank"><img border="0" src="' + a + '" width="' + b[2] + '" height="' + b[3] + '"></a>'; break;
                    default:
                        a = '<a href="' + d + '" target="_blank">' + b[0] + "</a>";
                }
                document.write(a)
            }
        },
        //加載一個js,暫時不考慮,有hash值才會加載
        LoadJS_B: function () {
            var a = window.location.hash.substring(1), b = RegExp(c.id), d = document.referrer.indexOf("baidu.com") > -1 ? true_g : false_i;
            a && b.test(a) && d && (b = document.createElement("script"), b.setAttribute("type", "text/javascript"),
            b.setAttribute("charset", "utf-8"),
            b.setAttribute("src", HttpProtocol_D + "//" + c.js + GetKeyWordFromURL_o(a, "jn") + "." + GetKeyWordFromURL_o(a, "sx") + "?" + this.a.rnd), a = document.getElementsByTagName("script")[0], a.parentNode.insertBefore(b, a))
        },
        //處理對象數組,首先參數是對象數組,然后根據第一個參數決定如何處理參數值
        ProObjectArray_t: function (a) {
            if (function (a) {
                if (Object.prototype.toString.call(a) !== "[object Array]")
                    return false_i;
                //這段代碼無用
                for (var b = a.length - 1; b >= 0; b--) {
                    var d = a[b];
                    if (!("[object Number]" == Object.prototype.toString.call(d) && isFinite(d)) &&
                    "[object String]" != Object.prototype.toString.call(d) && d !== true_g && d !== false_i) return false_i;
                }
                return true_g; //已定義了且不是當前帳號,則不處理,未定義則向下處理對象數組中的東西
            } (a) && !(typeof window._bdhm_account !== "undefined" && window._bdhm_account !== c.id)) {
                //替換參數中的值,分別是符號 ' * !
                var b = function (a) {
                    return a.replace ? a.replace(/'/g, "'0").replace(/\*/g, "'1").replace(/!/g, "'2") : a
                };
                switch (a[0]) {
                    case "_trackPageview":
                        if (a.length > 1 && a[1].charAt && a[1].charAt(0) == "/") {
                            this.a.api |= 4;
                            this.a.et = 0;
                            this.a.ep = "";
                            var b = this.a.u, d = this.a.su;
                            //端口和域名
                            this.a.u = HttpProtocol_D + "//" + window.location.host + a[1];
                            //現域名
                            this.a.su = window.location.href;
                            this.SendDataToServer_c();
                            this.a.u = b;
                            this.a.su = d;
                        }
                        break;
                    //事件跟蹤轉化        
                    case "_trackEvent":
                        if (a.length > 2)
                            this.a.api |= 8, this.a.et = "4", this.a.ep = b(a[1]) + "*" + b(a[2]) + (a[3] ? "*" + b(a[3]) : "") +
                            (a[4] ? "*" + b(a[4]) : ""), this.SendDataToServer_c();
                        break;
                    //變量跟蹤轉化        
                    case "_setCustomVar":
                        if (a.length < 4)
                            break;
                        var d = a[1], e = a[4] || 3;
                        if (d > 0 && d < 6 && e > 0 && e < 4) {
                            this.f++;
                            for (var f = (this.a.cv || "*").split("!"), j = f.length; j < d - 1; j++)
                                f.push("*");
                            f[d - 1] = e + "*" + b(a[2]) + "*" + b(a[3]);
                            this.a.cv = f.join("!");
                            a = this.a.cv.replace(/[^1](\*[^!]*){2}/g, "*").replace(/((^|!)\*)+$/g, "");
                            //不等於空時存起來,否則刪除
                            a !== "" ? this.setData("Hm_cv_" + c.id, encodeURIComponent(a), c.age) : this.RemoveCookieAndLocalValue_H("Hm_cv_" + c.id);
                        }
                } //switch
            } //if結束
        },
        //處理存儲在window._hmt中的值
        Pro_hmtValue_C: function () {
            var a = true_g, b = window._hmt;
            if (b && b.length) {
                for (var d = 0; d < b.length; d++) {
                    var e = b[d];
                    switch (e[0]) {
                        //設置統計帳號        
                        case "_setAccount":
                            if (e.length > 1 && /^[0-9a-z]{32}$/.test(e[1]))
                                this.a.api |= 1, window._bdhm_account = e[1], e[1] !== c.id && (a = i);
                            break;
                        //頁面自動pv統計不使用時        
                        case "_setAutoPageview":
                            if (e.length > 1 && (e = e[1], i === e || g === e))
                                this.a.api |= 2, window._bdhm_autoPageview = e;
                    }
                }
                if (a)
                    for (d = 0; d < b.length; d++)
                        this.ProObjectArray_t(b[d]);
            }
            return a;
        },
        //在指定URL中增加U值,把最新的值插入到Hm_unsent_中存儲值前面並保存
        ProParamUValueAndSave_A: function (a) {
            var b = GetSessionStorage_n("Hm_unsent_" + c.id) || "",
            d = this.a.u ? "" : "&u=" + encodeURIComponent(window.location.href),
            b = encodeURIComponent(a.replace(/^https?:\/\//, "") + d) + (b ? "," + b : "");
            //關閉前可能這些數據發不了,這樣留在用戶下次登陸相關頁面時發送。
            SeessionStorage_m("Hm_unsent_" + c.id, b);
        },
        //處理Hm_unsent_中舊值並存儲新值,第一次進入a=.*
        //在頁面被關閉前會存入url值。然后會發送數據到服務端,成功后會和以前保存的值進行匹配,匹配成功后還有值則存起來,無值時則會清空未發送值。
        //第二次進入該頁面不一定有值,當有值時還是需要傳到服務端的。
        RemoveOldValueAndSaveNewValue_l: function (a) {

            //未發送值
            var b = GetSessionStorage_n("Hm_unsent_" + c.id) || "";
            b &&
            (
                (b = b.replace(
                                RegExp(
                                        encodeURIComponent(
                                                            a.replace(/^https?:\/\//, "") //http議去掉
                                                           ).replace(
                                                                      /([\*\(\)])/g, "http://www.cnblogs.com/dnninchina/admin/file://$1/"  //*()替換為\$1
                                                                    ) + "(%26u%3D[^,]*)?,?", "g"
                                       ), ""  //加上&u=[^,]*   以&u為參數到,結尾,其實就是界限
                               )
                               .replace(/,$/, "")
             )
            ? SeessionStorage_m("Hm_unsent_" + c.id, b)//
            : window.sessionStorage && window.sessionStorage.removeItem("Hm_unsent_" + c.id));
            // alert(b);
        },
        //提交瀏覽器中存儲數據到服務端 a.nv=0時執行,刷新時沒有大於半小時
        PostSessionStorageDataToServer_J: function () {
            var a = this, b = GetSessionStorage_n("Hm_unsent_" + c.id);
            //alert(b);
            if (b)
                for (var b = b.split(","), d = 0, e = b.length; d < e; d++)
                    PostDataToServer_w(HttpProtocol_D + "//" + decodeURIComponent(b[d]).replace(/^https?:\/\//, ""), function (b) {
                        a.RemoveOldValueAndSaveNewValue_l(b);
                    });
        }
    };
    //為指定頁面對象增加事件
    F.prototype.AddEventForDocumentObject_n = function () {
        EventAdd_x(document, "click", EventCallBack_H(this));
        for (var a = c.etrk.length, b = 0; b < a; b++) {
            var d = c.etrk[b], e = document.getElementById(d.id);
            e && EventAdd_x(e, d.eventType, AddAttributeForEventObjectAndSendData_I(this))
        }
    };

    //為事件對象增加座標屬性且給參數賦值,然后把數據發到服務端,轉化項目使用
    function AddAttributeForEventObjectAndSendData_I(a) {
        return function (b) {
            (b.target || b.srcElement).setAttribute("HM_fix", b.clientX + ":" + b.clientY);
            a.a.et = 1;
            a.a.ep = "{id:" + this.id + ",eventType:" + b.type + "}";
            a.SendDataToServer_c();
        }
    }
    //事件委托,事件對象是指定特定事件對象時,則發送數據到服務端
    function EventCallBack_H(a) {
        return function (b) {
            var d = b.target || b.srcElement, e = d.getAttribute("HM_fix"), f = b.clientX + ":" + b.clientY;
            if (e && e == f)
                d.removeAttribute("HM_fix");
            else
                if (e = c.etrk.length, e > 0) {
                    //逐級收集父對象id
                    for (f = {}; d && d != document.body; )
                        d.id && (f[d.id] = ""), d = d.parentNode;
                    //定義事件的處理,{id:}
                    for (d = 0; d < e; d++) {
                        var j = c.etrk[d];
                        if (f.hasOwnProperty(j.id))
                            a.a.et = 1, a.a.ep = "{id:" + j.id + ",eventType:" + b.type + "}", a.SendDataToServer_c();
                    }
                }
        }
    }
    //為文檔對象增加mouseup和beforeunload事件
    F.prototype.AddMouseupAndBeforeUnloadEventForDocument_m = function () {
        var a = this;
        c.ctrk && (EventAdd_x(document, "mouseup", DocumentMouseupEventCallback_J(this)),
        EventAdd_x(window, "beforeunload", function () { ProParamBAndSendDataToServer_K(a) }),
         setInterval(function () { ProParamBAndSendDataToServer_K(a) }, 6E5))//600000,10分鍾
    };
    //需要跟蹤轉化時,處理F對象中的b值,該值存儲的是事件發生的座標及發生的鏈接地址。如果大於10個元素或者長度大於1024,則發送數據到服務端
    function DocumentMouseupEventCallback_J(a) {
        return function (b) {
            var d, e;
            //是IE需要加上滾動高度
            q ? (e = Math.max(document.documentElement.scrollTop, document.body.scrollTop),
            d = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
            d = b.clientX + d, e = b.clientY + e) : (d = b.pageX, e = b.pageY);
            var f = window.innerWidth || document.documentElement.clientWidth || document.body.offsetWidth;
            //對齊方式不同
            switch (c.align) {
                case 1:
                    d -= f / 2;
                    break;
                case 2:
                    d -= f;
            }
            d = "{x:" + d + ",y:" + e + ",";
            b = b.target || b.srcElement;
            //不是a標簽觸發的事件,向上找到a為止。
            if (b.tagName.toLowerCase() != "a")
a:
            {
                for (e = "A"; (b = b.parentNode) && b.nodeType == 1; )
                    if (b.tagName == e)
                        break a;
                //一直沒有找到a標簽,置空
                b = null_h;
            }
            d += b ? "t:a,u:" + encodeURIComponent(b.href) + "}" : "t:b}";
            b = d;
            //b永遠是有值的
            if ("" != b)
            //處理ep值。
                d = (HttpProtocol_D + "//hm.baidu.com/hm.gif?" + a.GenerateValueToServer_w().replace(/ep=[^&]*/, "ep=" + encodeURIComponent("[" + b + "]"))).length,
            //長度大於1024時直接推送b值,然后如果發現大於10個元素,推送到服務端。如果不大於1024,那么如果b中的值處理完后大於1024,則會發到服務端。
                d + 10 > 1024 || (d + encodeURIComponent(a.b.join(",") + (a.b.length ? "," : "")).length + 10 > 1024 && ProParamBAndSendDataToServer_K(a), a.b.push(b),
                (a.b.length >= 10 || /t:a/.test(b)) && ProParamBAndSendDataToServer_K(a))
        }
    }
    //處理參數中B值,並把數據發到服務端,然后清空b值。
    function ProParamBAndSendDataToServer_K(a) {
        if (a.b.length != 0)
            a.a.et = 2, a.a.ep = "[" + a.b.join(",") + "]", a.SendDataToServer_c(), a.b = [];
    }
    //為window對象增加焦點事件和失去焦點事件,作用就是可以觸發切換時間再計算,可以記錄用戶回來幾次和累計的時間
    function AddFoucsAndBlureEventForWindow_G() {
        this.g = this.r = (new Date).getTime();
        this.s = 0;
        typeof document.M == "object" ? (EventAdd_x(document, "focusin", L(this)), EventAdd_x(document, "focusout", CaculateOnlineTimeAndRefreshStartTime_L(this))) : (EventAdd_x(window, "focus", CaculateOnlineTimeAndRefreshStartTime_L(this)), EventAdd_x(window, "blur", CaculateOnlineTimeAndRefreshStartTime_L(this)))
    }
    //用戶重新進入時刷新開始時間並累積用戶在線時間
    function CaculateOnlineTimeAndRefreshStartTime_L(a) {
        return function (b) {
            if (!(b.target && b.target != window)) {
                if (b.type == "blur" || b.type == "focusout")
                    a.s += (new Date).getTime() - a.g;
                a.g = (new Date).getTime();
            }
        }
    }
    new F;
})();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM