diff --git a/app/controllers/analytics_controller.rb b/app/controllers/analytics_controller.rb index 332646d..ae0a927 100644 --- a/app/controllers/analytics_controller.rb +++ b/app/controllers/analytics_controller.rb @@ -12,8 +12,9 @@ def index @link_analytics = fetch_cached_data("link_analytics") { fetch_link_analytics } @achievement_analytics = fetch_cached_data("achievement_analytics") { fetch_achievement_analytics } @daily_views = fetch_cached_data("daily_views") { fetch_daily_views } + @daily_unique_visitors = fetch_cached_data("daily_unique_visitors") { fetch_daily_unique_visitors } @browser_data = fetch_cached_data("browser_data") { fetch_browser_data } - end + end private @@ -58,6 +59,10 @@ def fetch_daily_views @user.page_views.group_by_day(:visited_at, range: 30.days.ago..Time.now).count end + def fetch_daily_unique_visitors + @user.page_views.select(:ip_address).distinct.group_by_day(:visited_at, range: 30.days.ago..Time.now).count + end + def fetch_browser_data @user.page_views.group(:browser).count.transform_keys do |user_agent| case user_agent diff --git a/app/views/analytics/index.html.erb b/app/views/analytics/index.html.erb index 3fd0fdf..7b5b734 100644 --- a/app/views/analytics/index.html.erb +++ b/app/views/analytics/index.html.erb @@ -111,29 +111,51 @@ -
- -
-

Daily Views (Last 30 Days)

- <%= line_chart @daily_views, - colors: ["#84CC16"], - library: { - backgroundColor: 'transparent', - legend: { display: false }, - scales: { - x: { ticks: { color: 'white', fontSize: 12 } }, - y: { ticks: { color: 'white', fontSize: 12 } }, - }, - elements: { - line: { tension: 0.4 }, - point: { radius: 3, backgroundColor: 'white' } - }, - title: { display: true, text: 'Daily Views (Last 30 Days)', color: 'white', fontSize: 16 }, - responsive: true +
+ +
+

Daily Views (Last 30 Days)

+ <%= line_chart @daily_views, + colors: ["#84CC16"], + library: { + backgroundColor: 'transparent', + legend: { display: false }, + scales: { + x: { ticks: { color: 'white', fontSize: 12 } }, + y: { ticks: { color: 'white', fontSize: 12 } }, }, - height: "300px" %> -
+ elements: { + line: { tension: 0.4 }, + point: { radius: 3, backgroundColor: 'white' } + }, + title: { display: true, text: 'Daily Views (Last 30 Days)', color: 'white', fontSize: 16 }, + responsive: true + }, + height: "300px" %> +
+ + +
+

Unique Visitors (Last 30 Days)

+ <%= line_chart @daily_unique_visitors, + colors: ["#E879F9"], + library: { + backgroundColor: 'transparent', + legend: { display: false }, + scales: { + x: { ticks: { color: 'white', fontSize: 12 } }, + y: { ticks: { color: 'white', fontSize: 12 } }, + }, + elements: { + line: { tension: 0.4 }, + point: { radius: 3, backgroundColor: 'white' } + }, + title: { display: true, text: 'Unique Visitors (Last 30 Days)', color: 'white', fontSize: 16 }, + responsive: true + }, + height: "300px" %>
+