Skip to content

Instantly share code, notes, and snippets.

@bdittmer
Created April 30, 2014 03:43
Show Gist options
  • Save bdittmer/009b369f962fc49b75db to your computer and use it in GitHub Desktop.
Save bdittmer/009b369f962fc49b75db to your computer and use it in GitHub Desktop.
(function () {
function L(a) {
return typeof a == "string" || a instanceof String
}
function M(a) {
return a === Object(a)
}
function N(a) {
return Array.isArray ? Array.isArray(a) : Object.prototype.toString.call(a) == "[object Array]"
}
function O(a) {
var b = P(a, "class");
return M(b) ? b.baseVal : b
}
function P(a, b) {
return a.getAttribute ? a.getAttribute(b) || "" : a[b]
}
function S(b, c, e, f) {
a.addEventListener ? b.addEventListener(c, e, f) : a.attachEvent ? b.attachEvent("on" + c, function () {
var a = d.event;
a.currentTarget = b, a.target = a.srcElement, e.call(b, a)
}) : b["on" + c] = e
}
function T(a, b, c, d) {
if (a.removeEventListener) return a.removeEventListener(b, c, d), !0;
if (a.detachEvent) return a.detachEvent("on" + b, c);
a["on" + b] == c && delete a["on" + b]
}
function U() {
var a;
bq.flush();
if (I)
do a = new Date; while (a.gt() < I)
}
function V() {
if (D) return !1;
D = !0;
if (_(m) || bh(n)) bg(n, "on", 18e5), W(), heap.appid = _heapid = "3407116132", d.heapV = {
track: heap.track,
identify: heap.identify
}, heap.track = heap.identify = function () {}, bq.clear(), by = [];
return bu(function () {
bq.startLoop(), br(by)
}), !0
}
function W() {
var b, c;
a.charset = "UTF-8", b = a.createElement("script"), b.type = "text/javascript", b.src = o, a.head.appendChild(b), c = a.createElement("link"), c.rel = "stylesheet", c.href = p, a.head.appendChild(c)
}
function X() {
if (a.readyState === "interactive" || a.readyState === "complete") return V();
a.addEventListener ? S(a, "DOMContentLoaded", function b() {
a.removeEventListener("DOMContentLoaded", b, !1), V()
}) : a.attachEvent && a.attachEvent("onreadystatechange", function c() {
a.readyState === "complete" && (a.detachEvent("onreadystatechange", c), V())
}), S(d, "load", V, !1)
}
function Y(a) {
var b, c;
a = a || d.event, b = a.which || a.button, c = a.target || a.srcElement;
if (F && c !== a.currentTarget) return;
a.type === "click" ? c && bv(a) : a.type === "mousedown" ? b !== 1 && b !== 2 || !c ? lastButton = lastTarget = null : (lastButton = b, lastTarget = c) : a.type === "mouseup" && (b === lastButton && c === lastTarget && bv(a), lastButton = lastTarget = null)
}
function Z(a, b) {
return L(a) ? a.slice(0, b) : a
}
function $(a) {
var b = new RegExp("#.*");
return a.replace(b, "")
}
function _(a, b) {
b = b || d.location.search, a = a.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var c = new RegExp("[\\?&]" + a + "=([^&#]*)"),
e = c.exec(b);
return e === null ? "" : decodeURIComponent(e[1].replace(/\+/g, " "))
}
function ba(a) {
var b = new RegExp("^(?:(?:https?|ftp):)/*(?:[^@]+@)?([^:/#]+)"),
c = b.exec(a);
return c ? c[1] : a
}
function bb(a) {
var b, c, d;
b = ba(a), d = a.slice(a.indexOf("?"));
if (b.search("google.([^/?]*)$") >= 0 || b.search("bing.com$") >= 0) c = "q";
else if (b.search("yahoo.com$") >= 0) c = "p";
else return "";
return f(_(c, d))
}
function bc(b, c, d) {
if (b === "translate.googleusercontent.com") d === "" && (d = c), c = getParameter(c, "u"), b = ba(c);
else if (b === "cc.bingj.com" || b === "webcache.googleusercontent.com" || b.slice(0, 5) === "74.6.") c = a.links[0].href, b = ba(c);
return [b, c, d]
}
function bd(b) {
return ("https:" == a.location.protocol ? "https" : "http") + "://" + b
}
function be(a) {
return /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/.test(a)
}
function bf(a) {
return a = a.toString(), a.length > x && (a = a.slice(0, x).split(" ").slice(0, -1).join(" ")), a.replace(/[\(\)\!\@\#\$\%\^\&\*]/g, "")
}
function bg(b, c, d) {
var f, h;
d && (f = new Date, f.setTime(f.gt() + d)), h = i.match(/[a-z0-9][a-z0-9\-]+\.[a-z\.]{2,6}$/i), a.cookie = b + "=" + e(c) + (d ? ";expires=" + f.toGMTString() : "") + (h ? ";domain=." + h[0] : "") + ";path=/" + (g ? ";secure" : "")
}
function bh(b) {
var c = new RegExp("(^|;)[ ]*" + b + "=([^;]*)"),
d = c.exec(a.cookie);
return d ? f(d[2]) : 0
}
function bi(a) {
return t + a + "." + _heapid
}
function bj(a, b, c) {
bg(bi("id"), a + "." + b + "." + c, u)
}
function bk() {
bg(bi("ses"), "*", v)
}
function bl(a) {
var b, c, d;
b = bh(bi("id")), c = bh(bi("ses"));
if (!b) {
b = bh("_hp_id." + _heapid), c = bh("_hp_ses." + _heapid);
if (b) return H = 2, d = b.split("."), d[1] = R(32, 10), c || (H = 1, d[2] = R(32, 10)), J = "a=" + _heapid + "&u=" + d[0] + "&v=" + d[1] + "&s=" + d[2] + "&b=web", bm(r, "z=4", function (b) {
if (!b || !b.uid) return;
d[0] = b.uid, bk(), bj(b.uid, d[1], d[2]), bg("_hp_id." + _heapid, "", -(new Date).gt()), bg("_hp_ses." + _heapid, "", -(new Date).gt()), a(d)
})
}
return b ? (H = 2, d = b.split("."), d[1] = R(32, 10), c || (H = 1, d[2] = R(32, 10))) : (H = 0, d = [R(53, 10), R(32, 10), R(32, 10)]), bk(), bj(d[0], d[1], d[2]), a(d)
}
function bm(b, c, e) {
var f, g;
if (!c) return;
c = c ? "&" + c : "", d._hpjsonpcallback = e, g = a.head || a.getElementsByTagName("head")[0] || a.documentElement, f = a.createElement("script"), f.async = "async", f.src = b + "?" + J + c + "&callback=_hpjsonpcallback", f.onload = f.onreadystatechange = function () {
if (!f.readyState || /loaded|complete/.test(f.readyState)) f.onload = f.onreadystatechange = null, g && f.parentNode && g.removeChild(f), f = undefined
}, g.insertBefore(f, g.firstChild)
}
function bn(a, b) {
if (!a || E) return;
var c = new Image(1, 1);
b = b || q, c.onload = function () {
I = 0
}, c.onerror = function () {
E = !0
}, c.src = b + "?" + J + "&" + a, I = (new Date).gt() + B
}
function bo(a, b) {
bn(a[0], b);
for (K = 1; K < a.length; K++)(function (a, c) {
setTimeout(function () {
bn(a, b)
}, 10 * c)
})(a[K], K)
}
function bp(a) {
var b = "",
c = 0,
d = [],
f = function (a, b) {
return b !== undefined && b !== "" ? "&" + a + "=" + e(b) : ""
},
g = function (b) {
var d, e, g, h;
h = "", e = a ? c++ : "";
for (d in b) {
if (!b.hasOwnProperty(d)) continue;
g = b[d];
if (N(g))
for (K = 0; K < g.length; K++) h += f(d + e, g[K]);
else h += f(d + e, g)
}
return h
};
return {
addProps: function (a) {
var e = g(a);
e.length + b.length > z && (d.push(b), b = "", c = 0, e = g(a)), b += e
},
build: function (a) {
if (!a) return b.slice(1);
d.push(b);
for (K = 0; K < d.length; K++) d[K] = d[K].slice(1);
return d
}
}
}
function br(a) {
for (K = 0; K < a.length; K++) {
var b = a[K][0];
d.heap[b].apply(this, a[K].slice(1))
}
}
function bs(a) {
var b, c, d;
b = bp(), bl(function (c) {
d = {
a: _heapid,
u: c[0],
v: c[1],
s: c[2],
b: "web"
}, b.addProps(d), J = b.build(), a && a()
})
}
function bt() {
var b, c, e;
return b = bp(), c = $(k), e = {
z: H,
g: Z(d.location.hash, w),
h: Z(d.location.pathname, w),
q: Z(d.location.search, w),
d: Z(d.location.hostname, w),
t: Z(a.title, x),
r: Z(c, w),
e: Z(bb(c), w),
us: Z(_("utm_source"), w),
um: Z(_("utm_medium"), w),
ut: Z(_("utm_term"), w),
uc: Z(_("utm_content"), w),
ua: Z(_("utm_campaign"), w)
}, b.addProps(e), b.build()
}
function bu(a) {
var b, c, d;
bs(function () {
b = bt(), bn(b), a && a()
})
}
function bv(a) {
var b = a || d.event;
bq.queueEvent(b)
}
"use strict";
var a = document,
b = navigator,
c = screen,
d = window,
e = d.encodeURIComponent,
f = d.decodeURIComponent,
g = a.location.protocol === "https",
h = bc(a.domain, d.location.href, a.referrer),
i = h[0],
j = h[1],
k = h[2],
l = d.location.pathname + d.location.hash,
m = "heap-event-visualizer",
n = "_hp_ved",
o = bd("heapanalytics.com/js/ved.js"),
p = bd("heapanalytics.com/css/ved.css"),
q = bd("heapanalytics.com/h"),
r = bd("heapanalytics.com/u"),
s = bd("heapanalytics.com/api/identify"),
t = "_hp2_",
u = 63072e6,
v = 18e5,
w = 1024,
x = 255,
y = 64,
z = 3900,
A = 2e3,
B = 300,
C = ["change", "submit"],
D = !1,
E = !1,
F, G, H, I, J, K;
G = b.appVersion, G && (G.indexOf("MSIE 6.") > -1 ? (F = 6, z = 1700) : G.indexOf("MSIE 7.") > -1 ? (F = 7, z = 1900) : G.indexOf("MSIE 8.") > -1 && (F = 8)), Date.prototype.gt = Date.prototype.getTime;
var Q = [].indexOf || function (a) {
for (var b = 0, c = this.length; b < c; b++)
if (b in this && this[b] === a) return b;
return -1
},
R = function (a, b) {
b || (b = 16), a === undefined && (a = 128);
if (a <= 0) return "0";
var c = Math.log(Math.pow(2, a)) / Math.log(b);
for (var d = 2; c === Infinity; d *= 2) c = Math.log(Math.pow(2, a / d)) / Math.log(b) * d;
var e = c - Math.floor(c),
f = "";
for (var d = 0; d < Math.floor(c); d++) {
var g = Math.floor(Math.random() * b).toString(b);
f = g + f
}
if (e) {
var h = Math.pow(b, e),
g = Math.floor(Math.random() * h).toString(b);
f = g + f
}
var i = parseInt(f, b);
return i !== Infinity && i >= Math.pow(2, a) ? R(a, b) : f
},
bq = function () {
var a = [],
b = !1,
c = function () {
e(), setTimeout(c, A)
},
e = function () {
var c, d, e, f;
if (!b) return;
d = bp(!0);
for (f = 0; f < a.length; f++) c = a[f], d.addProps(c);
e = d.build(!0), bo(e), a = []
},
f = function (a) {
var b, c;
return b = a.target || a.srcElement, F && a.srcElement !== a.currentTarget ? !1 : b ? (c = P(b, "type"), c === "password" ? !1 : P(b, "heap-ignore") ? !1 : a.type === "mousedown" || a.type === "mousemove" ? !1 : !0) : !1
},
g = function (a) {
var b = null;
while (a && a.tagName !== "BODY" && a.tagName !== "HTML") {
b = P(a, "href");
if (b) return b;
a = a.parentElement
}
return b
},
h = function (a) {
var b, c, d, e;
c = "";
while (a && a.tagName !== "BODY" && a.tagName !== "HTML") {
b = "@" + a.tagName.toLowerCase() + ";", e = P(a, "id"), e && (b += "#" + e.replace(/\s/g, "") + ";"), d = O(a), d && (b += "." + d.split(/\s+/).sort().join(";.") + ";"), b += "|";
if (c.length + b.length > w) break;
c = b + c, a = a.parentElement
}
return c
},
i = function (a) {
var b, c, e, f;
return a = a || d.event, c = a.target || a.srcElement, e = O(c), f = a.type === "mouseup" ? "click" : a.type, b = {
t: Z(f, x),
n: Z(c.tagName.toLowerCase(), x),
c: Z(bf(e), x),
i: Z(P(c, "id"), x),
h: Z(g(c), w),
y: h(c)
}, L(c.innerText) && (b.x = Z(c.innerText.replace(/^\s+|\s+$/g, ""), y)), be(c.value) && (b.l = Z(c.value, x)), b
};
return new function () {
this.startLoop = function () {
b = !0, c()
}, this.clear = function () {
a = []
}, this.flush = e, this.queueEvent = function (a) {
var b;
if (!f(a)) return;
b = i(a), this.queue(b)
}, this.queue = function (b) {
a.push(b)
}
}
}();
if (typeof Event != "undefined") {
var bw = Event.prototype.dispatchEvent;
Event.prototype.dispatchEvent = function () {
return bv(this), bw.apply(this, arguments)
}
}
var bx = d.heap || [],
by = [];
d.heap = {
identify: function (a) {
var b, c, d, e, f, g;
if (!D) {
by.push(["identify", a]);
return
}
c = {}, b = bp(), f = ["handle", "email"];
if (!M(a)) return;
for (e in a) {
if (!a.hasOwnProperty(e)) continue;
if (M(a[e])) continue;
g = Z(a[e], x), Q.call(f, e) >= 0 ? c[e.charAt(0)] = g : c[Z(e, x)] = g
}
b.addProps(c), d = b.build(), bm(s, d, function (a) {
var b, c;
if (!a || !a.uid) return;
b = bh(bi("id")), c = b.split("."), bj(a.uid, c[1], c[2]), bs()
})
},
track: function (a, b) {
var c, d, e;
if (!L(a)) return;
e = {
t: a
};
if (M(b))
for (c in b) {
if (!b.hasOwnProperty(c)) continue;
d = b[c];
if (typeof d == "undefined" || d === null || d === "") continue;
d = d.toString(), e.k = e.k || [], e.k.push(c), e.k.push(d)
}
bq.queue(e)
}
}, br(bx), heap.appid = _heapid, S(d, "beforeunload", U, !0);
if (F) {
var bz = function () {
var b = a.getElementsByTagName("*");
for (var c = 0; c < b.length; c++) {
var d = b[c];
if (d.nodeType === 1 && !d._hpseen) {
d._hpseen = !0, S(d, "click", Y);
for (var e = 0; e < C.length; e++) S(d, C[e], bv)
}
}
setTimeout(bz, A)
};
bz()
} else {
S(d, "click", Y, !0);
for (K = 0; K < C.length; K++) S(d, C[K], bv, !0)
} if (d.history.pushState) {
var bA = function (a, b, c) {
var d = a[b];
a[b] = function () {
var b = d.apply(a, arguments);
return typeof a[c] == "function" && a[c](), b
}
};
bA(d.history, "pushState", "heappushstate"), bA(d.history, "replaceState", "heapreplacestate");
var bB = function () {
var a = d.location.pathname + d.location.hash;
l !== a && (l = a, bu())
};
history.heappushstate = history.heapreplacestate = bB, window.addEventListener("popstate", bB, !0), window.addEventListener("hashchange", bB, !0)
}
X()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment