document.onclick = function(event) {

    event = event || window.event;
    var target = event.target || event.srcElement,
        targetElement = target.tagName.toLowerCase();

    if (targetElement == "a") {
        var href = target.getAttribute("href"),
            urlHost = document.domain.replace(/^www\./i, "");
        var urlPattern = "^(?:https?:)?\/\/(?:(?:www)\.)?" + urlHost + "\/?";
        eventCheck(href, urlPattern);
    }

    function eventCheck(href, urlPattern) {
        if ((href.match(/^https?\:/i)) && (!href.match(urlPattern))) {
            if (href.match(/^.*\.(doc|eps|jpg|png|svg|xls|ppt|pdf|ashx|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/i)) {
                _gaq.push(['_trackEvent', 'Download', 'click', href]);
            } else {
                _gaq.push(['_trackEvent', 'External', 'click', href]);
            }
        } else if (href.match(/^mailto\:/i)) {
            _gaq.push(['_trackEvent', 'Email', 'click', href.substr(7)]);
        } else if (href.match(/^.*\.(doc|eps|jpg|png|svg|xls|ppt|pdf|ashx|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/i)) {
            _gaq.push(['_trackEvent', 'Download', 'click', href]);
        }
    }
};
