Recording mouse movements and saving data in a database

Im kind of new to javascript and database processing.

Is there a way that every time users enter a page, mouse movements begin to be recorded, and as soon as the user leaves the page, all data (Coords x and y and time) are stored in the database for subsequent analysis?

I know that many sites do this, so there should be an easy way to do this.

An example would be nice, my database is MySql, my site is in Wordpress.

+4
source share
2 answers

unload ()

JavaScript:

document.onmousemove = function(e){
  var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
  console.log(pageCoords);
};

Demo

Unload javascript:

window.onunload=function(){
  //SomeJavaScriptCode
};

JQuery

var pageCoords = []; 
$(document).onmousemove = function(){
  pageCoords.push("( " + e.pageX + ", " + e.pageY + " )");//get page coordinates and storing in array
}
$( window ).unload(function() {
  //make ajax call to save coordinates array to database
});

UPDATED DEMO

+8
source

, - mysql db

(function() {
    window.onmousemove = handleMouseMove;
    function handleMouseMove(event) {
        event = event || window.event; // IE-ism
        // event.clientX and event.clientY contain the mouse position
    }
})();

:

( jQuery)?

:

Javascript -

, , . PHP, mysql.

, : http://www.coderslexicon.com/the-basics-of-passing-values-from-javascript-to-php-and-back/

, :

http://php.net/manual/en/mysqli.query.php

MySQL-. MySQLi, MySQL .

+1

All Articles