Analytics' . 'Open Dashboard'; wp_add_dashboard_widget('cf_analytics_widget', $title, array($this, 'render_widget')); } /** * Data the widget needs, ready for JSON */ private function payload($series) { $t = $series['totals']; $p = $series['prev']; return array( 'labels' => array_values(wp_list_pluck($series['points'], 'label')), 'visits' => array_values(wp_list_pluck($series['points'], 'visits')), 'views' => array_values(wp_list_pluck($series['points'], 'views')), 'stats' => array( 'visits' => array(number_format_i18n($t['visits']), EACFA_Live::trend(EACFA_Live::change($t['visits'], $p ? $p['visits'] : null))), 'views' => array(number_format_i18n($t['views']), EACFA_Live::trend(EACFA_Live::change($t['views'], $p ? $p['views'] : null))) ), 'stale' => !empty($series['stale']), 'age' => isset($series['fetched_at']) ? max(0, time() - (int) $series['fetched_at']) : null ); } /** * AJAX: the cached 30-day numbers, read from the cache only. Used to redraw the widget in place * after the background refresh has finished. */ public function ajax_data() { check_ajax_referer('cf_analytics_widget_data', 'nonce'); if (!current_user_can('manage_options') || !EACFA_API::is_configured()) { wp_send_json_error('Unauthorized'); } $series = EACFA_Live::series('30days', true); if (empty($series['success'])) { wp_send_json_error(isset($series['message']) ? $series['message'] : 'Could not load analytics.'); } wp_send_json_success($this->payload($series)); } public function render_widget() { if (!EACFA_API::is_configured()) { ?>
Connect Cloudflare to see your Web Analytics here.
Connect now