From 7ead7984335ac21eb67774d43f1eb3dd6cacae63 Mon Sep 17 00:00:00 2001 From: Dean Lofts Date: Mon, 23 Sep 2024 21:45:17 +1000 Subject: [PATCH] change analytics to state --- app/controllers/analytics_controller.rb | 6 +++--- app/views/analytics/index.html.erb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/analytics_controller.rb b/app/controllers/analytics_controller.rb index 6e1528e..46270d8 100644 --- a/app/controllers/analytics_controller.rb +++ b/app/controllers/analytics_controller.rb @@ -37,14 +37,14 @@ def fetch_cached_data(key, &block) end def fetch_location_data - @user.page_views.group(:country, :city).count.map do |location, count| + @user.page_views.group(:country, :state).count.map do |location, count| { country: location[0] || 'Unknown', # Fallback to 'Unknown' if no country - city: location[1] || 'Unknown', # Fallback to 'Unknown' if no city + state: location[1] || 'Unknown', # Fallback to 'Unknown' if no state count: count } end.sort_by { |location| -location[:count] }.take(10) - end + end # Update this method to exclude hidden links def fetch_link_analytics diff --git a/app/views/analytics/index.html.erb b/app/views/analytics/index.html.erb index 12f7e22..5c0deb5 100644 --- a/app/views/analytics/index.html.erb +++ b/app/views/analytics/index.html.erb @@ -100,23 +100,23 @@ - +

Top Visitor Locations

- + <% @location_data.each_with_index do |location, index| %> - <% unless location[:city] == 'Unknown' && location[:country] == 'Unknown' %> + <% unless location[:state] == 'Unknown' && location[:country] == 'Unknown' %> - +
CityState Country Views
<%= location[:city].present? && location[:city] != 'Unknown' ? location[:city] : '' %><%= location[:state].present? && location[:state] != 'Unknown' ? location[:state] : '' %> <%= location[:country].present? && location[:country] != 'Unknown' ? location[:country] : '' %> <%= number_with_delimiter(location[:count]) %>