prefix . 'eistat_'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $days = isset($_GET['days']) && (int) $_GET['days'] === 28 ? 28 : 7; $eistat_today = current_time('Y-m-d'); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_today_row = $wpdb->get_row($wpdb->prepare( "SELECT * FROM {$eistat_p}daily WHERE date = %s", $eistat_today )); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_today_top_pages = $wpdb->get_results($wpdb->prepare( "SELECT page_id, page_type, page_url, views FROM {$eistat_p}pageviews WHERE date = %s ORDER BY views DESC LIMIT 5", $eistat_today )); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_today_top_sources = $wpdb->get_results($wpdb->prepare( "SELECT source, source_detail, SUM(sessions) AS s, SUM(pageviews) AS pv FROM {$eistat_p}sources WHERE date = %s GROUP BY source, source_detail ORDER BY s DESC LIMIT 5", $eistat_today )); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_daily = $wpdb->get_results($wpdb->prepare( "SELECT * FROM {$eistat_p}daily WHERE date >= DATE_SUB(CURDATE(), INTERVAL %d DAY) ORDER BY date DESC", $days )); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_devices = $wpdb->get_results($wpdb->prepare( "SELECT device, COUNT(*) AS c, SUM(is_bot) AS bots FROM {$eistat_p}sessions WHERE date >= DATE_SUB(CURDATE(), INTERVAL %d DAY) GROUP BY device ORDER BY c DESC", $days )); $eistat_dev_total = 0; foreach ($eistat_devices as $d) { $eistat_dev_total += (int) $d->c; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_dur_dist = $wpdb->get_row($wpdb->prepare( "SELECT SUM(CASE WHEN total_time < 15 THEN 1 ELSE 0 END) AS b1, SUM(CASE WHEN total_time >= 15 AND total_time < 60 THEN 1 ELSE 0 END) AS b2, SUM(CASE WHEN total_time >= 60 AND total_time < 300 THEN 1 ELSE 0 END) AS b3, SUM(CASE WHEN total_time >= 300 AND total_time < 900 THEN 1 ELSE 0 END) AS b4, SUM(CASE WHEN total_time >= 900 THEN 1 ELSE 0 END) AS b5, COUNT(*) AS total FROM {$eistat_p}sessions WHERE date >= DATE_SUB(CURDATE(), INTERVAL %d DAY) AND is_bot = 0", $days )); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_ip_stats = $wpdb->get_row($wpdb->prepare( "SELECT COUNT(DISTINCT ip_hash) AS total_ips, COUNT(DISTINCT CASE WHEN visits >= 2 THEN ip_hash END) AS returning_ips FROM ( SELECT ip_hash, COUNT(DISTINCT date) AS visits FROM {$eistat_p}sessions WHERE date >= DATE_SUB(CURDATE(), INTERVAL %d DAY) AND is_bot = 0 GROUP BY ip_hash ) t", $days )); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_source_details = $wpdb->get_results($wpdb->prepare( "SELECT source, source_detail, SUM(sessions) AS s, SUM(pageviews) AS pv, SUM(total_duration) AS dur FROM {$eistat_p}sources WHERE date >= DATE_SUB(CURDATE(), INTERVAL %d DAY) AND source_detail != '' GROUP BY source, source_detail ORDER BY s DESC LIMIT 15", $days )); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $eistat_clicks_summary = $wpdb->get_row($wpdb->prepare( "SELECT SUM(CASE WHEN link_type = 'outbound' THEN count ELSE 0 END) AS outbound, SUM(CASE WHEN link_type = 'email' THEN count ELSE 0 END) AS email, SUM(CASE WHEN link_type = 'phone' THEN count ELSE 0 END) AS phone, SUM(count) AS total FROM {$eistat_p}events WHERE date >= DATE_SUB(CURDATE(), INTERVAL %d DAY)", $days )); ?>

sessions; $eistat_bots = (int) $eistat_today_row->bot_sessions; $eistat_human = $eistat_sessions - $eistat_bots; $eistat_pv = (int) $eistat_today_row->pageviews; $eistat_avg_pv = $eistat_human > 0 ? round($eistat_pv / $eistat_human, 2) : 0; $eistat_dur_human = $eistat_human > 0 ? round($eistat_today_row->total_duration_human / $eistat_human) : 0; $eistat_dur_all = $eistat_sessions > 0 ? round($eistat_today_row->total_duration / $eistat_sessions) : 0; $eistat_dur_approx_human = $eistat_human > 0 ? round($eistat_today_row->total_duration_approx_human / $eistat_human) : 0; $eistat_b_human = (int) $eistat_today_row->bounces_human; $eistat_b_all = (int) $eistat_today_row->bounces; $eistat_br_human = $eistat_human > 0 ? round($eistat_b_human / $eistat_human * 100, 1) : 0; $eistat_br_all = $eistat_sessions > 0 ? round($eistat_b_all / $eistat_sessions * 100, 1) : 0; ?>
(%)

page_url); ?> views; ?>

source; if ($s->source_detail !== '') { $eistat_label .= ' / ' . $s->source_detail; } ?>
s; ?>

get_row($wpdb->prepare( "SELECT SUM(CASE WHEN link_type = 'outbound' THEN count ELSE 0 END) AS outbound, SUM(CASE WHEN link_type = 'email' THEN count ELSE 0 END) AS email, SUM(CASE WHEN link_type = 'phone' THEN count ELSE 0 END) AS phone, SUM(count) AS total FROM {$eistat_p}events WHERE date = %s", $eistat_today )); $eistat_ct_total = (int) ($eistat_clicks_today->total ?? 0); ?>
outbound ?? 0))); ?>
email ?? 0))); ?>
phone ?? 0))); ?>
0): ?>

sessions; $eistat_b = (int) $r->bot_sessions; $eistat_h = $eistat_s - $eistat_b; $eistat_pv_row = (int) $r->pageviews; $eistat_avg = $eistat_h > 0 ? round($eistat_pv_row / $eistat_h, 2) : 0; $eistat_dur_human = $eistat_h > 0 ? round($r->total_duration_human / $eistat_h) : 0; $eistat_dur_all = $eistat_s > 0 ? round($r->total_duration / $eistat_s) : 0; $eistat_dur_approx_human = $eistat_h > 0 ? round($r->total_duration_approx_human / $eistat_h) : 0; $eistat_b_human = (int) $r->bounces_human; $eistat_b_all = (int) $r->bounces; $eistat_br_human = $eistat_h > 0 ? round($eistat_b_human / $eistat_h * 100, 1) : 0; $eistat_br_all = $eistat_s > 0 ? round($eistat_b_all / $eistat_s * 100, 1) : 0; $eistat_day_url = admin_url('admin.php?page=eistat-dashboard&view=day&date=' . $r->date); ?>
date); ?> ()
(%)

0 ? round((int) $d->c / $eistat_dev_total * 100, 1) : 0; ?>
%
device); ?> c)); ?> %

total ?? 0); $eistat_buckets = [ ['< 15 s', (int) ($eistat_dur_dist->b1 ?? 0)], ['15–60 s', (int) ($eistat_dur_dist->b2 ?? 0)], ['1–5 min', (int) ($eistat_dur_dist->b3 ?? 0)], ['5–15 min', (int) ($eistat_dur_dist->b4 ?? 0)], ['> 15 min', (int) ($eistat_dur_dist->b5 ?? 0)], ]; ?> 0 ? round($b[1] / $eistat_total_dur * 100, 1) : 0; ?>
%
%

total_ips ?? 0); $eistat_returning_ips = (int) ($eistat_ip_stats->returning_ips ?? 0); $eistat_returning_pct = $eistat_total_ips > 0 ? round($eistat_returning_ips / $eistat_total_ips * 100, 1) : 0; ?>
(%)

⚠

s > 0 ? round($sd->dur / $sd->s) : 0; ?>
source); ?> source_detail); ?> s)); ?> pv)); ?>