Created
September 17, 2013 09:23
-
-
Save io41/6592046 to your computer and use it in GitHub Desktop.
Track dom element clicks.
Tested on chrome.
This file contains 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
var getPath = function(el) { | |
var path = elName = ""; | |
var siblings, siblingId; | |
while(el && elName != "body") { | |
elName = el.nodeName.toLowerCase(); | |
siblings = (el.parentNode)?el.parentNode.childNodes:[]; | |
siblingId = 0; | |
for (var i = 0; i < siblings.length; i++) { | |
if (siblings[i] == el) { | |
break; | |
} else if (siblings[i].nodeName.toLowerCase() == elName) { | |
siblingId++; | |
} | |
} | |
path = elName + ":eq(" + siblingId + ")" + ((path)?' > ' + path:''); | |
el = el.parentNode; | |
} | |
return path; | |
}; | |
dojo.query(document).onclick(function(e){window.__clicks = window.__clicks || []; window.__clicks.push(getPath(e.target));}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment