django logging local javascript events

By : Hulk
Source: Stackoverflow.com
Question!

All..

Say there exists a template x.html in Django templates section.

The contents of this page are

<html>
<a href="#" onclick="noserverrequest">
<input type="button onclick="noserverrequest"/>
..............
</html>

I have n number of buttons and hyperlinks as said above in a page.

My question is how to record all the clicks that are done in this page(local javascript sctions) and when one server request is made to django i have to record all the links that are clicked in this page.How is this achieved.

I can use a hidden variable to record all the hyperlinks or button actions.But how to send it to server......Please indicate me how this is achieved.On django side when the request is found i write the javascript events to database................

Thanks..........

By : Hulk


Answers
you should better trigger an image load in javascript :

function log(info) {
  document.getElementById('pixel').src = '/tracker?'+info;
}

somewhere on your page :

<img id='pixel' src='pixel.gif' style='display:none'/>

then call it this way in javascript :

log('clicked_Button_BuyStuff');

server side, you could have a django view then records all the data, including date, user, referer....

By : jujule


This video can help you solving your question :)
By: admin