Measuring network time on a website

I would like to measure how much time a user spends on my site. This is necessary for the community site, where you can say: "User X spent 1397 minutes here."

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

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

I use PHP and MySQL if that matters.

I hope you help me. Thanks in advance!

+1
source share
7 answers

Two factors act against you -

  • You can collect time statistics by time (page views) and there is no reasonable way to determine what happened between these points,

  • Even then you will count the time of the browser window, not the time of the user; Users can easily open multiple tabs simultaneously in multiple browser instances.

I suspect your best approximation ascribes some average attention time per click, and then multiplies. But then you can accurately measure clicks.

+2
source

, , .... , "" , ? ?

+6

, ?: , , ..

-.

, - -, , , , ?

+2

, , , ajax X ( 60 ?), .

, , "" , . , .

+2

Google Analytics /, , - d ,

0

- iframe, - php. - ( ) . , , , . 3 .

. , , ipaddress.htm --.

iframe php. -/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);


?>
Hide result

javascript iframe -.:

<!-- 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>
Hide result

IFrame - :

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

:

<!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>
Hide result

You get the results page as follows:

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

0
source

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

You have google analitycs, piwik , and there are also advertising tools in JS that do just that.

-2
source

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


All Articles