Last active
December 18, 2015 00:29
-
-
Save firedfox/5696733 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (function() { | |
| var MY_DOMAINS = ['image.baidu.com', 'tu.baidu.com']; | |
| var on = function(elem, event, handler) { | |
| if (elem.addEventListener) { | |
| elem.addEventListener(event, handler, false); | |
| } else if (elem.attachEvent) { | |
| elem.attachEvent('on' + event, handler); | |
| } | |
| }; | |
| var getHost = function(url) { | |
| var match = url.match(/^(https?:\/\/)?([^\/\?#]*)/); | |
| return match ? match[2].replace(/.*@/, '') : null; | |
| }; | |
| var getAncestorByTag = function(element, tagName) { | |
| tagName = tagName.toUpperCase(); | |
| while ((element = element.parentNode) && element.nodeType == 1) { | |
| if (element.tagName == tagName) { | |
| return element; | |
| } | |
| } | |
| return null; | |
| }; | |
| window._hmt = window._hmt || []; | |
| on(document, 'mousedown', function(e) { | |
| e = e || window.event; | |
| var target = e.target || e.srcElement; | |
| var a = (target.tagName == 'A' ? target : getAncestorByTag(target, 'a')); | |
| if (!a) { return; } | |
| var domain = getHost(a.href); | |
| for (var j = MY_DOMAINS.length - 1; j >= 0; j--) { | |
| var idx = domain.indexOf(MY_DOMAINS[j]); | |
| if (idx > -1 && idx + MY_DOMAINS[j].length == domain.length) { return; } | |
| } | |
| _hmt.push(['_trackEvent', 'OutboundLink', 'click', domain]); | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment