feat(analytics): add request status field

This commit is contained in:
David Bailey 2025-04-08 10:04:39 +02:00
parent 6ae06b4765
commit 73414fa639
4 changed files with 11 additions and 3 deletions

View file

@ -8,7 +8,7 @@ interface AnalyticsInterface {
public function log_path_access( public function log_path_access(
$path, $path,
$agent, $agent,
$referrer, $runtime); $referrer, $runtime, $status = 200);
public function log_path_errcode( public function log_path_errcode(
$path, $path,

View file

@ -72,7 +72,7 @@ class MySQLAnalyticsHandler
$path, $path,
$agent, $agent,
$referrer, $referrer,
$time) { $time, $status = 200) {
if(strlen($path) == 0) { if(strlen($path) == 0) {
$path = '/'; $path = '/';
@ -83,6 +83,7 @@ class MySQLAnalyticsHandler
'path' => $path, 'path' => $path,
'agent' => $agent, 'agent' => $agent,
'referrer' => $referrer, 'referrer' => $referrer,
'status' => $status
], 'access_sum'); ], 'access_sum');
$this->increment_counter([ $this->increment_counter([

View file

@ -107,6 +107,8 @@ if($REQUEST_PATH == '/search/') {
$post = $adapter->get_post($REQUEST_PATH); $post = $adapter->get_post($REQUEST_PATH);
if(!isset($post)) { if(!isset($post)) {
$analytics_return_status = 404;
$error_page = $SITE_CONFIG['site_defaults']; $error_page = $SITE_CONFIG['site_defaults'];
$error_page['path'] = '/404'; $error_page['path'] = '/404';
$error_page['title'] = '404 oh no'; $error_page['title'] = '404 oh no';

View file

@ -5,6 +5,9 @@ $data_time_start = microtime(true);
$analytics_enable_tail = false; $analytics_enable_tail = false;
$analytics_post = null; $analytics_post = null;
$analytics_return_status = 200;
function deduce_user_agent() { function deduce_user_agent() {
$real_agent=$_SERVER['HTTP_USER_AGENT']; $real_agent=$_SERVER['HTTP_USER_AGENT'];
@ -34,6 +37,8 @@ register_shutdown_function(function() {
global $analytics_enable_tail; global $analytics_enable_tail;
global $analytics_return_status;
$data_time_end = microtime(true); $data_time_end = microtime(true);
$http_referer = 'magic'; $http_referer = 'magic';
@ -48,7 +53,7 @@ register_shutdown_function(function() {
$analytics_adapter->log_path_access($REQUEST_PATH, $analytics_adapter->log_path_access($REQUEST_PATH,
deduce_user_agent(), deduce_user_agent(),
$referrer, $referrer,
$compute_time); $compute_time, $analytics_return_status);
if($analytics_enable_tail) { if($analytics_enable_tail) {
echo "<!-- Total page time was: " . $compute_time . " -->"; echo "<!-- Total page time was: " . $compute_time . " -->";