django logging local javascript events

By : Hulk


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

The contents of this page are

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

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................


By : Hulk

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 :


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