Track Click on Elements

I once used the code below to track the clicks on elements on a page. If you know JavaScript, you may understand what it is about.

// Track every click within the page.

document.onclick = function(e) {

    e = e || window.event;

    el = e.target || e.srcElement;

if(el.tagName.toLowerCase() != ‘a’ || el.tagName.toLowerCase() != ‘input’) return true;

    var name = “”;

    var i = 0;

    while(el != document && i++ < 10 && el.tagName.toLowerCase() != "html") {         name = el.tagName.toLowerCase() + (el.id == "" ? "" : "@" + el.id) + (el.className == "" ? "" : "." + el.className) + "/" + name;         el = el.parentNode;     }   _uacct = "###########YOUR GOOGLE ANALYTICS CODE HERE############";   if(typeof(urchinTracker)=='function')     urchinTracker(name);   return true; }

Basically, it just record entries like below in your Google Analytics account.

html/body/.related/a

html/body/#header/div.navigation

Leave a Reply

Your email address will not be published. Required fields are marked *