Skip to content

Instantly share code, notes, and snippets.

@livingston
Created June 4, 2010 15:05
Show Gist options
  • Save livingston/425515 to your computer and use it in GitHub Desktop.
Save livingston/425515 to your computer and use it in GitHub Desktop.
XHR Monitor
/* XHR Monitor
*
* @author Livingston Samuel
* @copyright (c) 2010
*
* @browsers FF 3.6.3
*/
;(function (win, doc, XHR) {
var currentEvent = '',
beacon = (function () {
var img = doc.createElement('img');
return function (data) {
img.src = 'http://DOMAIN/PATH/beacon.php?' + data;
};
}());
XHR.prototype._send = XHR.prototype.send; //Reference to actual send method
XHR.prototype.send = function () {
beacon('element='+ encodeURIComponent(currentEvent) +'&data='+ encodeURIComponent(Array.prototype.join.call(arguments, ',')));
XHR.prototype._send.apply(this, arguments);
};
doc.addEventListener("DOMContentLoaded", function () {
doc.getElementsByTagName('body')[0].addEventListener('click', function (e) {
currentEvent = e.originalTarget.nodeName + '#' + e.originalTarget.id +'.'+ e.originalTarget.className;
}, true);
}, false);
}(window, document, XMLHttpRequest));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment