mirror of
https://github.com/SophiaAtkinson/steamwidgets-web.git
synced 2025-06-27 14:37:41 -07:00
Include referrers in statistics
This commit is contained in:
@ -99,11 +99,19 @@ class StatsController extends BaseController
|
|||||||
$data[$hits->get($i)->get('hittype')][$hits->get($i)->get('created_at')][] = $hits->get($i)->get('count');
|
$data[$hits->get($i)->get('hittype')][$hits->get($i)->get('created_at')][] = $hits->get($i)->get('count');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$referrers = HitsModel::getReferrers($start, $end);
|
||||||
|
|
||||||
|
$refar = [];
|
||||||
|
foreach ($referrers as $ref) {
|
||||||
|
$refar[] = $ref->get('referrer');
|
||||||
|
}
|
||||||
|
|
||||||
return json([
|
return json([
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'counts' => $count_total,
|
'counts' => $count_total,
|
||||||
'count_total' => $count_total[HitsModel::HITTYPE_MODULE_APP] + $count_total[HitsModel::HITTYPE_MODULE_SERVER] + $count_total[HitsModel::HITTYPE_MODULE_USER] + $count_total[HitsModel::HITTYPE_MODULE_WORKSHOP] + $count_total[HitsModel::HITTYPE_MODULE_GROUP],
|
'count_total' => $count_total[HitsModel::HITTYPE_MODULE_APP] + $count_total[HitsModel::HITTYPE_MODULE_SERVER] + $count_total[HitsModel::HITTYPE_MODULE_USER] + $count_total[HitsModel::HITTYPE_MODULE_WORKSHOP] + $count_total[HitsModel::HITTYPE_MODULE_GROUP],
|
||||||
|
'referrers' => $refar,
|
||||||
'start' => $start,
|
'start' => $start,
|
||||||
'end' => $end,
|
'end' => $end,
|
||||||
'day_diff' => $dayDiff
|
'day_diff' => $dayDiff
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
$this->database->add('id INT NOT NULL AUTO_INCREMENT PRIMARY KEY');
|
$this->database->add('id INT NOT NULL AUTO_INCREMENT PRIMARY KEY');
|
||||||
$this->database->add('hash_token VARCHAR(512) NOT NULL');
|
$this->database->add('hash_token VARCHAR(512) NOT NULL');
|
||||||
$this->database->add('hittype VARCHAR(100) NOT NULL');
|
$this->database->add('hittype VARCHAR(100) NOT NULL');
|
||||||
|
$this->database->add('referrer VARCHAR(512) NOT NULL');
|
||||||
$this->database->add('created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP');
|
$this->database->add('created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP');
|
||||||
$this->database->create();
|
$this->database->create();
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,12 @@ class HitsModel extends \Asatru\Database\Model
|
|||||||
static::validateHitType($type);
|
static::validateHitType($type);
|
||||||
|
|
||||||
$token = md5($_SERVER['REMOTE_ADDR']);
|
$token = md5($_SERVER['REMOTE_ADDR']);
|
||||||
|
$referrer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
|
||||||
|
|
||||||
HitsModel::raw('INSERT INTO `' . self::tableName() . '` (hash_token, hittype, created_at) VALUES(?, ?, CURRENT_TIMESTAMP)', [
|
HitsModel::raw('INSERT INTO `' . self::tableName() . '` (hash_token, hittype, referrer, created_at) VALUES(?, ?, ?, CURRENT_TIMESTAMP)', [
|
||||||
$token,
|
$token,
|
||||||
$type
|
$type,
|
||||||
|
$referrer
|
||||||
]);
|
]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
@ -63,7 +65,7 @@ class HitsModel extends \Asatru\Database\Model
|
|||||||
* @param $start
|
* @param $start
|
||||||
* @param $end
|
* @param $end
|
||||||
* @return Asatru\Database\Collection
|
* @return Asatru\Database\Collection
|
||||||
* @throws Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function getHitsPerDay($start, $end)
|
public static function getHitsPerDay($start, $end)
|
||||||
{
|
{
|
||||||
@ -74,7 +76,29 @@ class HitsModel extends \Asatru\Database\Model
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
} catch (Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all referrers of a given range
|
||||||
|
*
|
||||||
|
* @param $start
|
||||||
|
* @param $end
|
||||||
|
* @return Asatru\Database\Collection
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function getReferrers($start, $end)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$result = HitsModel::raw('SELECT DISTINCT referrer FROM `' . self::tableName() . '` WHERE DATE(created_at) >= ? AND DATE(created_at) <= ? ORDER BY referrer ASC', [
|
||||||
|
$start,
|
||||||
|
$end
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
} catch (\Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,7 @@ window.vue = new Vue({
|
|||||||
document.getElementById('count-user').innerHTML = response.counts.mod_user;
|
document.getElementById('count-user').innerHTML = response.counts.mod_user;
|
||||||
document.getElementById('count-workshop').innerHTML = response.counts.mod_workshop;
|
document.getElementById('count-workshop').innerHTML = response.counts.mod_workshop;
|
||||||
document.getElementById('count-group').innerHTML = response.counts.mod_group;
|
document.getElementById('count-group').innerHTML = response.counts.mod_group;
|
||||||
|
document.getElementById('referrers').innerHTML = '';
|
||||||
|
|
||||||
let content = document.getElementById(elem);
|
let content = document.getElementById(elem);
|
||||||
if (content) {
|
if (content) {
|
||||||
@ -200,6 +201,16 @@ window.vue = new Vue({
|
|||||||
content,
|
content,
|
||||||
config
|
config
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let refcode = '<ul>';
|
||||||
|
response.referrers.forEach(function(referrer, index) {
|
||||||
|
if (referrer.length > 0) {
|
||||||
|
refcode += '<li>' + referrer + '</li>';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
refcode += '</ul>';
|
||||||
|
|
||||||
|
document.getElementById('referrers').innerHTML = refcode;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alert(response.msg);
|
alert(response.msg);
|
||||||
|
@ -174,6 +174,10 @@ tbody strong {
|
|||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#referrers {
|
||||||
|
margin-top: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
.scroll-to-top {
|
.scroll-to-top {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 3;
|
z-index: 3;
|
||||||
|
@ -24,4 +24,8 @@
|
|||||||
<div>
|
<div>
|
||||||
<canvas id="hits-stats"></canvas>
|
<canvas id="hits-stats"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="referrers">
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user