Skip to content

Instantly share code, notes, and snippets.

@englishextra
Last active May 3, 2016 09:27
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 englishextra/b1e2dec7ab9b5d5af28a02c7257b17e6 to your computer and use it in GitHub Desktop.
Save englishextra/b1e2dec7ab9b5d5af28a02c7257b17e6 to your computer and use it in GitHub Desktop.
track clicks on external links
/*!
* 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