diff --git a/lang/en_us.php b/lang/en_us.php index d3e84a3..4a10257 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -85,6 +85,9 @@ define("STRINGS", [ "overview" => "Overview", "views per visit" => "views per visit", "visits over time" => "Visits Over Time", + "page views over time" => "Page Views Over Time", + "page ranking" => "Page Ranking", + "x views" => "{views} views", "no data" => "No data.", "visitor map" => "Visitor Map", "enable built-in analytics" => "Enable built-in analytics", diff --git a/pages/analytics.php b/pages/analytics.php index 6442a0b..26d0767 100644 --- a/pages/analytics.php +++ b/pages/analytics.php @@ -45,6 +45,83 @@ $records = $database->select("analytics", [ "lat", "lon", "time", "pages.title (pagetitle)", "pages.slug (pageslug)", "sites.sitename" ], $where); + +$format = "Y-m-00 00:00:00"; +$max = $records[0]; +$min = $records[count($records) - 1]; +$diff = strtotime($max['time']) - strtotime($min['time']); +if ($diff < 60 * 60) { // 1 hour + $format = "Y-m-d H:i:00"; +} else if ($diff < 60 * 60 * 24 * 3) { // 3 days + $format = "Y-m-d H:00:00"; +} else if ($diff < 60 * 60 * 24 * 60) { // 30 days + $format = "Y-m-d 00:00:00"; +} + +$visitors = []; +$viewsovertime = []; +$pages = []; +foreach ($records as $r) { + if (!array_key_exists($r["uuid"], $visitors)) { + $visitors[$r["uuid"]] = $r; + } + + $rf = date($format, strtotime($r['time'])); + if (array_key_exists($rf, $viewsovertime)) { + $viewsovertime[$rf] ++; + } else { + $viewsovertime[$rf] = 1; + } + + if (array_key_exists($r['pageid'], $pages)) { + $pages[$r['pageid']]["views"] ++; + } else { + $pages[$r['pageid']] = [ + "pagetitle" => $r['pagetitle'], + "sitename" => $r['sitename'], + "views" => 1 + ]; + } +} +$pageviews = count($records); +usort($pages, function($a, $b) { + return $b['views'] <=> $a['views']; +}); + +require_once __DIR__ . "/../lib/countries_2_3.php"; +$countries = []; +$states = []; +$visitsovertime = []; +foreach ($visitors as $r) { + $rf = date($format, strtotime($r['time'])); + if (array_key_exists($rf, $visitsovertime)) { + $visitsovertime[$rf] ++; + } else { + $visitsovertime[$rf] = 1; + } + if (array_key_exists($COUNTRY_CODES[$r['countrycode']], $countries)) { + $countries[$COUNTRY_CODES[$r['countrycode']]] ++; + } else { + $countries[$COUNTRY_CODES[$r['countrycode']]] = 1; + } + if ($r['countrycode'] === "US") { + if (array_key_exists($r['regioncode'], $states)) { + $states[$r['regioncode']] ++; + } else { + $states[$r['regioncode']] = 1; + } + } +} +$visits = count($visitors); + +$countrymapdata = []; +foreach ($countries as $id => $count) { + $countrymapdata[] = [$id, $count]; +} +$statemapdata = []; +foreach ($states as $id => $count) { + $statemapdata[] = [$id, $count]; +} ?> @@ -104,19 +181,11 @@ if (count($records) > 0) {


-
+
@@ -126,37 +195,13 @@ if (count($records) > 0) {

- - @@ -166,44 +211,30 @@ if (count($records) > 0) {
+ +
+
+

+ +
+ +
+
+
+

- $count) { - $countrymapdata[] = [$id, $count]; - } - $statemapdata = []; - foreach ($states as $id => $count) { - $statemapdata[] = [$id, $count]; - } - ?>