<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } $attributions = Database::fetchAll( "SELECT cd.campaign_name, cd.platform, cd.store_name, COUNT(*) as visits      FROM campaign_hits ch      JOIN stores cd ON cd.id = ch.domain_id      GROUP BY cd.campaign_name, cd.platform, cd.store_name      ORDER BY visits DESC LIMIT 50" ); $headers = ["Campaign", "Platform", "Store", "Visits"]; $rows = []; foreach ($attributions as $a) { $rows[] = [ UI::e($a["campaign_name"] ?? "direct"), UI::e($a["platform"] ?? ""), UI::e($a["store_name"] ?? ""), $a["visits"] ]; } echo "<div class=\"attribution\"><h3>Campaign Attribution</h3>" . UI::table($headers, $rows, "tbl-attribution") . "</div>"; 