stats: pages, browsers, platforms and references
This commit is contained in:
parent
155d431ccf
commit
9659a4197c
72
stats.php
72
stats.php
|
@ -13,7 +13,7 @@ if (!empty($_GET['for'])) {
|
|||
// TODO - for now all stats are de-facto public, this should not be true
|
||||
|
||||
$labels = $visits = $uniques = [];
|
||||
for ($d=14; $d>0; $d--) {
|
||||
for ($d=14; $d>=0; $d--) {
|
||||
$labels[date('Y-m-d', strtotime('-'.$d.'days'))] = date('Dd', strtotime('-'.$d.'days'));
|
||||
$visits[date('Y-m-d', strtotime('-'.$d.'days'))] = 0;
|
||||
$uniques[date('Y-m-d', strtotime('-'.$d.'days'))] = 0;
|
||||
|
@ -35,6 +35,29 @@ GROUP BY date', [':site_id'=>$site['id'], ':date_min'=>date('Y-m-d', strtotime('
|
|||
$uniques[$stat['date']] = (int) $stat['visits'];
|
||||
}
|
||||
|
||||
$totalVisits = $pdo->run('SELECT COUNT(*) FROM visits WHERE site_id=?', [$site['id']])->fetchColumn();
|
||||
$byPaths = $pdo->run('SELECT path, COUNT(*) as visits
|
||||
FROM visits
|
||||
WHERE site_id=?
|
||||
GROUP BY path
|
||||
ORDER BY visits DESC', [$site['id']])->fetchAll();
|
||||
$byBrowsers = $pdo->run('SELECT browser, COUNT(*) as visits
|
||||
FROM visits
|
||||
WHERE site_id=?
|
||||
GROUP BY browser
|
||||
ORDER BY visits DESC', [$site['id']])->fetchAll();
|
||||
$byPlatforms = $pdo->run('SELECT platform, COUNT(*) as visits
|
||||
FROM visits
|
||||
WHERE site_id=?
|
||||
GROUP BY platform
|
||||
ORDER BY visits DESC', [$site['id']])->fetchAll();
|
||||
$byRefs = $pdo->run('SELECT ref, COUNT(*) as visits
|
||||
FROM visits
|
||||
WHERE site_id=? AND ref!=""
|
||||
GROUP BY ref
|
||||
ORDER BY visits DESC', [$site['id']])->fetchAll();
|
||||
|
||||
|
||||
} else {
|
||||
$sites = $pdo->run('SELECT host, label, COUNT(*) AS visits, stats_public
|
||||
FROM visits
|
||||
|
@ -58,6 +81,10 @@ ORDER BY visits DESC');
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/yegor256/tacit@gh-pages/tacit-css-1.5.1.min.css"/>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.js"></script>
|
||||
<style>
|
||||
.progress { display: block; width: 100%; height: 5px; background-color: lightgrey; }
|
||||
.progress > div { background-color: green; height: 5px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<section>
|
||||
|
@ -114,7 +141,44 @@ ORDER BY visits DESC');
|
|||
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
<?php
|
||||
if (count($byPaths)) {
|
||||
echo '<h2>Top visited pages</h2>';
|
||||
foreach ($byPaths as $page) {
|
||||
echo '<div><a href="//' . $site['host'] . $page['path'] . '">'.$page['path'].'</a>';
|
||||
echo ' ' . pct($page['visits'], $totalVisits) . '%<div class="progress"><div style="width: '.pct($page['visits'], $totalVisits).'%"></div></div>';
|
||||
}
|
||||
}
|
||||
|
||||
if (count($byBrowsers)) {
|
||||
echo '<h2>Top browsers</h2>';
|
||||
foreach ($byBrowsers as $page) {
|
||||
echo '<div>'.$page['browser'].'';
|
||||
echo ' ' . pct($page['visits'], $totalVisits) . '%<div class="progress"><div style="width: '.pct($page['visits'], $totalVisits).'%"></div></div>';
|
||||
}
|
||||
}
|
||||
|
||||
if (count($byPlatforms)) {
|
||||
echo '<h2>Top platforms</h2>';
|
||||
foreach ($byPlatforms as $page) {
|
||||
echo '<div>'.$page['platform'];
|
||||
echo ' ' . pct($page['visits'], $totalVisits) . '%<div class="progress"><div style="width: '.pct($page['visits'], $totalVisits).'%"></div></div>';
|
||||
}
|
||||
}
|
||||
|
||||
if (count($byRefs)) {
|
||||
echo '<h2>Top references</h2>';
|
||||
foreach ($byRefs as $page) {
|
||||
echo '<div>'.$page['ref'];
|
||||
echo ' ' . pct($page['visits'], $totalVisits) . '%<div class="progress"><div style="width: '.pct($page['visits'], $totalVisits).'%"></div></div>';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
} else {
|
||||
echo '<table><tr><th>Site</th><th>domain</th><th>#visits</th></tr>';
|
||||
|
@ -129,6 +193,7 @@ ORDER BY visits DESC');
|
|||
}
|
||||
?>
|
||||
</section>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
|
@ -155,4 +220,9 @@ class MyPDO extends PDO
|
|||
$stmt->execute($args);
|
||||
return $stmt;
|
||||
}
|
||||
}
|
||||
|
||||
function pct($of, $total){
|
||||
$p1 = $total / 100;
|
||||
return round($of / $p1);
|
||||
}
|
Loading…
Reference in New Issue