记录用户操作和页面查看的最有效方法是什么?

时间:2021-11-04 06:40:31

I've created a website where users will be able to add entries, associate rows in different tables and so on. I need to track what actions users are doing for a score table.

我创建了一个网站,用户可以在其中添加条目,在不同的表中关联行等等。我需要跟踪用户为分数表执行的操作。

I also need to keep track on page views.

我还需要跟踪页面浏览量。

I'm trying to figure out what is the most efficient way for tracking / logging this.

我想弄清楚跟踪/记录这个的最有效方法是什么。

Is it best to:

最好是:

  • create a new DB and add records here?
  • 创建一个新数据库并在此处添加记录?

  • Add records on same DB as website?
  • 在与网站相同的数据库中添加记录?

  • Use javascript to send parameters by URL to a logging server?
  • 使用javascript通过URL将参数发送到日志记录服务器?

Any other methods that is good?

还有其他什么方法好吗?

I don't know how many users I will have on my website when I launch this, but hopefully I will have a bit of trafic.

我不知道在我推出这个网站时我的网站会有多少用户,但希望我会有一些交通。

4 个解决方案

#1


1  

You can make DB table with rows:

您可以使用行创建DB表:

  • Date and time
  • 日期和时间

  • IP address
  • Current URL
  • Referrer URL
  • Serialized $_GET
  • Serialized $_POST
  • Serialized $_COOKIE

It's very useful if you want track your traffic.

如果您想要跟踪流量,这非常有用。

Pseudocode:

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

Use same DB, so you will have less connections to mysql server.

使用相同的DB,因此与mysql服务器的连接较少。

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

在PHP脚本中执行它(在mysql_connect之后是非常好的主意),我相信每次访问一次INSERT对您的机器来说不是一个很大的挑战。

#2


0  

I wouldn't use Javascript if you want reliable results as users may have that disabled or may try and manipulate it to cheat somehow.

如果您想要可靠的结果我不会使用Javascript,因为用户可能已禁用或可能尝试操纵它以某种方式作弊。

Ideally I would use a separate schema as that will scale the best (you may in the future want to split that schema off onto a separate server for processing) although it will make it hard to join data between the two schemas. You could start with a new table in the same schema (as long as your code is nicely encapsulated you could always break the logging out into a separate table at a later date).

理想情况下,我会使用一个单独的模式,因为它将扩展最佳(您可能在将来希望将该模式拆分到一个单独的服务器上进行处理),尽管这将使得很难在两个模式之间连接数据。您可以从同一模式中的新表开始(只要您的代码被很好地封装起来,您可以随时在以后的日志中破坏登录)。

#3


0  

I advise looking for a solution that is asynchronous (to minimize the performance impact for end users) and integrated with an overall visitor data solution (so that reporting on various metrics can be combined). For example, Google Analytics offers Event Tracking so that you can add to its standard metrics on visitors, page views etc, arbitrary user-action data like those you describe.

我建议寻找异步的解决方案(以最小化对最终用户的性能影响)并与整体访问者数据解决方案集成(以便可以组合各种指标的报告)。例如,Google Analytics(分析)会提供事件跟踪功能,以便您可以在访问者,网页浏览量等上添加标准指标,以及您描述的任意用户操作数据。

#4


0  

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

您是否考虑过使用HTML5 webstorage:http://www.w3schools.com/html5/html5_webstorage.asp

you could use javascripts sessionstorage object(data is stored in key/value pairs) to store all the page activities as properties of this object, then POST this information alongwith the logout action to the backend script which in turn maintains the corresponding database entries, I believe this way you can avoid uneccessary http requests with all the overheads, by sending the page activity information in one final request.

您可以使用javascripts sessionstorage对象(数据存储在键/值对中)将所有页面活动存储为此对象的属性,然后将此信息与注销操作一起POST到后端脚本,后端脚本又维护相应的数据库条目,I相信这样,您可以通过在一个最终请求中发送页面活动信息来避免所有开销的不必要的http请求。

you should re-initialize the object on every user login.

你应该在每次用户登录时重新初始化对象。

#1


1  

You can make DB table with rows:

您可以使用行创建DB表:

  • Date and time
  • 日期和时间

  • IP address
  • Current URL
  • Referrer URL
  • Serialized $_GET
  • Serialized $_POST
  • Serialized $_COOKIE

It's very useful if you want track your traffic.

如果您想要跟踪流量,这非常有用。

Pseudocode:

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

Use same DB, so you will have less connections to mysql server.

使用相同的DB,因此与mysql服务器的连接较少。

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

在PHP脚本中执行它(在mysql_connect之后是非常好的主意),我相信每次访问一次INSERT对您的机器来说不是一个很大的挑战。

#2


0  

I wouldn't use Javascript if you want reliable results as users may have that disabled or may try and manipulate it to cheat somehow.

如果您想要可靠的结果我不会使用Javascript,因为用户可能已禁用或可能尝试操纵它以某种方式作弊。

Ideally I would use a separate schema as that will scale the best (you may in the future want to split that schema off onto a separate server for processing) although it will make it hard to join data between the two schemas. You could start with a new table in the same schema (as long as your code is nicely encapsulated you could always break the logging out into a separate table at a later date).

理想情况下,我会使用一个单独的模式,因为它将扩展最佳(您可能在将来希望将该模式拆分到一个单独的服务器上进行处理),尽管这将使得很难在两个模式之间连接数据。您可以从同一模式中的新表开始(只要您的代码被很好地封装起来,您可以随时在以后的日志中破坏登录)。

#3


0  

I advise looking for a solution that is asynchronous (to minimize the performance impact for end users) and integrated with an overall visitor data solution (so that reporting on various metrics can be combined). For example, Google Analytics offers Event Tracking so that you can add to its standard metrics on visitors, page views etc, arbitrary user-action data like those you describe.

我建议寻找异步的解决方案(以最小化对最终用户的性能影响)并与整体访问者数据解决方案集成(以便可以组合各种指标的报告)。例如,Google Analytics(分析)会提供事件跟踪功能,以便您可以在访问者,网页浏览量等上添加标准指标,以及您描述的任意用户操作数据。

#4


0  

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

您是否考虑过使用HTML5 webstorage:http://www.w3schools.com/html5/html5_webstorage.asp

you could use javascripts sessionstorage object(data is stored in key/value pairs) to store all the page activities as properties of this object, then POST this information alongwith the logout action to the backend script which in turn maintains the corresponding database entries, I believe this way you can avoid uneccessary http requests with all the overheads, by sending the page activity information in one final request.

您可以使用javascripts sessionstorage对象(数据存储在键/值对中)将所有页面活动存储为此对象的属性,然后将此信息与注销操作一起POST到后端脚本,后端脚本又维护相应的数据库条目,I相信这样,您可以通过在一个最终请求中发送页面活动信息来避免所有开销的不必要的http请求。

you should re-initialize the object on every user login.

你应该在每次用户登录时重新初始化对象。