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 @@ - +
City | +State | 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]) %> |