测量网站在线时间

发布于 2024-08-12 09:27:31 字数 309 浏览 11 评论 0原文

我想衡量用户在我的网站上花费了多少时间。社区网站需要它,您可以在其中说:“用户 X 已在此处花费了 1397 分钟。”

在阅读了一些有关这方面的文档后,我知道没有完美的方法来实现这一目标。你无法测量准确的时间。但我正在寻找一种能够提供良好近似值的方法。

你怎么能这么做?我的想法: 1) 每次页面浏览的在线时间计数器增加 30 秒。 2) 在每个页面视图上,保存当前时间戳。在下一个视图中,将保存的时间戳和当前时间戳之间的差异添加到在线时间计数器中​​。

如果这确实重要的话,我会使用 PHP 和 MySQL。

我希望你能帮助我。提前致谢!

I would like to measure how much time a user spends on my website. It's needed for a community site where you can say: "User X has been spending 1397 minutes here."

After reading some documents about this, I know that there is no perfect way to achieve this. You can't measure the exact time. But I'm looking for an approach which gives a good approximation.

How could you do this? My ideas:
1) Adding 30 seconds to the online time counter on every page view.
2) On every page view, save the current timestamp. On the next view, add the difference between the saved timestamp and the current timestamp to the online time counter.

I use PHP and MySQL if this does matter.

I hope you can help me. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

时间你老了 2024-08-19 09:27:31

这可能毫无意义......如果用户打开了三个选项卡并且在实际操作其他两个选项卡时“访问”您的网站怎么办?你想数一下吗?

This is probably pointless.... what if the user has three tabs open and is "visiting" your site while actually working on the other two tabs? Do you want to count that?

清晨说晚安 2024-08-19 09:27:31

有两个因素对您不利 -

  1. 您只能收集时间点统计信息(页面浏览量),并且没有合理的方法来检测这些点之间发生的情况;

  2. 即便如此,您计算的还是浏览器窗口时间,而不是用户时间;用户可以轻松地同时在多个浏览器实例上打开多个选项卡。

我怀疑你最好的近似是分配每次点击的平均注意力时间,然后相乘。但你也可以衡量点击次数。

Two factors are working against you -

  1. You can only collect point-in-time statistics (page views), and there's no reasonable way to detect what happened between those points;

  2. Even then, you'd be counting browser window time, not user time; users can easily have multiple tabs open on multiple browser instances simultaneously.

I suspect your best approximation is attributing some average amount of attention time per click and then multiplying. But then you might just as well measure clicks.

兮颜 2024-08-19 09:27:31

为什么不直接衡量实际可以衡量的内容呢?:推荐、页面浏览量、点击率等。

收集和宣传这些类型的数字完全符合网络衡量标准的其他方面。

此外,如果有人打开一个网页,然后,比如说,去度两周的假期,那么如何最好地解释它呢?

Why not just measure what actually can be measured?: referrals, page views, click-throughs, etc.

Collecting and advertising these kinds of numbers is completely in line with the rest of the world of web metrics.

Besides—if someone were to bring up a web page and then, say, go on a two week holiday, how best to account for it?

嘿嘿嘿 2024-08-19 09:27:31

您可以做的是检查用户是否在页面上处于活动状态,然后每隔 X 秒(60 秒可以吗?)向您的服务器发送一个 ajax 请求,以确定用户是否在页面上处于活动状态。

然后,您可以使用您提到的第二种方法来计算两个“活动”时间戳之间的时间差,这些时间戳之间的时间间隔不超过一两个间隔。添加这些将给出用户在您网站上花费的时间。

What you could do is check if a user is active on the page and then send an ajax request to your server every X seconds (would 60 secs be fine?) that a user is active or not on the page.

Then you can use the second method you have mentioned to calculate the time difference between two 'active' timestamps that are not separated by more than one or two intervals. Adding these would give the time spent by the user on your site.

梦情居士 2024-08-19 09:27:31

Google Analytics(分析)包含一个非常强大的事件记录/跟踪机制,您可以可以定制并利用以获得对用户行为的真正良好的测量 - 我会研究一下

google analytics includes a very powerful event logging/tracking mechanism you can customize and tap into get really good measurements of user behavior - I'd look into that

勿忘心安 2024-08-19 09:27:31

一个非常简单的解决方案是使用隐藏的 iframe 定期加载 php 网页。加载的网页记录开始时间(如果不存在)和停止时间。当此人离开页面时,您会看到此人第一次访问该网站的时间以及他们最后一次访问该网站的时间。在本例中,时间戳每 3 秒更新一次。

我使用文件来保存日志信息。我使用的文件名由月-日-年 ipaddress.htm

示例 iframe php 代码组成。将其放入 yourwebsite/yourAnalyticsiFrameCode.php 中:

<?php
  // get the IP address of the sender
  $clientIpAddress=$_SERVER['REMOTE_ADDR'];
  $folder = "yourAnalyticsDataFolder";
  // Combine the IP address with the current date.
  $clientFileRecord=$folder."/".date('d-M-Y')."  ".$clientIpAddress;

  $startTimeDate = "";

  // check to see if the folder to store analytics exists
  if (!file_exists($folder))
  {
    if (!mkdir($folder))
      return;  // error - just bail

  }


  if (file_exists($clientFileRecord) )
  {
    //read the contents of the clientFileRedord
    $lines = file($clientFileRecord);

    $count = 0;

    // Loop through our array, show HTML source as HTML source; and line numbers too.
    foreach ($lines as $line_num => $line)
    {
      echo($line);
      if ($count == 0)
        $startTimeDate = rtrim( $line );
      $count++;

    }
  }

  if ($startTimeDate == "")
    $startTimeDate = date('H:i:s d-M-Y');

  $endTimeDate = date('H:i:s d-M-Y');

  // write the start and stop times back out to the file
  $file = fopen($clientFileRecord,"w");
  fwrite($file,$startTimeDate."\n".$endTimeDate);
  fclose($file);


