How to capture user interaction with a website?

How can I capture user interaction on a website? How many links the user has clicked. Where the user came from. I want to create my own logic. I don't want to use any statistics tool. How can i do this?

Thank you in advance

+2


source to share


7 replies


The place where the user comes from can get the referrer (document.referrer).
And if you have some sort of session or user mark (via cookies) than you can check which links will be clicked by capturing the onclick event. But don't put onclick on every link, just use the event capture technique. In jQuery, this would be:

$('a') 
    .livequery('click', function(event) { 
        alert('clicked'); 
        return false; 
    }); 

      



If you want to capture which link was clicked when you leave - you have to place an onunload event that will send the click data to your server.

+2


source


There are two ways that I know:

  • make a service and call it with a GET method for each event you want to track.
    it's something like this:

    service.php?event=pageview&time=127862936&userId=70&registered=true
    
          

    this way your service can work with data.

  • The second way I know, which I myself use, is causing some dummy image on my server by associating a GET request with it and then parsing the image request from the server side. every request is processed and logged, then I generate reports.

again, you need to know what events you want to capture, they are predefined and they need to catch and send them as they occur. you can put 1 script js file, but this script should add event listeners. let's say you want to know when the user left the page. add an event listener to the onbeforeunload event like:



window.onbeforeunload = function(){
   sendStats({event:'onbeforeunload'});
}

      

then the sendStats function splits the JSON and builds the request to send to the server like this:

function sendStats(statsJSON){
    var url = [];
    for (var key in statsJSON) {
        // make sure that the key is an actual property of an object, and doesn't come from the prototype
        if( statsJSON.hasOwnProperty(key) ){  
            var sign = (!url[0]) ? '?' : '&';
            url.push(sign);
            url.push(key + '=');
            url.push( encodeURI(statsJSON[key]) );
        }
    }
    var time = new Date().getTime();
    url.push('&time=');
    url.push(time);

    var stat = new Image();
    stat.src = clientHost + 'stats.gif' + url.join('');
}

      

+1


source


Start with web server log files, copy to format, try simple statistics. Then you can read the code of statistical tools like awstats to improve your vision.

0


source


I am an asp.net developer. But I think this technique will work all the time. If you want to know where the user came from to your site, you can use some kind of request tracking variable www.mysite.com?IMFrom=something. Thus, you publish your link on some third party website, for example. let's say google. Submit the link as www.mysite.com?google=traficfromgoogle. Perhaps you have trafic from another otherwebsite. There is a variable for every variable. You can also use some kind of unique identifier for the whole website that trafic sends you. Now create a tracker function that will track this querystring variable. Use this function as it gets called during each request. And now you can put some custom logic for each request,having such a request.

0


source


I don't think you will need to capture this as it is most likely already captured in the webserver logs by the webserver itself. You just need to find software that can analyze the logs and give you nice metrics. There are many packages out there for this.

0


source


I know it doesn't generate your own logic, but if you decide you don't want to parse your server logs, you can try a new service that tries to figure out google analytics: http://mixpanel.com/ . This is real time analysis and they have a free limited account so you can try it before upgrading.

I haven't tried their api yet, but my guess is that you can let them collect data from your site and do funny things with it after you let it go.

0


source


Use Google Analytics and connect site elements using your API.

0


source







All Articles