mongoDBで~以上、~以下

analytics.php

$date1 = date("Y-m-d H:i:s", strtotime("- 2 day"));
$date2 = date("Y-m-d H:i:s", strtotime("- 1 day"));
echo $date1 ."~".$date2 ."<br>";


$mng = new MongoDB\Driver\Manager("mongodb://localhost:27017");

$filter =  [
	'date' => [ '$gte' => $date1, '$lte' => $date2]
];
$options = [
  'projection' => ['_id' => 0],
  'sort' => ['_id' => -1],
];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $mng->executeQuery('app.na007', $query);

foreach ($cursor as $document) {
  // var_dump($document);
  $pv[] = $document->date;
  $cookie[] = $document->cookie;
  if(!is_null($document->referrer)){
  $referrer = $document->referrer;
  }
}
$uu = array_unique($cookie);
echo "<br>Users :".count($uu)."<br>";
echo "Pageviews :".count($pv)."<br>";
$bounce = (count($pv) - count($referrer))/ count($pv);
echo "Bounce rate :" .sprintf('%.2f',$bounce)."<br>";

Bounce rateは直帰率です。

Exitは離脱率なので、uniqueなsession / PVですね。やはり、sessionのIDは必要のようです。
twitterのsessionのjsonでいう、idあたりでしょうか。