Skip to content

Instantly share code, notes, and snippets.

@weisjohn
Created September 5, 2013 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weisjohn/6453681 to your computer and use it in GitHub Desktop.
Save weisjohn/6453681 to your computer and use it in GitHub Desktop.
Google Analytics beforeunload inpsection
// this code isn't intended to work:
if (J.body) {
a = aa(a);
try {
var c = J[qa]('<iframe name="' + a + '"></iframe>')
} catch (d) {
c = J[qa]("iframe"), ha(c, a)
}
c.height = "0";
c.width = "0";
c.style.display = "none";
c.style.visibility = "hidden";
var e = J[z],
e = ("https:" == J[z][A] || M.G ? "https://ssl.google-analytics.com" : "http://www.google-analytics.com") + "/u/post_iframe.html#" + aa(e[A] + "//" + e[u] + "/favicon.ico"),
f = function() {
c.src = "";
c.parentNode && c.parentNode.removeChild(c)
};
Ga(W, "beforeunload", f);
var Be = !1,
k = 0,
s = function() {
if (!Be) {
try {
if (9 < k || c.contentWindow[z][u] == J[z][u]) {
Be = !0;
f();
Ha(W, "beforeunload", f);
b();
return
}
} catch (a) {}
k++;
ca(s, 200)
}
};
Ga(c, "load", s);
J.body.appendChild(c);
c.src = e
} else We(function() {
Ee(a, b)
}, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment