Referrer count

This commit is contained in:
Daniel Brendel
2023-07-29 12:30:54 +02:00
parent 03b3fb8b10
commit 02aee919bd
3 changed files with 10 additions and 7 deletions

View File

@ -92,7 +92,7 @@ class HitsModel extends \Asatru\Database\Model
public static function getReferrers($start, $end)
{
try {
$items = HitsModel::raw('SELECT DISTINCT referrer FROM `' . self::tableName() . '` WHERE DATE(created_at) >= ? AND DATE(created_at) <= ? ORDER BY referrer ASC', [
$items = HitsModel::raw('SELECT DISTINCT referrer, COUNT(referrer) AS count FROM `' . self::tableName() . '` WHERE DATE(created_at) >= ? AND DATE(created_at) <= ? GROUP BY referrer ORDER BY referrer ASC', [
$start,
$end
]);
@ -102,10 +102,12 @@ class HitsModel extends \Asatru\Database\Model
foreach ($items as $item) {
$furl = parse_url($item->get('referrer'), PHP_URL_HOST);
if (!in_array($furl, $result)) {
$result[] = $furl;
$entry['ref'] = $furl;
$entry['count'] = $item->get('count');
$result[] = $entry;
}
}
return $result;
} catch (\Exception $e) {
throw $e;