Skip to content

Commit

Permalink
change analytics to state
Browse files Browse the repository at this point in the history
  • Loading branch information
loftwah committed Sep 23, 2024
1 parent 80f492e commit 7ead798
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/controllers/analytics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/views/analytics/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,23 @@
</div>
</div>

<!-- Top Visitor Locations (New Section) -->
<!-- Top Visitor Locations (Updated Section) -->
<div class="bg-gray-800 rounded-lg shadow p-4 mb-6">
<h2 class="text-xl font-semibold mb-4">Top Visitor Locations</h2>
<div class="overflow-x-auto">
<table class="w-full text-sm text-center table-auto">
<thead class="text-xs uppercase bg-gray-700">
<tr>
<th scope="col" class="px-4 py-3 rounded-tl-lg">City</th>
<th scope="col" class="px-4 py-3 rounded-tl-lg">State</th>
<th scope="col" class="px-4 py-3">Country</th>
<th scope="col" class="px-4 py-3 rounded-tr-lg">Views</th>
</tr>
</thead>
<tbody>
<% @location_data.each_with_index do |location, index| %>
<% unless location[:city] == 'Unknown' && location[:country] == 'Unknown' %>
<% unless location[:state] == 'Unknown' && location[:country] == 'Unknown' %>
<tr class="<%= index.even? ? 'bg-gray-800' : 'bg-gray-900' %> border-b border-gray-700">
<td class="px-4 py-3"><%= location[:city].present? && location[:city] != 'Unknown' ? location[:city] : '' %></td>
<td class="px-4 py-3"><%= location[:state].present? && location[:state] != 'Unknown' ? location[:state] : '' %></td>
<td class="px-4 py-3"><%= location[:country].present? && location[:country] != 'Unknown' ? location[:country] : '' %></td>
<td class="px-4 py-3"><%= number_with_delimiter(location[:count]) %></td>
</tr>
Expand Down

0 comments on commit 7ead798

Please sign in to comment.