get_ai_referrer_insights($almaweb_period); // Prepare data for the new Doughnut Chart and enqueue inline script if (!empty($almaweb_referrer_insights['top_sources'])) { $almaweb_labels = []; $almaweb_data = []; // Simple, visually distinct color palette $almaweb_colors = ['#4f46e5', '#10b981', '#f59e0b', '#ef4444', '#3b82f6', '#6b7280', '#8b5cf6', '#ec4899', '#f97316', '#06b6d4']; $almaweb_background_colors = []; $almaweb_i = 0; foreach ($almaweb_referrer_insights['top_sources'] as $almaweb_source) { $almaweb_labels[] = $almaweb_source['ai_referrer_source']; $almaweb_data[] = $almaweb_source['visit_count']; $almaweb_background_colors[] = $almaweb_colors[$almaweb_i % count($almaweb_colors)]; $almaweb_i++; } $almaweb_chart_data = [ 'aiSourcesData' => [ 'labels' => $almaweb_labels, 'datasets' => [[ 'data' => $almaweb_data, 'backgroundColor' => $almaweb_background_colors, ]] ] ]; // Enqueue inline script for chart data $almaweb_referrers_script = 'document.addEventListener("DOMContentLoaded", function() { var event = new CustomEvent("almawebAIVisitorAnalyticsDataLoaded", { detail: ' . wp_json_encode($almaweb_chart_data) . ' }); document.dispatchEvent(event); });'; wp_add_inline_script('almaweb-ai-visitor-analytics-admin', $almaweb_referrers_script); } ?>

0): ?>

' . number_format($almaweb_referrer_insights['total_visits']) . '', count($almaweb_referrer_insights['top_sources'])); ?>