1) Referrer URL, IP address, User Agent, screen size and other statistics . You can also get a geographic location, but it is more active.
2) Some data is available in the headers, so it is sent for each request - other data, such as screen size, is a little more complicated, so you want to make an ajax request to send it.
// Somewhere on your page(s) - here we use jQuery $(document).ready(function(){ // Check if they have been logged if ($.cookie('logged') == null ){ // Send screen size and whatever else that is not available from headers $.post('/logger', { width: screen.width, height: screen.height }, function(res) { // Set cookie for 30 days so we don't keep doing this $.cookie('logged', true, { expires: 30 }); }); } }); // Server side - example is an Express controller exports.logger = function(req, res) { var user = { agent: req.header('user-agent'(, // User Agent we get from headers referrer: req.header('referrer'), // Likewise for referrer ip: req.header('x-forwarded-for') || req.connection.remoteAddress, // Get IP - allow for proxy screen: { // Get screen info that we passed in url post data width: req.param('width'), height: req.param('height') } }; // Store the user in your database // User.create(user)... res.end(); }
cyberwombat
source share