谷歌 analytics.js 简要分析
下面是部分翻译过的JS,看起来好看些。
(function () { function setHref(a, b) { return a.href = b; } function setName(a, b) { return a.name = b; } //使用情况的埋点 var allusage = new function () { var array = []; this.set = function (b) { array[b]= true; }; this.usageFlag = function () { for(var b = [], c = 0; c < array.length; c++) { array[c]&& (b[Math.floor(c / 6)] = b[Math.floor(c / 6)] ^ 1 << c % 6); } for (c = 0; c < b.length; c++) { b[c]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".charAt(b[c]|| 0); } return b.join("") + "~"; }; }; //设置信息标志 function setMsgCode(a) { allusage.set(a); }; function isFunction(a) { return "function" == typeof a; } function isArray(a) { return "[object Array]" == Object.prototype.toString.call(Object(a)); } function isString(a) { return void 0 != a && - 1 < (a.constructor + "").indexOf("String"); } function inString(a, b) { return 0 == a.indexOf(b); } //去除空格 function removeBlank(a) { return a ? a.replace(/^[\s\xa0]+|[\s\xa0]+$/g, ""): ""; } function Td() { return [roundCode() ^ Mc() & 0x7FFFFFFF, Math.round((new Date).getTime() / 1E3)].join("."); } function createImg(a) { var b = document.createElement("img"); b.width = 1; b.height = 1; b.src = a; return b; } function emptyFunction() { } function encodeUri(a) { if(encodeURIComponent instanceof Function) return encodeURIComponent(a); setMsgCode(28); return a; } //对括号进行编码 function encodeBracket(a) { return encodeUri(a).replace(/\(/g, "%28").replace(/\)/g, "%29"); } var addEvent = function (a, b, c, d) { try { a.addEventListener ? a.addEventListener(b, c, !!d): a.attachEvent && a.attachEvent("on" +b, c); } catch (e) { setMsgCode(27); } }; var removeEvent = function (a, b, c) { a.removeEventListener ? a.removeEventListener(b, c, false): a.detachEvent && a.detachEvent("on" +b, c); }; function createScript(a, b) { if(a) { var c = document.createElement("script"); c.type = "text/javascript"; c.async = true; c.src = a; c.id = b; var d = document.getElementsByTagName("script")[0]; d.parentNode.insertBefore(c, d); } } function getProtocol() { return Ba || "https:" == document.location.protocol ? "https:" : "http:"; } function getHostname() { var a = "" + document.location.hostname; return 0 == a.indexOf("www.") ? a.substring(4): a; } function getReferrer(a) { var b = document.referrer; if (/^https?:\/\//i.test(b)) { if (a) return b; a = "//" + document.location.hostname; var c = b.indexOf(a); if (5 == c || 6 == c) if (a = b.charAt(c +a.length), "/" == a || "?" == a || "" == a || ":" == a) return; return b; } } function preParameters(a, b) { if(1 == b.length && null != b[0] && "object" === typeof b[0]) return b[0]; for (var c = { }, d = Math.min(a.length +1, b.length), e = 0; e < d; e++) if ("object" === typeof b[e]) { for (var g in b[e]) b[e].hasOwnProperty(g) &&(c[g] = b[e][g]); break; } else e < a.length && (c[a[e]]= b[e]); return c; }; //用于存在储键值对应的容器 var kVContainer = function () { this.keys =[]; this.w = { }; this.m = { }; }; kVContainer.prototype.set = function (a, b, c) { this.keys.push(a); c ? this.m[":" +a] = b: this.w[":" +a] = b; }; kVContainer.prototype.get = function (a) { return this.m.hasOwnProperty(":" +a) ? this.m[":" +a] : this.w[":" +a]; }; kVContainer.prototype.map = function (a) { for(var b = 0; b < this.keys.length; b++) { var c = this.keys[b]; var d = this.get(c); d && a(c, d); } }; //是否禁用了跟踪,参见帮助文档 var isDisabledTrack = function (a) { return false; }; var fb = function (a) { setTimeout(a, 100); }; var getCookieValue = function (a) { var b = [], c = document.cookie.split(";"); a = new RegExp("^\\s*" +a + "=\\s*(.*?)\\s*$"); for (var d = 0; d < c.length; d++) { var e = c[d].match(a); e && b.push(e[1]); } return b; }; var getsetCookie = function (a, b, c, d, e, g) { //如果被禁用或自身几个网站,不进行跟踪,返回False e = isDisabledTrack(e) ? false : regDoubleclick.test(document.location.hostname) || "/" == c && regGoogleSite.test(d) ? false : true; if (!e) return false; b && 1200 < b.length && (b = b.substring(0, 1200), setMsgCode(24)); c = a + "=" + b + "; path=" +c + "; "; g && (c += "expires=" +(new Date((new Date).getTime() +g)).toGMTString() + "; "); d && "none" != d && (c += "domain=" +d + ";"); d = document.cookie; document.cookie = c; if (!(d = d != document.cookie)) t: { a = getCookieValue(a); for (d = 0; d < a.length; d++) if (b == a[d]) { d = true; break t; } d = false; } return d; }; var regGoogleSite = new RegExp(/^(www\.)?google(\.com?)?(\.[a-z]{2})?$/); var regDoubleclick = new RegExp(/(^|\.)doubleclick\.net$/i); var Mc = function () { //debugger; for(var a = window.navigator.userAgent + (document.cookie ? document.cookie: "") + (document.referrer ? document.referrer: ""), b = a.length, c = window.history.length; 0 < c;) { a += c-- ^ b++; } return La(a); }; var oc = function () { return getProtocol() + "//localhost:25388"; //return getProtocol() + "//www.google-analytics.com"; }; var lenException = function (a) { setName(this, "len"); this.message = a + "-8192"; }; //firefox error var ff2postException = function (a) { setName(this, "ff2post"); this.message = a + "-2036"; }; //如果支持sendBeacon 就使用它, var sendRequest = function (targetUrl, datas, callback, sendBeaconCallback) { callback = callback || emptyFunction; //优先使用sendBeaconCallback sendBeaconCallback && (sendBeaconCallback = callback, window.navigator.sendBeacon ? window.navigator.sendBeacon(targetUrl, datas) ? (sendBeaconCallback(), sendBeaconCallback = true) : sendBeaconCallback = false : sendBeaconCallback = false); if (!sendBeaconCallback) { if (2036 >= datas.length) { imageRequest(targetUrl, datas, callback); } else if (8192 >= datas.length) { if (0 <= window.navigator.userAgent.indexOf("Firefox") && ![].reduce) { throw new ff2postException(datas.length); } XMLHttpRequest(targetUrl, datas, callback) || XDomainRequest(targetUrl, datas, callback) || IframeRequest(datas, callback) || callback(); } else { throw new lenException(datas.length); } } }; //图片的请求方式 var imageRequest = function (a, b, c) { var d = createImg(a + "?" + b); d.onload = d.onerror = function () { d.onload = null; d.onerror = null; c(); }; }; //XDomainRequest var XDomainRequest = function (a, b, c) { var d; d = window.XDomainRequest; if (!d) return false; d = new d; d.open("POST", a); d.onerror = function () { c(); }; d.onload = c; d.send(b); return true; }; var XMLHttpRequest = function (a, b, c) { var d = window.XMLHttpRequest; if (!d) return false; var e = new d; if (!("withCredentials" in e)) return false; e.open("POST", a, true); e.withCredentials = true; e.setRequestHeader("Content-Type", "text/plain"); e.onreadystatechange = function () { 4 == e.readyState && (c(), e = null); }; e.send(b); return true; }; var IframeRequest = function (a, b) { if(!document.body) return fb(function () { IframeRequest(a, b); }), true; a = encodeURIComponent(a); try { var c = document.createElement(‘<iframe name="‘ +a + ‘"></iframe>‘); } catch (d) { c = document.createElement("iframe"), setName(c, a); } c.height = "0"; c.width = "0"; c.style.display = "none"; c.style.visibility = "hidden"; var e = document.location, e = oc() + "/analytics_iframe.html#" + encodeURIComponent(e.protocol + "//" + e.host + "/favicon.ico"), g = function () { c.src = ""; c.parentNode && c.parentNode.removeChild(c); }; addEvent(window, "beforeunload", g); var ca = false, l = 0, k = function () { if(!ca) { try { if (9 < l || c.contentWindow.location.host == document.location.host) { ca = true; g(); removeEvent(window, "beforeunload", g); b(); return; } } catch (a) { } l++; setTimeout(k, 200); } }; addEvent(c, "load", k); document.body.appendChild(c); c.src = e; return true; }; var Ha = function () { this.t =[]; }; Ha.prototype.add = function (a) { this.t.push(a); }; Ha.prototype.D = function (a) { try { for (var b = 0; b < this.t.length; b++) { var c = a.get(this.t[b]); c && isFunction(c) && c.call(window, a); } } catch (d) { } b = a.get(hitCallback); b != emptyFunction && isFunction(b) &&(a.set(hitCallback, emptyFunction, true), setTimeout(b, 10)); }; function checksampler(a) { if(100 != a.get(sampleRate) && La(getStrConfig(a, clientId)) % 1E4 >= 100 * getIntConfig(a, sampleRate)) throw "abort"; } function checkisDisabledTrack(a) { if(isDisabledTrack(getStrConfig(a, trackingId))) throw "abort"; } function checkProtocol() { var a = document.location.protocol; if ("http:" != a && "https:" != a) throw "abort"; } function buildHitTasks(a) { try { window.XMLHttpRequest && "withCredentials" in new window.XMLHttpRequest ? setMsgCode(40): window.XDomainRequest && setMsgCode(41), window.navigator.sendBeacon && setMsgCode(42); } catch (b) { } a.set(stepInPage, getIntConfig(a, stepInPage) +1); var c = []; Qa.map(function(b, d) { if(d.p) { var e = a.get(b); void 0 != e && e != d.defaultValue && ("boolean" == typeof e && (e *= 1), c.push(d.p + "=" + encodeUri("" +e))); } }); if (Ed(new Od(1E4))) { var d = []; d.push(round1()); d.push.apply(d, Td().split(".")); d.push(round2()); var e; e = window.crypto ? true : false; d.push(e ? "c": "b"); c.push("z=" +d.join(".")); } else c.push("z=" +round2()); a.set(hitPayload, c.join("&"), true); } function sendHitTasks(a) { var b = getStrConfig(a, transportUrl) || oc() + "/collect"; sendRequest(b, getStrConfig(a, hitPayload), a.get(hitCallback), a.get(useBeacon)); a.set(hitCallback, emptyFunction, true); } function Hc(a) { var b = window.gaData; b && (b.expId && a.set(Nc, b.expId), b.expVar && a.set(Oc, b.expVar)); } function checkpreviewTask() { if(window.navigator && "preview" == window.navigator.loadPurpose) throw "abort"; } function checkTrackidexist(a) { if(!a.get(trackingId)) throw "abort"; }; var round1 = function () { return Math.round(0x7FFFFFFF * Math.random()); }; var round2 = function () { try { var a = new Uint32Array(1); window.crypto.getRandomValues(a); return a[0]& 0x7FFFFFFF; } catch (b) { return round1(); } }; var roundCode = round1; function Ta(a) { var b = getIntConfig(a, Ua); 500 <= b && setMsgCode(15); var c = getStrConfig(a, hitType); if ("transaction" != c && "item" != c) { var c = getIntConfig(a, Wa), d = (new Date).getTime(), e = getIntConfig(a, Xa); 0 == e && a.set(Xa, d); e = Math.round(2 * (d - e) / 1E3); 0 < e && (c = Math.min(c +e, 20), a.set(Xa, d)); if (0 >= c) throw "abort"; a.set(Wa, --c); } a.set(Ua, ++b); }; var settings = function () { this.data = new kVContainer; }; var Qa = new kVContainer; var Za = []; settings.prototype.get = function (a) { var b = $a(a); var c = this.data.get(a); b && void 0 == c && (c = isFunction(b.defaultValue) ? b.defaultValue(): b.defaultValue); return b && b.n ? b.n(this, a, c): c; }; settings.prototype.set = function (a, b, c) { if(a) if ("object" == typeof a) { for (var d in a) { a.hasOwnProperty(d) && ab(this, d, a[d], c); } } else { ab(this, a, b, c); } }; var getStrConfig = function (a, b) { var c = a.get(b); return void 0 == c ? "" : "" + c; }; var getIntConfig = function (a, b) { var c = a.get(b); return void 0 == c || "" === c ? 0 : 1 * c; }; var ab = function (a, b, c, d) { if(void 0 != c) switch (b) { case trackingId: wb.test(c); } var e = $a(b); e && e.o ? e.o(a, b, c, d): a.data.set(b, c, d); }; var bb = function (aName, bshortName, cdefaultValue, d, e) { setName(this, aName); this.p = bshortName; this.n = d; this.o = e; this.defaultValue = cdefaultValue; }; var $a = function (a) { var b = Qa.get(a); if (!b) for (var c = 0; c < Za.length; c++) { var d = Za[c], e = d[0].exec(a); if (e) { b = d[1](e); Qa.set(b.name, b); break; } } return b; }; var yc = function (a) { var b; Qa.map(function(c, d) { d.p == a && (b = d); }); return b && b.name; }; var S = function (aName, bshortName, cdefaultValue, d, e) { aName = new bb(aName, bshortName, cdefaultValue, d, e); Qa.set(aName.name, aName); return aName.name; }; var cb = function (a, b) { Za.push([new RegExp("^" +a + "$"), b]); }; var T = function (aName, bshortName, cdefaultValue) { return S(aName, bshortName, cdefaultValue, void 0, db); }; var db = function () { }; var WXAnalyticsObjectName = isString(window.WXAnalyticsObject) && removeBlank(window.WXAnalyticsObject) || "wa"; var Ba = false; var apiVersion = T("apiVersion", "v"); var clientVersion = T("clientVersion", "_v"); S("anonymizeIp", "aip"); var hitType = S("hitType", "t"); var hitCallback = S("hitCallback"); var hitPayload = S("hitPayload"); S("nonInteraction", "ni"); S("currencyCode", "cu"); var useBeacon = S("useBeacon", void 0, false); S("dataSource", "ds"); S("sessionControl", "sc", ""); S("sessionGroup", "sg"); S("queueTime", "qt"); var stepInPage = S("_s", "_s"); S("screenName", "cd"); var kb = S("location", "dl", ""); var lb = S("referrer", "dr"); var mb = S("page", "dp", ""); S("hostname", "dh"); var nb = S("language", "ul"); var ob = S("encoding", "de"); S("title", "dt", function () { return document.title || void 0; }); cb("contentGroup([0-9]+)", function (a) { return new bb(a[0], "cg" +a[1]); }); var pb = S("screenColors", "sd"); var qb = S("screenResolution", "sr"); var rb = S("viewportSize", "vp"); var sb = S("javaEnabled", "je"); var tb = S("flashVersion", "fl"); S("campaignId", "ci"); S("campaignName", "cn"); S("campaignSource", "cs"); S("campaignMedium", "cm"); S("campaignKeyword", "ck"); S("campaignContent", "cc"); var ub = S("eventCategory", "ec"); var xb = S("eventAction", "ea"); var yb = S("eventLabel", "el"); var zb = S("eventValue", "ev"); var Bb = S("socialNetwork", "sn"); var Cb = S("socialAction", "sa"); var Db = S("socialTarget", "st"); var Eb = S("l1", "plt"); var Fb = S("l2", "pdt"); var Gb = S("l3", "dns"); var Hb = S("l4", "rrt"); var Ib = S("l5", "srt"); var Jb = S("l6", "tcp"); var Kb = S("l7", "dit"); var Lb = S("l8", "clt"); var Mb = S("timingCategory", "utc"); var Nb = S("timingVar", "utv"); var Ob = S("timingLabel", "utl"); var Pb = S("timingValue", "utt"); S("appName", "an"); S("appVersion", "av", ""); S("appId", "aid", ""); S("appInstallerId", "aiid", ""); S("exDescription", "exd"); S("exFatal", "exf"); var Nc = S("expId", "xid"); var Oc = S("expVar", "xvar"); var Ua = S("_hc", void 0, 0); var Xa = S("_ti", void 0, 0); var Wa = S("_to", void 0, 20); cb("dimension([0-9]+)", function (a) { return new bb(a[0], "cd" +a[1]); }); cb("metric([0-9]+)", function (a) { return new bb(a[0], "cm" +a[1]); }); S("linkerParam", void 0, void 0, Bc, db); var ld = S("usage", "_u", void 0, function () { return allusage.usageFlag(); }, db); S("forceSSL", void 0, void 0, function () { return Ba; }, function (a, b, c) { setMsgCode(34); Ba = !!c; }); //var ed = S("_j1", "jid"); //var Hd = S("_j2", "gjid"); cb("\\&(.*)", function (a) { var b = new bb(a[0], a[1]), c = yc(a[0].substring(1)); c && (b.n = function (a) { return a.get(c); }, b.o = function (a, b, g, ca) { a.set(c, g, ca); }, b.p = void 0); return b; }); var _oot = T("_oot"); var previewTask = S("previewTask"); var checkProtocolTask = S("checkProtocolTask"); var validationTask = S("validationTask"); var checkStorageTask = S("checkStorageTask"); //var historyImportTask = S("historyImportTask"); var samplerTask = S("samplerTask"); var _rlt = T("_rlt"); var buildHitTask = S("buildHitTask"); var sendHitTask = S("sendHitTask"); var ceTask = S("ceTask"); //var devIdTask = S("devIdTask"); var timingTask = S("timingTask"); //var displayFeaturesTask = S("displayFeaturesTask"); var V = T("name"); var clientId = T("clientId", "cid"); var userId = S("userId", "uid"); var trackingId = T("trackingId", "tid"); var cookieName = T("cookieName", void 0, "_wa"); var cookieDomain = T("cookieDomain"); var cookiePath = T("cookiePath", void 0, "/"); var cookieExpires = T("cookieExpires", void 0, 63072E3); var legacyCookieDomain = T("legacyCookieDomain"); //var legacyHistoryImport = T("legacyHistoryImport", void 0, true); var storage = T("storage", void 0, "cookie"); //var allowLinker = T("allowLinker", void 0, false); //var allowAnchor = T("allowAnchor", void 0, true); var sampleRate = T("sampleRate", "sf", 100); var siteSpeedSampleRate = T("siteSpeedSampleRate", void 0, 1); var alwaysSendReferrer = T("alwaysSendReferrer", void 0, false); var transportUrl = S("transportUrl"); //var _r = S("_r", "_r"); //var _dfr = S("_dfr", void 0, 1); function createCommands(commandName, b, c, d) { b[commandName]= function () { try { return d && setMsgCode(d), c.apply(this, arguments); } catch (b) { var g = b && b.name; if (!(1 <= 100 * Math.random() || isDisabledTrack("?"))) { var ca = ["t=error", "_e=exc", "_v=j30", "sr=1"]; commandName && ca.push("_f=" + commandName); g && ca.push("_m=" + encodeUri(g.substring(0, 100))); ca.push("aip=1"); ca.push("z=" +roundCode()); sendRequest(oc() + "/collect", ca.join("&")); } throw b; } }; }; var Od = function (a) { this.V = a; this.fa = void 0; this.$ = false; this.ha = void 0; this.ea = 1; }; var Ed = function (a, b, c) { if(a.fa && a.$) return 0; a.$ = true; if (b) { if (a.ha && getIntConfig(b, a.ha)) return getIntConfig(b, a.ha); if (0 == b.get(siteSpeedSampleRate)) return 0; } if (0 == a.V) return 0; void 0 === c && (c = round2()); return 0 == c % a.V ? Math.floor(c / a.V) % a.ea + 1: 0; }; function flashVersion() { var a, b, c; if ((c = (c = window.navigator) ? c.plugins : null) && c.length) for (var d = 0; d < c.length && !b; d++) { var e = c[d]; -1 < e.name.indexOf("Shockwave Flash") && (b = e.description); } if (!b) try { a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"), b = a.GetVariable("$version"); } catch (g) { } if (!b) try { a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"), b = "WIN 6,0,21,0", a.AllowScriptAccess = "always", b = a.GetVariable("$version"); } catch (ca) { } if (!b) try { a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), b = a.GetVariable("$version"); } catch (l) { } b && (a = b.match(/[\d]+/g)) && 3 <= a.length && (b = a[0] + "." + a[1] + " r" + a[2]); return b || void 0; }; var collectPerformance = function (a, b) { var c = Math.min(getIntConfig(a, siteSpeedSampleRate), 100); if (!(La(getStrConfig(a, clientId)) % 100 >= c) && (c = { }, getperformance(c) || getperformance2(c))) { var d = c[Eb]; void 0 == d || Infinity == d || isNaN(d) || (0 < d ? (Y(c, Gb), Y(c, Jb), Y(c, Ib), Y(c, Fb), Y(c, Hb), Y(c, Kb), Y(c, Lb), b(c)): addEvent(window, "load", function () { collectPerformance(a, b); }, false)); } }; var getperformance = function (a) { var b = window.performance || window.webkitPerformance, b = b && b.timing; if (!b) return false; var c = b.navigationStart; if (0 == c) return false; a[Eb]= b.loadEventStart -c; a[Gb]= b.domainLookupEnd -b.domainLookupStart; a[Jb]= b.connectEnd -b.connectStart; a[Ib]= b.responseStart -b.requestStart; a[Fb]= b.responseEnd -b.responseStart; a[Hb]= b.fetchStart -c; a[Kb]= b.domInteractive -c; a[Lb]= b.domContentLoadedEventStart -c; return true; }; var getperformance2 = function (a) { if(window.top != window) return false; var b = window.external, c = b && b.onloadT; b && !b.isValidLoadTime && (c = void 0); 2147483648 < c && (c = void 0); 0 < c && b.setPageReadyTime(); if (void 0 == c) return false; a[Eb]= c; return true; }; var Y = function (a, b) { var c = a[b]; if (isNaN(c) || Infinity == c || 0 > c) a[b]= void 0; }; var sendTiming = function (a) { return function (b) { "pageview" != b.get(hitType) || a.I || (a.I = true, collectPerformance(b, function (b) { a.send("timing", b); })); }; }; var hc = false; var mc = function (a) { if("cookie" == getStrConfig(a, storage)) { var b = getStrConfig(a, cookieName), c = nd(a), d = kc(getStrConfig(a, cookiePath)), e = lc(getStrConfig(a, cookieDomain)), g = 1E3 * getIntConfig(a, cookieExpires), ca = getStrConfig(a, trackingId); if ("auto" != e) getsetCookie(b, c, d, e, ca, g) && (hc = true); else { setMsgCode(32); var l; t: { c =[]; e = getHostname().split("."); if (4 == e.length && (l = e[e.length -1], parseInt(l, 10) == l)) { l =["none"]; break t; } for (l = e.length -2; 0 <= l; l--) c.push(e.slice(l).join(".")); c.push("none"); l = c; } for (var k = 0; k < l.length; k++) if (e = l[k], a.data.set(cookieDomain, e), c = nd(a), getsetCookie(b, c, d, e, ca, g)) { hc = true; return; } a.data.set(cookieDomain, "auto"); } } }; var checkStorage = function (a) { if("cookie" == getStrConfig(a, storage) && !hc && (mc(a), !hc)) throw "abort"; }; var nd = function (a) { var b = encodeBracket(getStrConfig(a, clientId)); var c = ic(getStrConfig(a, cookieDomain)); a = jc(getStrConfig(a, cookiePath)); 1 < a && (c += "-" + a); return ["MY_A1", c, b].join("."); }; var Gc = function (a, b, c) { for(var d = [], e =[], g, ca = 0; ca < a.length; ca++) { var l = a[ca]; if (l.r[c]== b) d.push(l); else void 0 == g || l.r[c] < g ? (e = [l], g = l.r[c]): l.r[c] == g && e.push(l); } return 0 < d.length ? d: e; }; var lc = function (a) { return 0 == a.indexOf(".") ? a.substr(1): a; }; var ic = function (a) { return lc(a).split(".").length; }; var kc = function (a) { if(!a) return "/"; 1 < a.length && a.lastIndexOf("/") == a.length -1 && (a = a.substr(0, a.length -1)); 0 != a.indexOf("/") &&(a = "/" + a); return a; }; var jc = function (a) { a = kc(a); return "/" == a ? 1 : a.split("/").length; }; function Xc(a, b, c) { "none" == b && (b = ""); var d = [], e = getCookieValue(a); a = "__utma" == a ? 6 : 2; for (var g = 0; g < e.length; g++) { var ca = ("" + e[g]).split("."); ca.length >= a && d.push({ hash: ca[0], R: e[g], O: ca }); } return 0 == d.length ? void 0 : 1 == d.length ? d[0] : Zc(b, d) || Zc(c, d) || Zc(null, d) || d[0]; } function Zc(a, b) { var c, d; null == a ? c = d = 1 : (c = La(a), d = La(inString(a, ".") ? a.substring(1): "." + a)); for (var e = 0; e < b.length; e++) if (b[e].hash == c || b[e].hash == d) return b[e]; }; var od = new RegExp(/^https?:\/\/([^\/:]+)/); var pd = /(.*)([?&#])(?:_wa=[^&#]*)(?:&?)(.*)/; function Bc(a) { a = a.get(clientId); var b = Ic(a, 0); return "_wa=1." + encodeUri(b + "." + a); } function Ic(a, b) { for(var c = new Date, d = window.navigator, e = d.plugins ||[], c =[a, d.userAgent, c.getTimezoneOffset(), c.getYear(), c.getDate(), c.getHours(), c.getMinutes() +b], d = 0; d < e.length; ++d) c.push(e[d].description); return La(c.join(".")); } var Dc = function (a) { setMsgCode(48); this.target = a; this.T = false; }; Dc.prototype.Q = function (a, b) { if(a.tagName) { if ("a" == a.tagName.toLowerCase()) { a.href && setHref(a, qd(this, a.href, b)); return; } if ("form" == a.tagName.toLowerCase()) return rd(this, a); } if ("string" == typeof a) return qd(this, a, b); }; var qd = function (a, b, c) { var d = pd.exec(b); d && 3 <= d.length && (b = d[1] + (d[3] ? d[2] + d[3] : "")); a = a.target.get("linkerParam"); var e = b.indexOf("?"), d = b.indexOf("#"); c ? b += (- 1 == d ? "#" : "&") + a : (c = - 1 == e ? "?" : "&", b = -1 == d ? b + (c + a) : b.substring(0, d) +c + a + b.substring(d)); return b; }; var rd = function (a, b) { if(b && b.action) { var c = a.target.get("linkerParam").split("=")[1]; if ("get" == b.method.toLowerCase()) { for (var d = b.childNodes ||[], e = 0; e < d.length; e++) if ("_wa" == d[e].name) { d[e].setAttribute("value", c); return; } d = document.createElement("input"); d.setAttribute("type", "hidden"); d.setAttribute("name", "_wa"); d.setAttribute("value", c); b.appendChild(d); } else "post" == b.method.toLowerCase() &&(b.action = qd(a, b.action)); } }; Dc.prototype.S = function (a, b, c) { function d(c) { try { c = c || window.event; var d; t: { var g = c.target || c.srcElement; for (c = 100; g && 0 < c;) { if (g.href && g.nodeName.match(/^a(?:rea)?$/i)) { d = g; break t; } g = g.parentNode; c--; } d = { }; } ("http:" == d.protocol || "https:" == d.protocol) && sd(a, d.hostname || "") && d.href && setHref(d, qd(e, d.href, b)); } catch (w) { setMsgCode(26); } } var e = this; this.T || (this.T = true, addEvent(document, "mousedown", d, false), addEvent(document, "touchstart", d, false), addEvent(document, "keyup", d, false)); if (c) { c = function (b) { b = b || window.event; if ((b = b.target || b.srcElement) && b.action) { var c = b.action.match(od); c && sd(a, c[1]) && rd(e, b); } }; for (var g = 0; g < document.forms.length; g++) addEvent(document.forms[g], "submit", c); } }; function sd(a, b) { if(b == document.location.hostname) return false; for (var c = 0; c < a.length; c++) if (a[c]instanceof RegExp) { if (a[c].test(b)) return true; } else if (0 <= b.indexOf(a[c])) return true; return false; }; var wb = /^(UA|YT|MO|GP)-(\d+)-(\d+)$/; var pc = function (a) { function bind(a, b) { d.b.data.set(a, b); } function bindfilters(a, c) { bind(a, c); d.filters.add(a); } var d = this; this.b = new settings; this.filters = new Ha; bind(V, a[V]); bind(trackingId, removeBlank(a[trackingId])); bind(cookieName, a[cookieName]); bind(cookieDomain, a[cookieDomain]|| getHostname()); bind(cookiePath, a[cookiePath]); bind(cookieExpires, a[cookieExpires]); bind(sampleRate, a[sampleRate]); bind(siteSpeedSampleRate, a[siteSpeedSampleRate]); bind(alwaysSendReferrer, a[alwaysSendReferrer]); bind(storage, a[storage]); bind(userId, a[userId]); bind(apiVersion, 1); bind(clientVersion, "j30"); bindfilters(_oot, checkisDisabledTrack); bindfilters(previewTask, checkpreviewTask); bindfilters(checkProtocolTask, checkProtocol); bindfilters(validationTask, checkTrackidexist); bindfilters(checkStorageTask, checkStorage); bindfilters(samplerTask, checksampler); bindfilters(_rlt, Ta); bindfilters(ceTask, Hc); bindfilters(buildHitTask, buildHitTasks); bindfilters(sendHitTask, sendHitTasks); bindfilters(timingTask, sendTiming(this)); Jc(this.b, a[clientId]); preCommRequestArgs(this.b); }; var Jc = function (a, b) { if("cookie" == getStrConfig(a, storage)) { hc = false; var c; i: { var d = getCookieValue(getStrConfig(a, cookieName)); if (d && !(1 > d.length)) { c =[]; for (var e = 0; e < d.length; e++) { var g; g = d[e].split("."); var ca = g.shift(); ("GA1" == ca || "1" == ca) && 1 < g.length ? (ca = g.shift().split("-"), 1 == ca.length && (ca[1] = "1"), ca[0]*= 1, ca[1]*= 1, g = { r: ca, s: g.join(".") }): g = void 0; g && c.push(g); } if (1 == c.length) { setMsgCode(13); c = c[0].s; break i; } if (0 == c.length) setMsgCode(12); else { setMsgCode(14); d = ic(getStrConfig(a, cookieDomain)); c = Gc(c, d, 0); if (1 == c.length) { c = c[0].s; break i; } d = jc(getStrConfig(a, cookiePath)); c = Gc(c, d, 1); c = c[0] && c[0].s; break i; } } c = void 0; } c || (c = getStrConfig(a, cookieDomain), d = getStrConfig(a, legacyCookieDomain) || getHostname(), c = Xc("__utma", d, c), (c = void 0 == c ? void 0 : c.O[1] + "." + c.O[2]) && setMsgCode(10)); c && (a.data.set(clientId, c), hc = true); } b && (setMsgCode(9), a.data.set(clientId, encodeUri(b))); a.get(clientId) || ((c = (c = window.gaGlobal && window.gaGlobal.vid) && - 1 != c.search(/^(?:utma\.)?\d+\.\d+$/) ? c : void 0) ? (setMsgCode(17), a.data.set(clientId, c)): (setMsgCode(8), a.data.set(clientId, Td()))); mc(a); }; //准备通用的请请求参数 var preCommRequestArgs = function (a) { var b = window.navigator, c = window.screen, d = document.location; a.set(lb, getReferrer(a.get(alwaysSendReferrer))); if (d) { var e = d.pathname || ""; "/" != e.charAt(0) &&(setMsgCode(31), e = "/" + e); a.set(kb, d.protocol + "//" + d.hostname +e + d.search); } c && a.set(qb, c.width + "x" + c.height); c && a.set(pb, c.colorDepth + "-bit"); var c = document.documentElement, g = (e = document.body) && e.clientWidth && e.clientHeight, ca =[]; c && c.clientWidth && c.clientHeight && ("CSS1Compat" === document.compatMode || !g) ? ca = [c.clientWidth, c.clientHeight]: g && (ca = [e.clientWidth, e.clientHeight]); c = 0 >= ca[0] || 0 >= ca[1] ? "" : ca.join("x"); a.set(rb, c); a.set(tb, flashVersion()); a.set(ob, document.characterSet || document.charset); a.set(sb, b && "function" === typeof b.javaEnabled && b.javaEnabled() || false); a.set(nb, (b && (b.language || b.browserLanguage) || "").toLowerCase()); }; pc.prototype.get = function (a) { return this.b.get(a); }; pc.prototype.set = function (a, b) { this.b.set(a, b); }; var qc = { pageview: [mb], event: [ub, xb, yb, zb], social: [Bb, Cb, Db], timing: [Mb, Nb, Pb, Ob] }; pc.prototype.send = function (a) { if(!(1 > arguments.length)) { var b, c; if ("string" === typeof arguments[0]) { (b = arguments[0], c =[].slice.call(arguments, 1)); } else { (b = arguments[0]&& arguments[0][hitType], c = arguments); } if (b) { c = preParameters(qc[b]||[], c), c[hitType]= b, this.b.set(c, void 0, true), this.filters.D(this.b), this.b.data.m = { }, setMsgCode(44); } } }; var onPageIsVisibility = function (funcrun) { if("prerender" == document.visibilityState) return false; funcrun(); return true; }; var td = /^(?:(\w+)\.)?(?:(\w+):)?(\w+)$/; var sc = function (a) { if(isFunction(a[0])) this.u = a[0]; else { var b = td.exec(a[0]); null != b && 4 == b.length && (this.c = b[1] || "t0", this.e = b[2] || "", this.d = b[3], this.a =[].slice.call(a, 1), this.e || (this.A = "create" == this.d, this.i = "require" == this.d, this.g = "provide" == this.d, this.ba = "remove" == this.d), this.i && (3 <= this.a.length ? (this.X = this.a[1], this.W = this.a[2]): this.a[1]&& (isString(this.a[1]) ? this.X = this.a[1]: this.W = this.a[1]))); b = a[1]; a = a[2]; if (!this.d) throw "abort"; if (this.i && (!isString(b) || "" == b)) throw "abort"; if (this.g && (!isString(b) || "" == b || !isFunction(a))) throw "abort"; if (ud(this.c) || ud(this.e)) throw "abort"; if (this.g && "t0" != this.c) throw "abort"; } }; function ud(a) { return 0 <= a.indexOf(".") || 0 <= a.indexOf(":"); }; var Yd; var Zd; var $d; Yd = new kVContainer; $d = new kVContainer; Zd = { ec: 45, ecommerce: 46, linkid: 47 }; var tc = function (a, b, c) { b == $ ? setMsgCode(35): b.get(V); var d = Yd.get(a); if (!isFunction(d)) return false; b.plugins_ = b.plugins_ || new kVContainer; if (b.plugins_.get(a)) return true; b.plugins_.set(a, new d(b, c || { })); return true; }; var parseUrl = function (a) { function b(a) { var b = (a.hostname || "").split(":")[0].toLowerCase(), c = (a.protocol || "").toLowerCase(), c = 1 * a.port || ("http:" == c ? 80 : "https:" == c ? 443 : ""); a = a.pathname || ""; inString(a, "/") || (a = "/" + a); return [b, "" +c, a]; } var c = document.createElement("a"); setHref(c, document.location.href); var d = (c.protocol || "").toLowerCase(), e = b(c), g = c.search || "", ca = d + "//" + e[0] + (e[1] ? ":" + e[1] : ""); inString(a, "//") ? a = d + a : inString(a, "/") ? a = ca + a : !a || inString(a, "?") ? a = ca + e[2] + (a || g) : 0 > a.split("/")[0].indexOf(":") &&(a = ca + e[2].substring(0, e[2].lastIndexOf("/")) + "/" + a); setHref(c, a); d = b(c); return { protocol: (c.protocol || "").toLowerCase(), host: d[0], port: d[1], path: d[2], G: c.search || "", url: a || "" }; }; var Z = { wa: function () { Z.f =[]; } }; Z.wa(); Z.D = function (a) { var b = Z.J.apply(Z, arguments), b = Z.f.concat(b); for (Z.f =[]; 0 < b.length && !Z.v(b[0]) && !(b.shift(), 0 < Z.f.length);); Z.f = Z.f.concat(b); }; Z.J = function (a) { for(var b = [], c = 0; c < arguments.length; c++) try { var d = new sc(arguments[c]); if (d.g) Yd.set(d.a[0], d.a[1]); else { if (d.i) { var e = d, g = e.a[0]; if (!isFunction(Yd.get(g)) && !$d.get(g)) { Zd.hasOwnProperty(g) && setMsgCode(Zd[g]); var ca = e.X; !ca && Zd.hasOwnProperty(g) ?(setMsgCode(39), ca = g + ".js") : setMsgCode(43); if (ca) { ca && 0 <= ca.indexOf("/") ||(ca = "/plugins/ua/" +ca); var l = parseUrl(ca); var e = void 0; var k = l.protocol; var w = document.location.protocol; e = "https:" == k || k == w ? true : "http:" != k ? false : "http:" == w; var xd; if (xd = e) { var e = l, be = parseUrl(document.location.href); if (e.G || 0 <= e.url.indexOf("?") || 0 <= e.path.indexOf("://")) xd = false; else if (e.host == be.host && e.port == be.port) xd = true; else { var ce = "http:" == e.protocol ? 80 : 443; xd = "localhost:25388" == e.host && (e.port || ce) == ce && inString(e.path, "/plugins/") ? true : false; } } xd && (createScript(l.url), $d.set(g, true)); } } } b.push(d); } } catch (de) { // throw de; } return b; }; Z.v = function (a) { try { if (a.u) a.u.call(window, $.j("t0")); else { var b = a.c == WXAnalyticsObjectName ? $: $.j(a.c); if (a.A) "t0" == a.c && $.create.apply($, a.a); else if (a.ba) $.remove(a.c); else if (b) if (a.i) { if (!tc(a.a[0], b, a.W)) return true; } else if (a.e) { var c = a.d, d = a.a, e = b.plugins_.get(a.e); e[c].apply(e, d); } else b[a.d].apply(b, a.a); } } catch (g) { // throw g; } }; var $ = function (a) { setMsgCode(1); Z.D.apply(Z, [arguments]); }; $.h = { }; $.P =[]; $.L = 0; $.answer = 42; var uc = [trackingId, cookieDomain, V]; $.create = function (a) { var b = preParameters(uc, [].slice.call(arguments)); b[V]|| (b[V] = "t0"); var c = "" + b[V]; if ($.h[c]) return $.h[c]; b = new pc(b); $.h[c]= b; $.P.push(b); return b; }; $.remove = function (a) { for(var b = 0; b < $.P.length; b++) if ($.P[b].get(V) == a) { $.P.splice(b, 1); $.h[a]= null; break; } }; $.j = function (a) { return $.h[a]; }; $.K = function () { return $.P.slice(0); }; $.N = function () { "wa" != WXAnalyticsObjectName && setMsgCode(49); var a = window[WXAnalyticsObjectName]; if (!a || 42 != a.answer) { $.L = a && a.l; $.loaded = true; var b = window[WXAnalyticsObjectName]= $; createCommands("create", b, b.create, 3); createCommands("remove", b, b.remove); createCommands("getByName", b, b.j, 5); createCommands("getAll", b, b.K, 6); b = pc.prototype; createCommands("get", b, b.get, 7); createCommands("set", b, b.set, 4); createCommands("send", b, b.send, 2); b = settings.prototype; createCommands("get", b, b.get); createCommands("set", b, b.set); (window.waplugins = window.waplugins || { }).Linker = Dc; b = Dc.prototype; Yd.set("linker", Dc); createCommands("decorate", b, b.Q, 20); createCommands("autoLink", b, b.S, 25); //Yd.set("displayfeatures", fd); //Yd.set("adfeatures", Kd); a = a && a.q; if (isArray(a)) { Z.D.apply($, a); } else { setMsgCode(50); } } }; //启动入口 (function () { var a = $.N; if (!onPageIsVisibility(a)) { setMsgCode(16); var b = false; var c = function () { !b && onPageIsVisibility(a) &&(b = true, removeEvent(document, "visibilitychange", c)); }; addEvent(document, "visibilitychange", c); } }) (); //这个是干什么的?我不知道。 function La(a) { var b = 1, c = 0, d; if (a) for (b = 0, d = a.length -1; 0 <= d; d--) { c = a.charCodeAt(d), b = (b << 0x6 & 0xFFFFFFF) +c + (c << 14), c = b & 0xFE00000, b = 0 != c ? b ^ c >> 21 : b; } return b; }; }) (window);
最后说一下,谷歌代码编译工具。
http://closure-compiler.appspot.com/home
编译后,代码长度明显变短了。。。
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。