Created
August 18, 2017 20:02
-
-
Save pganti/d928b14011df2a89ea37a51d1953dfed to your computer and use it in GitHub Desktop.
rum_timing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright 2010 Google Inc. | |
Copyright 2016 Akamai Technolgies | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
See the source code here: | |
http://code.google.com/p/episodes/ | |
*/ | |
! function() { | |
function e(e, a) { | |
function i() { | |
this.data = {}, this.value = [] | |
} | |
function s(e, t) { | |
for (var r = {}, n = a.getElementsByTagName(t), o = 0; o < n.length; o++) e.href = n[o].src || n[o].href, e.href.match(/^https?:\/\//) && (r[e.href] = n[o]); | |
return r | |
} | |
"undefined" == typeof e.RT && (e.RT = {}); | |
var u = e.RT; | |
if (!u.version && "undefined" != typeof e.AKSB.version && void 0 !== Object.keys) { | |
u.version = "0.2"; | |
var d = { | |
prefetch: 1, | |
preload: 2, | |
prerender: 3, | |
stylesheet: 4 | |
}; | |
u.init = function() { | |
u.getW3CTimings() | |
}, u.getW3CTimings = function() { | |
var p = new i, | |
f = u.getResourceTimingAPI(), | |
m = a.createElement("a"), | |
c = s(m, "script"), | |
l = s(m, "link"); | |
for (var S in f) | |
if ("undefined" != typeof f[S].duration) { | |
var v = [f[S].initiatorType]; | |
if ("script" === f[S].initiatorType || "link" === f[S].initiatorType) { | |
var g = c[f[S].name]; | |
g && (g.async ? v.push("async") : g.defer && v.push("defer")) | |
} | |
if ("link" === f[S].initiatorType) { | |
var g = l[f[S].name]; | |
g && g.hasAttribute("rel") && g.rel.split(/[\u0009\u000A\u000C\u000D\u0020]+/).find(function(e) { | |
if (e = e.toLowerCase(), d[e]) return v.push(d[e]), !0 | |
}) | |
} | |
p.insert(f[S].name, [Math.round(f[S].redirectStart), Math.round(f[S].redirectEnd), Math.round(f[S].fetchStart), Math.round(f[S].domainLookupStart), Math.round(f[S].domainLookupEnd), Math.round(f[S].connectStart), Math.round(f[S].connectEnd), Math.round(f[S].secureConnectionStart), Math.round(f[S].requestStart), Math.round(f[S].responseStart), Math.round(f[S].responseEnd), Math.round(f[S].duration), v.join("_"), f[S].nextHopProtocol, f[S].transferSize, f[S].encodedBodySize, f[S].decodedBodySize]) | |
} | |
u.radtree = p, u.baseurl = a.location.protocol.toLowerCase() + "//" + a.location.hostname.toLowerCase() + a.location.pathname; | |
var h = function(i) { | |
var s = new XMLHttpRequest; | |
s.open("POST", ("https:" === e.document.location.protocol ? "https:" : "http:") + "//ds-aksb-a.akamaihd.net/RRT", !0), s.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
var d = { | |
nt: escape(JSON.stringify(i)), | |
rt: escape(JSON.stringify(u.radtree.data)), | |
rid: e.AKSB.prof.requestid, | |
gh: e.AKSB.prof.ghostip, | |
b: e.AKSB.bf.get(), | |
c: e.AKSB.prof.custid, | |
us: e.AKSB.prof.ustr, | |
ol: e.AKSB.prof.originlat, | |
cr: e.AKSB.prof.clientrtt, | |
ua: t, | |
pl: r, | |
mt: n, | |
mb: o, | |
vc: e.AKSB.aksbVersion(), | |
bpcip: e.AKSB.getMangledAddress(), | |
akTX: e.AKSB.akTX, | |
akTI: e.AKSB.akTI, | |
ai: e.AKSB.prof.ai, | |
rf: "string" == typeof a.referrer ? encodeURIComponent(a.referrer.replace(/\?.*/, "?")) : "" | |
}, | |
p = []; | |
for (var f in d) d.hasOwnProperty(f) && d[f] && p.push(f + "=" + d[f]); | |
s.send(p.join("&")) | |
}, | |
E = e.performance && e.performance.timing; | |
if (E) { | |
var k = e.performance.timing, | |
y = function() { | |
if (k.loadEventEnd > 0) { | |
var t = [k.domainLookupEnd - k.domainLookupStart, k.connectStart - k.domainLookupStart, k.connectEnd - k.domainLookupStart, k.secureConnectionStart ? k.secureConnectionStart - k.domainLookupStart : null, k.requestStart - k.domainLookupStart, k.responseStart - k.domainLookupStart, k.responseEnd - k.domainLookupStart, k.domLoading - k.domainLookupStart, k.domInteractive - k.domainLookupStart, k.msFirstPaint ? k.msFirstPaint - k.navigationStart : "undefined" != typeof e.chrome && e.chrome.hasOwnProperty("loadTimes") ? Math.round(1e3 * e.chrome.loadTimes().firstPaintTime) - k.domainLookupStart : null, k.domContentLoadedEventStart - k.domainLookupStart, k.domContentLoadedEventEnd - k.domainLookupStart, k.domComplete - k.domainLookupStart, k.loadEventStart - k.domainLookupStart, k.loadEventEnd - k.domainLookupStart], | |
r = {}; | |
r[u.baseurl] = t, h(r) | |
} else k.loadEventEnd <= 0 && setTimeout(y, 100) | |
}; | |
y() | |
} else { | |
var b = function() { | |
if ("AKSB" in e && "measures" in e.AKSB && "t_plt" in e.AKSB.measures) { | |
var t = [null, null, null, 0, null, null, null, null, null, null, null, null, null, e.AKSB.measures.t_onload, e.AKSB.measures.t_plt], | |
r = {}; | |
r[u.baseurl] = t, h(r) | |
} else setTimeout(b, 100) | |
}; | |
b() | |
} | |
}, u.getResourceTimingAPI = function() { | |
if ("performance" in e) { | |
if ("getEntriesByType" in e.performance) return e.performance.getEntriesByType("resource"); | |
if ("webkitGetEntriesByType" in e.performance) return e.performance.webkitGetEntriesByType("resource") | |
} | |
return null | |
}, i.prototype.insert = function(e, t) { | |
for (var r = this.data; e;) { | |
var n = this.get_prefix(e, Object.keys(r)), | |
o = n[0], | |
a = n[1]; | |
if (!o || "string" != typeof o || "string" != typeof a) break; | |
var i = o.length; | |
if (o !== a) { | |
var s = a.slice(i, a.length), | |
u = r[a]; | |
u === this.value && (u = JSON.parse(JSON.stringify(u))), r[o] = {}, r[o][s] = u, delete r[a] | |
} else r[o] === this.value && (r[o] = JSON.parse(JSON.stringify(this.value))); | |
e = e.slice(i, e.length), r = r[o] | |
} | |
return r[e] = e ? t : null, !0 | |
}, i.prototype.get_prefix = function(e, t) { | |
function r(e, t) { | |
return e.length < t.length ? -1 : e.length > t.length ? 1 : 0 | |
} | |
function n(e, t) { | |
return "" === t || null != e && null != t && (e = String(e), t = String(t), e.length >= t.length && e.slice(0, t.length) === t) | |
} | |
if (t.sort(r), "undefined" != typeof e) { | |
wc = e[0]; | |
for (var o in t) | |
if (n(t[o], wc)) | |
for (var a = e.length; a >= 1; a--) | |
if (n(t[o], e.slice(0, a))) return [e.slice(0, a), t[o]] | |
} | |
return ["", null] | |
}; | |
var p = e.AKSB.prof.akTT; | |
if (e.performance && (e.performance.getEntries || e.performance.webkitGetEntries)) | |
if ("R" === p) u.init(); | |
else { | |
if ("O" !== p && void 0 !== p || !(e.document.location.search.search("akamai-rum-rt=on") >= 0) && 5 <= 100 * Math.random()) return; | |
u.init() | |
} | |
} | |
} | |
var t, r, n, o; | |
! function(a) { | |
a.parent !== a && void 0 == a.AKSB && (a = a.parent); | |
var i = a.document; | |
"undefined" == typeof a.AKSB && (a.AKSB = {}); | |
var s = a.AKSB; | |
if (void 0 != s.prof && s.prof.origin === !0) { | |
var u = "number" == typeof s.prof.beaconrate ? parseInt(s.prof.beaconrate, 10) : 10; | |
if (u <= 100 * Math.random()) return | |
} | |
if (s.q = s.q || [], s.autorun = "undefined" == typeof s.autorun || s.autorun, !s.version && "X" !== a.AKSB.prof.akTT) { | |
s.version = 13; | |
var d, p, f, m, c, l; | |
s.init = function() { | |
s.bDone = !1, s.marks = {}, s.measures = {}, s.starts = {}, s.getClientProf(), s.processQ(); | |
var e = s.findStartWebTiming(); | |
e && (s.mark("starttime", e), s.addEventListener("DOMContentLoaded", s.onready, !1), s.addEventListener("load", s.onload, !1), "complete" === i.readyState && (s.onloadHasFired = !0, window.setTimeout(s.onload, 1)), s.processQ()) | |
}, s.processQ = function() { | |
for (var e = s.q.length, t = 0; t < e; t++) { | |
var r = s.q[t], | |
n = r[0]; | |
"mark" === n ? s.mark(r[1], r[2]) : "measure" === n ? s.measure(r[1], r[2], r[3]) : "done" === n && s.done(r[1]) | |
} | |
}, s.getClientProf = function() { | |
s.prof = s.prof || {}, d = s.prof.ipv6 === !0 || "true" === s.prof.ipv6, p = s.prof.beaconUrl || ("https:" === i.location.protocol ? "https:" : "http:") + "//ds-aksb-a.akamaihd.net/2/" + s.prof.custid + "/b", t = escape(a.navigator.userAgent), r = escape(a.navigator.platform), f = escape(i.location.protocol.toLowerCase() + "//" + i.location.hostname.toLowerCase() + i.location.pathname); | |
var e = a.navigator.connection || a.navigator.mozConnection || a.navigator.webkitConnection, | |
u = "", | |
S = ""; | |
if (e && "number" == typeof e.type ? e.type == e.WIFI ? (u = "wifi", S = 7e6) : e.type == e.CELL_2G ? (u = "cellular", S = 384) : e.type == e.CELL_3G ? (u = "cellular", S = 42e3) : e.type == e.CELL_4G ? (u = "cellular", S = 1e5) : e.type == e.ETHERNET ? (u = "ethernet", S = 1e7) : e.type == e.NONE ? (u = "none", S = 0) : u = "unknown" : e && "string" == typeof e.type && (u = e.type, e.downlinkMax && (S = Math.round(1e3 * e.downlinkMax))), n = escape(u), o = S, m = i.visibilityState || i.webkitVisibilityState || i.mozVisibilityState || i.msVisibilityState, c = "undefined" != typeof a.aFeoApplied, l = "" !== i.location.search, s.prof.pct) { | |
var v = !(parseInt(s.prof.pct, 10) <= 100 * Math.random()); | |
if (v && void 0 !== s.prof.clientip) { | |
var g = s.getMangledAddress(), | |
h = d ? "j" : "i"; | |
p = ("https:" === i.location.protocol ? "https:" : "http:") + "//" + h + g + "-ds-aksb-a.akamaihd.net/2/" + s.prof.custid + "/b" | |
} | |
} | |
}, s.getMangledAddress = function() { | |
if (void 0 === s.prof.clientip) return ""; | |
if (d) { | |
var e = s.prof.clientip.split(":"); | |
return ("" == e[0] ? "" : parseInt(e[0], 16).toString(32)) + "z" + ("" == e[1] ? "" : parseInt(e[1], 16).toString(32)) + "z" + ("" == e[2] ? "" : parseInt(e[2], 16).toString(32)) | |
} | |
var e = s.prof.clientip.split("."); | |
return ("00000000" + (256 * (256 * (256 * +e[0] + +e[1]) + +e[2]) + 0).toString(16)).slice(-8) | |
}, s.mark = function(e, t) { | |
e && (s.marks[e] = parseInt(t || (new Date).getTime(), 10), "firstbyte" === e ? s.measure("t_fb", "starttime", "firstbyte") : "onload" === e ? s.measure("t_onload", "starttime", "onload") : "done" === e && s.measure("t_plt", "starttime", "done")) | |
}, s.measure = function(e, t, r) { | |
if (e) { | |
var n; | |
if ("undefined" == typeof t) n = "number" == typeof s.marks[e] ? s.marks[e] : (new Date).getTime(); | |
else if ("number" == typeof s.marks[t]) n = s.marks[t]; | |
else { | |
if ("number" != typeof t) return; | |
n = t | |
} | |
var o; | |
if ("undefined" == typeof r) o = (new Date).getTime(); | |
else if ("number" == typeof s.marks[r]) o = s.marks[r]; | |
else { | |
if ("number" != typeof r) return; | |
o = r | |
} | |
s.starts[e] = parseInt(n, 10), s.measures[e] = parseInt(o - n, 10) | |
} | |
}, s.done = function(e) { | |
s.mark("done"); | |
var t = function() { | |
s.bDone = !0, s.autorun && s.sendBeacon(), "function" == typeof e && e() | |
}, | |
r = s.getNavTimingAPI(), | |
n = r.navigation, | |
o = r.timing; | |
if (void 0 !== r) { | |
var i = function() { | |
for (var e in o) s.mark(e, o[e]); | |
if (s.measure("dE", "domainLookupStart", "domainLookupEnd"), s.measure("cS", "domainLookupStart", "connectStart"), o.secureConnectionStart && s.measure("sS", "domainLookupStart", "secureConnectionStart"), s.measure("cE", "domainLookupStart", "connectEnd"), s.measure("rqS", "domainLookupStart", "requestStart"), s.measure("rsS", "domainLookupStart", "responseStart"), s.measure("rsE", "domainLookupStart", "responseEnd"), o.msFirstPaint) s.measure("fp", "navigationStart", "msFirstPaint"); | |
else if ("undefined" != typeof a.chrome && a.chrome.hasOwnProperty("loadTimes")) { | |
var r = Math.round(1e3 * a.chrome.loadTimes().firstPaintTime); | |
r > 0 && s.measure("fp", "domainLookupStart", r) | |
} | |
s.measure("dl", "domainLookupStart", "domLoading"), s.measure("di", "domainLookupStart", "domInteractive"), s.measure("dlS", "domainLookupStart", "domContentLoadedEventStart"), s.measure("dlE", "domainLookupStart", "domContentLoadedEventEnd"), s.measure("dc", "domainLookupStart", "domComplete"), s.measure("leS", "domainLookupStart", "loadEventStart"), s.measure("leE", "domainLookupStart", "loadEventEnd"), t() | |
}, | |
u = function() { | |
n && (0 === n.type || 1 === n.type) && o && o.loadEventEnd > 0 ? i() : o && o.loadEventEnd <= 0 && setTimeout(u, 100) | |
}; | |
u() | |
} | |
}, s.aksbVersion = function() { | |
return "" + (void 0 === s.prof.blver ? 0 : s.prof.blver) + ":" + (void 0 === s.version ? 0 : s.version) | |
}, s.sendBeacon = function(u, d) { | |
u = u || p; | |
var m = (s.measures, ""); | |
s.bf = s.bitField(), s.createBitField(); | |
var c = { | |
dE: s.measures.dE, | |
cS: s.measures.cS, | |
cE: s.measures.cE, | |
rqS: s.measures.rqS, | |
rsS: "undefined" != typeof s.measures.rsS ? s.measures.rsS : s.measures.t_fb, | |
rsE: s.measures.rsE, | |
sS: s.measures.sS, | |
dl: s.measures.dl, | |
di: s.measures.di, | |
fp: s.measures.fp, | |
dlS: s.measures.dlS, | |
dlE: "undefined" != typeof s.measures.dlE ? s.measures.dlE : s.measures.t_onready, | |
dc: s.measures.dc, | |
leS: "undefined" != typeof s.measures.leS ? s.measures.leS : s.measures.t_onload, | |
leE: "undefined" != typeof s.measures.leE ? s.measures.leE : s.measures.t_plt, | |
to: s.measures.to, | |
ol: s.prof.originlat, | |
cr: s.prof.clientrtt, | |
mt: n, | |
mb: o, | |
b: s.bf.get(), | |
u: f, | |
ua: t, | |
pl: r, | |
us: s.prof.ustr, | |
gh: s.prof.ghostip, | |
t: s.prof.token, | |
rid: s.prof.requestid, | |
r: s.prof.region, | |
akM: s.prof.akM, | |
akN: s.prof.akN, | |
vc: s.aksbVersion(), | |
bpcip: s.getMangledAddress(), | |
akTX: s.prof.akTX, | |
akTI: s.prof.akTI, | |
ai: s.prof.ai, | |
pmgn: s.prof.pmgn, | |
pmgi: s.prof.pmgi, | |
pmp: s.prof.pmp | |
}; | |
if (c) | |
for (var l in c) m += "&" + escape(l) + "=" + ("undefined" == typeof c[l] ? "" : c[l]); | |
if (m) { | |
if (m = m.substring(1), d) | |
for (var S in d) d.hasOwnProperty(S) && (m += "&" + escape(S) + "=" + escape(d[S])); | |
var v = (s.bf.get(), new Image); | |
return v.src = u + "?" + m, e(a, i), v.src | |
} | |
return "" | |
}, s.bitField = function(e) { | |
var t = Math.abs(e), | |
r = function() {}; | |
return r.prototype.set = function(e) { | |
return this.hasbit(e) ? t : t |= e | |
}, r.prototype.hasbit = function(e) { | |
return e > t ? 0 : t & e | |
}, r.prototype.get = function() { | |
return t | |
}, new r | |
}, s.createBitField = function() { | |
var e = { | |
MS_NT: 1, | |
IPv6: 16, | |
FEO: 32, | |
VIA_SPDY: 64, | |
VIS_HIDDEN: 128, | |
VIS_VISIBLE: 256, | |
VIS_PRERENDERED: 512, | |
QUERY_TRUNCATED: 2048, | |
RUM_AT_ORIGIN: 4096, | |
ONLOAD_HAS_FIRED: 8192, | |
VIA_HTTP_TWO: 131072, | |
TXN_ENABLED: 262144, | |
RUA_APPLIED: 524288, | |
VIA_QUIC: 1048576 | |
}; | |
s.bf.set(e.MS_NT); | |
var t = s.prof.protocol; | |
void 0 !== t && ("h2" == t.slice(0, 2) ? s.bf.set(e.VIA_HTTP_TWO) : "spdy" == t.slice(0, 4) && s.bf.set(e.VIA_SPDY)); | |
var r = s.prof.qc; | |
"string" == typeof r && "" !== r && "0" !== r && s.bf.set(e.VIA_QUIC), d && s.bf.set(e.IPv6), c && s.bf.set(e.FEO), "hidden" === m && s.bf.set(e.VIS_HIDDEN), "visible" === m && s.bf.set(e.VIS_VISIBLE), "prerendered" === m && s.bf.set(e.VIS_PRERENDERED), l && s.bf.set(e.QUERY_TRUNCATED), s.prof.origin === !0 && s.bf.set(e.RUM_AT_ORIGIN), s.onloadHasFired === !0 && s.bf.set(e.ONLOAD_HAS_FIRED), "true" === s.prof.ra && s.bf.set(e.RUA_APPLIED), s.prof.akTT && "O" != s.prof.akTT && s.bf.set(e.TXN_ENABLED) | |
}, s.findStartWebTiming = function() { | |
var e = void 0, | |
r = s.getNavTimingAPI(); | |
return "undefined" != typeof r && "undefined" != typeof r.timing && "undefined" != typeof r.timing.navigationStart && (e = t.match(/Firefox\/[78]\./i) ? r.timing.unloadEventStart || r.timing.fetchStart : r.timing.navigationStart), e | |
}, s.onready = function(e) { | |
s.mark("onready", (new Date).getTime()), s.measure("t_onready", "starttime", "onready") | |
}, s.onload = function(e) { | |
s.mark("onload", (new Date).getTime()), s.autorun && s.done() | |
}, s.addEventListener = function(e, t, r) { | |
return "undefined" != typeof a.attachEvent ? a.attachEvent("on" + e, t) : a.addEventListener ? a.addEventListener(e, t, r) : void 0 | |
}, s.getNavTimingAPI = function() { | |
return a.performance || a.mozPerformance || a.msPerformance || a.webkitPerformance | |
}, s.init() | |
} | |
}(window) | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment