最近准备实现一个流量分析的系统的,所以就研究了国外和国内的网流流量分析系统。数据分析首先是收集用户数据,就把百度和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;
})();