Browse Source

We can display stats per day.

master
severak 1 year ago
parent
commit
91f9f93d19
  1. 87
      stats.php

87
stats.php

@ -21,56 +21,92 @@ if (!empty($_GET['for'])) {
if ($site) {
$labels = $visits = $uniques = [];
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;
}
if (!empty($_GET['date'])) {
$visits = false;
$totalVisits = $pdo->run('SELECT COUNT(*) FROM visits WHERE site_id=? AND date(ts, "unixepoch")=?', [$site['id'], $_GET['date']])->fetchColumn();
$byPaths = $pdo->run('SELECT path, COUNT(*) as visits
FROM visits
WHERE site_id=? AND date(ts, "unixepoch")=?
GROUP BY path
ORDER BY visits DESC LIMIT 10', [$site['id'], $_GET['date']])->fetchAll();
$byBrowsers = $pdo->run('SELECT browser, COUNT(*) as visits
FROM visits
WHERE site_id=? AND is_bot=0 AND date(ts, "unixepoch")=?
GROUP BY browser
ORDER BY visits DESC', [$site['id'], $_GET['date']])->fetchAll();
$byPlatforms = $pdo->run('SELECT platform, COUNT(*) as visits
FROM visits
WHERE site_id=? AND is_bot=0 AND date(ts, "unixepoch")=?
GROUP BY platform
ORDER BY visits DESC', [$site['id'], $_GET['date']])->fetchAll();
$byRefs = $pdo->run('SELECT ref, COUNT(*) as visits
FROM visits
WHERE site_id=? AND ref!="" AND date(ts, "unixepoch")=?
GROUP BY ref
ORDER BY visits DESC', [$site['id'], $_GET['date']])->fetchAll();
$last14days = $pdo->run('SELECT date(datetime(ts, \'unixepoch\')) as date, COUNT(*) as visits
$byBots = $pdo->run('SELECT browser, COUNT(*) as visits
FROM visits
WHERE site_id=? AND is_bot=1 AND date(ts, "unixepoch")=?
GROUP BY browser
ORDER BY visits DESC', [$site['id'], $_GET['date']])->fetchAll();
} else {
$labels = $visits = $uniques = [];
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;
}
$last14days = $pdo->run('SELECT date(datetime(ts, \'unixepoch\')) as date, COUNT(*) as visits
FROM visits
WHERE site_id=:site_id AND date>=:date_min AND date<=:date_max
GROUP BY date', [':site_id'=>$site['id'], ':date_min'=>date('Y-m-d', strtotime('-14 days')), ':date_max'=>date('Y-m-d')]);
foreach ($last14days as $stat) {
$visits[$stat['date']] = (int) $stat['visits'];
}
foreach ($last14days as $stat) {
$visits[$stat['date']] = (int) $stat['visits'];
}
$last14daysUniq = $pdo->run('SELECT date(datetime(ts, \'unixepoch\')) as date, COUNT(*) as visits
$last14daysUniq = $pdo->run('SELECT date(datetime(ts, \'unixepoch\')) as date, COUNT(*) as visits
FROM visits
WHERE site_id=:site_id AND is_unique=1 AND date>=:date_min AND date<=:date_max
GROUP BY date', [':site_id'=>$site['id'], ':date_min'=>date('Y-m-d', strtotime('-14 days')), ':date_max'=>date('Y-m-d')]);
foreach ($last14daysUniq as $stat) {
$uniques[$stat['date']] = (int) $stat['visits'];
}
foreach ($last14daysUniq as $stat) {
$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
$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 LIMIT 10', [$site['id']])->fetchAll();
$byBrowsers = $pdo->run('SELECT browser, COUNT(*) as visits
$byBrowsers = $pdo->run('SELECT browser, COUNT(*) as visits
FROM visits
WHERE site_id=? AND is_bot=0
GROUP BY browser
ORDER BY visits DESC', [$site['id']])->fetchAll();
$byPlatforms = $pdo->run('SELECT platform, COUNT(*) as visits
$byPlatforms = $pdo->run('SELECT platform, COUNT(*) as visits
FROM visits
WHERE site_id=? AND is_bot=0
GROUP BY platform
ORDER BY visits DESC', [$site['id']])->fetchAll();
$byRefs = $pdo->run('SELECT ref, COUNT(*) as visits
$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();
$byBots = $pdo->run('SELECT browser, COUNT(*) as visits
$byBots = $pdo->run('SELECT browser, COUNT(*) as visits
FROM visits
WHERE site_id=? AND is_bot=1
GROUP BY browser
ORDER BY visits DESC', [$site['id']])->fetchAll();
}
} else {
@ -104,7 +140,12 @@ ORDER BY visits DESC');
<a href="stats.php">Millions web counter</a>:
<?php if ($site) { ?>
<h1><?php echo $site['label']; ?></h1>
<?php if ($visits) { ?>
<canvas id="canvas"></canvas>
<?php foreach ($labels as $ymd=>$label) {
echo '<a href="stats.php?for=' . $site['host'] . '&date=' . $ymd . '">' . $label . '</a> ';
} ?>
<script>
window.chartColors = {
red: 'rgb(255, 99, 132)',
@ -154,9 +195,13 @@ ORDER BY visits DESC');
};
</script>
<?php } // if $visits ?>
<?php
if ($totalVisits==0 && !empty($_GET['date'])) {
echo '<p>no visits this day!</p>';
}
if (count($byPaths)) {
echo '<h2>Top '.count($byPaths).' visited pages</h2>';
foreach ($byPaths as $page) {

Loading…
Cancel
Save