Skip to content

Instantly share code, notes, and snippets.

@cacheleocode
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save cacheleocode/9221834 to your computer and use it in GitHub Desktop.

Select an option

Save cacheleocode/9221834 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
$.ajaxSetup({
url: "/process/",
cache: false
});
$("#topbar .search input[title!=]").hint();
$("#navigation").navigation();
$("table.type1").table();
$(".dialog").bind("click",function(e){
e.preventDefault();
$($(this).attr("href")).dialog();
return false;
}); // bind
// event tracking
function getLinkText(obj)
{
var linkText;
if ($(obj).text() != "")
{
linkText = $(obj).text();
}
else if (($(obj).text() === "") && ($(obj).children("img") != "") && ($(obj).children("img").attr("alt") != ""))
{
linkText = $(obj).children("img").attr("alt");
}
else if (($(obj).text() === "") && ($(obj).children("img") != "") && ($(obj).children("img").attr("alt") === ""))
{
linkText = $(obj).children("img").attr("src").split("/").pop();
}
return linkText;
} //getLinkText()
var url = location.href.replace(/^.*\/\/[^\/]+/,"");
var host = location.host.replace(/\\./, "\\.");
var fileTypes = /\.doc$|\.xls$|\.pdf$|\.oft$/i;
var pattern = new RegExp("^(http\:\/\/)*(www\.)*(" + host + ")*\/", "i");
var fileName = "";
$("a").bind("click",function(){
if($(this).attr("href").match(fileTypes))
{
var fileType = $(this).attr("href").match(fileTypes).toString().replace(".", "").toLowerCase();
fileName = $(this).attr("href").replace(pattern,"");
_gaq.push(["_trackEvent", fileType, "download", "/" + fileName]);
}
});
$("#topbar a").bind("click",function(){
_gaq.push(["_trackEvent", "topbar", "click", getLinkText($(this))]);
});
$("#topbar form").bind("submit",function(e){
_gaq.push(["_trackEvent", "topbar", "search", $(this).find("input[name='k']").val()]);
});
$("#masthead .logo a").bind("click",function(e){
_gaq.push(["_trackEvent", "masthead", "click", "logo"]);
});
$("#navigation > .content > ul > li > a").bind("click",function(){
_gaq.push(["_trackEvent", "main navigation tab", "click", $(this).text()]);
});
$("#navigation > .content > ul > li > a").hover(function(){
_gaq.push(["_trackEvent", "main navigation tab", "hover", $(this).text()]);
});
$("#navigation .sub h3, #navigation .sub p, #navigation .sub a").bind("click",function(){
_gaq.push(["_trackEvent", "main navigation", "click", $(this).text()]);
});
$(".nivo-directionNav a, .nivo-controlNav a").live("click",function(){
_gaq.push(["_trackEvent", "slider", "click", $(this).text()]);
});
$("#breadcrumbs a").bind("click",function(){
_gaq.push(["_trackEvent", "breadcrumbs", "click", $(this).text()]);
});
$(".segment.block a").bind("click",function(){
_gaq.push(["_trackEvent", "content switcher", "click", $(this).text()]);
});
$(".navigation.block a").bind("click",function(){
_gaq.push(["_trackEvent", "content navigation", "click", $(this).text()]);
});
$(".group.zone_1 .block.html a").bind("click",function(){
_gaq.push(["_trackEvent", "zone_1", "click", getLinkText($(this))]);
});
$(".group.zone_2 .block.html a").bind("click",function(){
_gaq.push(["_trackEvent", "zone_2", "click", getLinkText($(this))]);
});
$(".group.sidebar a").bind("click",function(){
_gaq.push(["_trackEvent", "sidebar", "click", getLinkText($(this))]);
});
$(".pagination.block .prev a").bind("click",function(){
_gaq.push(["_trackEvent", "pagination", "prev", $(this).text()]);
});
$(".pagination.block .next a").bind("click",function(){
_gaq.push(["_trackEvent", "pagination", "next", $(this).text()]);
});
$("#footer a").bind("click",function(){
_gaq.push(["_trackEvent", "footer", "click", getLinkText($(this))]);
});
$("body.home .promos .promo a").bind("click",function(){
_gaq.push(["_trackEvent", "slot", "click", $(this).parents(".promo").prop("class")]);
_gaq.push(["_trackEvent", $(this).parents(".promo").prop("class"), "click", getLinkText($(this))]);
});
var obj = $("h3").filter(function(){
return $(this).text() == "type 1 table with caption, with thead, and with supplemental table headers row";
});
obj.parent("div").css("display","none");
}); // ready
var isDuplicateScrollEvent = 0;
$(window).scroll(function(){
var bottom = $(window).height() + $(window).scrollTop();
var height = $(document).height();
var percentage = Math.round(100*bottom/height);
var url = location.href;
url = url.replace(/^.*\/\/[^\/]+/,"");
if(percentage > 75)
{
if(isDuplicateScrollEvent == 0)
{
isDuplicateScrollEvent = 1;
_gaq.push(["_trackEvent","browser","scrolled 75%",url]);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment