Add device statistics to analytics reports and implement pie chart visualization in admin panel
This commit is contained in:
@@ -131,6 +131,27 @@ try {
|
||||
$stmtGeo->execute($baseParams);
|
||||
$geo = $stmtGeo->fetch() ?: ['geo_passed' => 0, 'geo_failed' => 0, 'geo_bypass' => 0];
|
||||
|
||||
$sqlDeviceStats = "
|
||||
SELECT
|
||||
COALESCE(NULLIF(device_type, ''), 'other') AS device_type,
|
||||
COUNT(*) AS total
|
||||
FROM analytics_events
|
||||
WHERE event_name = 'qr_scan' {$whereWindow}
|
||||
GROUP BY COALESCE(NULLIF(device_type, ''), 'other')
|
||||
";
|
||||
$stmtDeviceStats = $pdo->prepare($sqlDeviceStats);
|
||||
$stmtDeviceStats->execute($baseParams);
|
||||
$deviceRows = $stmtDeviceStats->fetchAll();
|
||||
$deviceStats = ['ios' => 0, 'android' => 0, 'other' => 0];
|
||||
foreach ($deviceRows as $row) {
|
||||
$key = (string) ($row['device_type'] ?? 'other');
|
||||
if (!isset($deviceStats[$key])) {
|
||||
$deviceStats['other'] += (int) $row['total'];
|
||||
} else {
|
||||
$deviceStats[$key] = (int) $row['total'];
|
||||
}
|
||||
}
|
||||
|
||||
$sqlRecentOpens = "
|
||||
SELECT
|
||||
created_at,
|
||||
@@ -248,6 +269,7 @@ try {
|
||||
'failed' => (int)$geo['geo_failed'],
|
||||
'bypass' => (int)$geo['geo_bypass'],
|
||||
],
|
||||
'deviceStats' => $deviceStats,
|
||||
'recentOpens' => $recentOpens,
|
||||
'guestQueueSummary' => [
|
||||
'total' => (int)$queueSummary['total_actions'],
|
||||
|
||||
Reference in New Issue
Block a user