Last active
May 3, 2016 09:27
-
-
Save englishextra/b1e2dec7ab9b5d5af28a02c7257b17e6 to your computer and use it in GitHub Desktop.
track clicks on external links
This file contains 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
/*! | |
* externalcounters-clicks.js | |
* track clicks on external links | |
* gist.github.com/englishextra/b1e2dec7ab9b5d5af28a02c7257b17e6 | |
*/ | |
"undefined" !== typeof window.jQuery && $(function () { | |
$(document).on("click", ".superbox-current-desc a", function (e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
var w = window, | |
d = document, | |
s = /localhost/.test(self.location.host) ? "http://localhost/externalcounters/" : "//shimansky.biz/externalcounters/", | |
rfrr = encodeURIComponent(d.location.href || ""), | |
ttl = encodeURIComponent(d.title || "").replace("\x27", "'"), | |
h = $(this).attr("href"), | |
dmn = h ? encodeURIComponent(h) : "", | |
b = d.getElementsByTagName("body")[0].firstChild || "", | |
a = d.createElement("div"); | |
a.setAttribute("style", "position:absolute;left:-9999px;width:1px;height:1px;border:0;background:transparent url(" + s + "?dmn=" + dmn + "&rfrr=" + rfrr + "&ttl=" + ttl + "&encoding=utf-8) top left no-repeat;"); | |
b && b.parentNode.insertBefore(a, b); | |
setTimeout(function () { | |
w.open(h, "_blank") || changeDocumentLocation(h); | |
}, 500); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment