django logging local javascript events
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"/>开发者_Python百科;
...
</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 actions) 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 the database.
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....
精彩评论