What is the most effective way to register user actions and view pages?

I created a website where users can add records, link rows in different tables, etc. I need to keep track of what actions users are doing for the score table.

I also need to track pageviews.

I am trying to figure out what is the most efficient way to track / register this.

Is it better:

  • create a new database and add entries here?
  • Add records to the same database as the website?
  • Use javascript to send parameters by URL to the registration server?

Any other methods that are good?

I don’t know how many users I will have on my website when I launched it, but hopefully I will have some traffic.

+4
source share
4 answers

You can create a database table with the lines:

  • date and time
  • IP address
  • Current url
  • Referrer URL
  • Serialized $ _GET
  • Serialized $ _POST
  • Serialized $ _COOKIE

This is very useful if you want to track traffic.

pseudo code:

if(!$bot) { $visit = Array( 'date' => date("Ymd H:i:s"), 'ip' => $_SERVER['REMOTE_ADDR'], etc ... ); $sql = "INSERT INTO visits (`".join("`,`",array_keys($visit)."`) VALUES ('".join("','",array_values($visit)."')"; ... } 

Use the same database, so you will have fewer connections to the mysql server.

Do it in a PHP script (after mysql_connect good idea), I believe that one INSERT per visit is not a big problem for your machine.

+1
source

I would not use Javascript if you want to get reliable results, since users may be disabled or may try to manipulate it in order to somehow cheat.

Ideally, I would use a separate scheme that will scale in the best way (in the future you can split this scheme into a separate server for processing), although this will make it difficult to combine data between the two schemes. You can start with a new table in the same scheme (provided that your code is well encapsulated, you can disable it at any time in a separate table).

0
source

I recommend looking for a solution that is asynchronous (to minimize the impact of performance for end users) and integrated with a common solution for processing visitors (so that reporting can be combined across different metrics). For example, Google Analytics offers event tracking so that you can add to your standard metrics visitors, pageviews, etc., Custom activity custom data such as you describe.

0
source

Have you considered using the HTML5 website: http://www.w3schools.com/html5/html5_webstorage.asp

you can use javascripts sessionstorage object (data is stored in key / value pairs) to store all actions with pages as properties of this object, then POST this information along with the exit action to the script backend, which, in turn, supports the corresponding records in the database , I believe that you can avoid unnecessary HTTP requests with all the overhead by sending information about the activity of the page in one final request.

you must reinitialize the object each time a user logs in.

0
source

Source: https://habr.com/ru/post/1379356/


All Articles