How to capture user interaction with a website?
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.
source to share
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®istered=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('');
}
source to share
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.
source to share
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.
source to share