?>

定期重新加载主网页中的 iframe 的 javascript:

<!-- Javascript to reload the analytics code -->
<script>
  window.setInterval("reloadIFrame();", 3000);

  function reloadIFrame() {
    document.getElementById('AnalyticsID').src = document.getElementById('AnalyticsID').src
      //          document.frames["AnalyticsID"].location.reload();
  }
</script>

主网页中的 iframe 如下所示:

<iframe id="AnalyticsID" name="AnalyticsID" src="http://yourwebsite/yourAnalyticsiFrameCode.php" width="1"
height="1" frameborder="0" style="visibility:hidden;display:none">
</iframe>

显示时间戳文件的一种非常简单的方法:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <title></title>
</head>

<body>
Analytics results
<br>
<?php
  $folder = "yourAnalyticsDataFolder";
  $files1 = scandir($folder);
  // Loop through the files
  foreach ($files1 as $fn)
  {
    echo ($fn."<br>\n");
    $lines = file($folder."/".$fn);
    foreach ($lines as $line_num => $line)
    {
      echo("  ".$line."<br>\n");
    }
    echo ("<br>\n <br>");

  }

?>
</body>

</html>

您会得到如下结果页面:

22-Mar-2015 104.37.100.30

18:09:03 22-Mar-2015

19:18:53 22-Mar-2015

22-Mar-2015 142.162.20.133

18:10 :06 2015年3月22日

18:10:21 2015年3月22日

A very simple solution is to use a hidden iframe that loads a php web page periodically. The loaded web page logs the start time (if it doesn't exist) and the stop time. When the person leaves the page you are left with the time the person first came to the site and the last time they were there. In this case, the timestamp is updated every 3 seconds.

I use files to hold the log information. The filename I use consists of month-day-year ipaddress.htm

Example iframe php code. Put this in yourwebsite/yourAnalyticsiFrameCode.php:

<?php
  // get the IP address of the sender
  $clientIpAddress=$_SERVER['REMOTE_ADDR'];
  $folder = "yourAnalyticsDataFolder";
  // Combine the IP address with the current date.
  $clientFileRecord=$folder."/".date('d-M-Y')."  ".$clientIpAddress;

  $startTimeDate = "";

  // check to see if the folder to store analytics exists
  if (!file_exists($folder))
  {
    if (!mkdir($folder))
      return;  // error - just bail

  }


  if (file_exists($clientFileRecord) )
  {
    //read the contents of the clientFileRedord
    $lines = file($clientFileRecord);

    $count = 0;

    // Loop through our array, show HTML source as HTML source; and line numbers too.
    foreach ($lines as $line_num => $line)
    {
      echo($line);
      if ($count == 0)
        $startTimeDate = rtrim( $line );
      $count++;

    }
  }

  if ($startTimeDate == "")
    $startTimeDate = date('H:i:s d-M-Y');

  $endTimeDate = date('H:i:s d-M-Y');

  // write the start and stop times back out to the file
  $file = fopen($clientFileRecord,"w");
  fwrite($file,$startTimeDate."\n".$endTimeDate);
  fclose($file);


?>

The javascript to periodically reload the iframe in the main web page.:

<!-- Javascript to reload the analytics code -->
<script>
  window.setInterval("reloadIFrame();", 3000);

  function reloadIFrame() {
    document.getElementById('AnalyticsID').src = document.getElementById('AnalyticsID').src
      //          document.frames["AnalyticsID"].location.reload();
  }
</script>

The iframe in the main web page looks like this:

<iframe id="AnalyticsID" name="AnalyticsID" src="http://yourwebsite/yourAnalyticsiFrameCode.php" width="1"
height="1" frameborder="0" style="visibility:hidden;display:none">
</iframe>

A very simple way to display the time stamp files:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <title></title>
</head>

<body>
Analytics results
<br>
<?php
  $folder = "yourAnalyticsDataFolder";
  $files1 = scandir($folder);
  // Loop through the files
  foreach ($files1 as $fn)
  {
    echo ($fn."<br>\n");
    $lines = file($folder."/".$fn);
    foreach ($lines as $line_num => $line)
    {
      echo("  ".$line."<br>\n");
    }
    echo ("<br>\n <br>");

  }

?>
</body>

</html>

You get a results page like this:

22-Mar-2015 104.37.100.30

18:09:03 22-Mar-2015

19:18:53 22-Mar-2015

22-Mar-2015 142.162.20.133

18:10:06 22-Mar-2015

18:10:21 22-Mar-2015

往日情怀 2024-08-19 09:27:31

我认为客户端 JavaScript 分析就是这个问题的解决方案。

你有 google analitycs,piwik,还有 JS 中的商业工具也能做到这一点。

I think client side JavaScript analytics is the solution for this.

You have the google analitycs, piwik, and there also commercials tools in JS that do exactly that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文