User Activity Tracking or Logging with javascript

2019-01-21 17:52发布

Is it possible to track every action of a user on a webpage and creating log of it? The idea is to transfer log of user actions to server via AJAX and saving it. On each event for each element I can write code/logic to write some log in console, but I was wondering if there is any library/shortcut available which can log all actions on webpage at client side including events and actions such as copy, paste, click, double click, selection etc. with their element reference.

3条回答
相关推荐>>
2楼-- · 2019-01-21 18:26

You can use ready-made solutions:

You can do amazing stuff with Google Analytics and its Event Tracker:

If you're looking for a custom-made solution, you can try the following one with PHP and JavaScript:

Keep in mind that using third-party solutions is better performance-wise. Writing the coordinates of the mouse movements in a database in real time, needs a lot of resources.

查看更多
爷、活的狠高调
3楼-- · 2019-01-21 18:37

I don't think that this kind of javascript library exist, you could easily build one with jquery, just listen to all the event (blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error)

and than send them to the server side using web sockets

查看更多
地球回转人心会变
4楼-- · 2019-01-21 18:42

Have you look at Google Analytic Event Tracking?

You need to embed the tracking function within your javascript but it is very convenience to use.

// Google API
_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)

// Example
_trackEvent('checkout' 'remove-item' 'poodle skirt')

Update: 2017 New Analytics Api

// Api
ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);

// Example remove product id#27
ga('send', 'event', 'ecart', 'remove-item', 'poodle skirt', 27);
   // OR
ga('send', {
      hitType: 'event',
      eventCategory: 'ecart',
      eventAction: 'remove-item',
      eventLabel: 'poodle skirt'
   }); 
查看更多
登录 后发表回答