Created
October 19, 2014 18:49
-
-
Save shawn-crigger/eb607b97ddeed37d2545 to your computer and use it in GitHub Desktop.
Very nicely used Google Analytics tracking code.
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
$("a").click(function() { | |
var href, href_lower; | |
href = ($(this).attr("href") === undefined ? "" : $(this).attr("href")); | |
href_lower = href.toLowerCase(); | |
if (href_lower.substr(-3) === "pdf" || href_lower.substr(-3) === "xls" || href_lower.substr(-3) === "doc") { | |
_gaq.push(["_trackEvent", "document", "download", href_lower.substr(-3), $(this).text()]); | |
_gaq.push(["_trackPageview", href]); | |
} | |
if (href_lower.substr(0, 4).toLowerCase() === "http") { | |
_gaq.push(["_trackEvent", "external_link", "open", "href", $(this).text()]); | |
_gaq.push(["_trackPageview", href]); | |
} | |
if ($(this).attr("target") !== undefined && $(this).attr("target").toLowerCase() !== "_blank" && href_lower.substr(0, 10) !== "javascript") { | |
setTimeout((function() { | |
location.href = href; | |
}), 200); | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment