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 @@ -