Skip to content

Instantly share code, notes, and snippets.

@hax hax/hi-bot.js
Created Jan 5, 2016

Embed
What would you like to do?
detect robot
void function () {
if (!window.tracker) {
return;
}
var events = ['scroll', 'click', 'mousemove', 'keydown', 'mousedown'];
for (var i = 0; i < events.length; i++) {
addHandler(document, events[i], detect);
}
function detect(event) {
for (var i = 0; i < events.length; i++) {
removeHandler(document, events[i], detect);
}
track(event)
}
function addHandler(element, type, handler) {
if (element.addEventListener) {
element.addEventListener(type, handler, false);
} else {
element.attachEvent('on' + type, handler)
}
}
function removeHandler(element, type, handler) {
if (element.removeEventListener) {
element.removeEventListener(type, handler);
} else {
element.detachEvent('on' + type, handler);
}
}
function track(event) {
var action = event.type;
tracker.evt('detect_robot', {human: '1', behavior: action});
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.