Skip to content

Commit

Permalink
add monthly traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly committed Jul 10, 2024
1 parent 5d1af76 commit ccbbec9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/controllers/analytics/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ def daily_page_views
Ahoy::Event.where("date(time) BETWEEN ? AND ?", 60.days.ago.to_date, Date.yesterday).group_by_day(:time).count
end
end

def monthly_visits
@monthly_visits = Rails.cache.fetch("monthly_visits", expires_at: Time.current.end_of_day) do
Ahoy::Visit.where("date(started_at) BETWEEN ? AND ?", 12.months.ago.to_date.beginning_of_month, Date.yesterday).group_by_month(:started_at).count
end
end

def monthly_page_views
@monthly_page_views = Rails.cache.fetch("monthly_page_views", expires_at: Time.current.end_of_day) do
Ahoy::Event.where("date(time) BETWEEN ? AND ?", 12.months.ago.to_date.beginning_of_month, Date.yesterday).group_by_month(:time).count
end
end
end
4 changes: 4 additions & 0 deletions app/views/analytics/dashboards/monthly_page_views.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= turbo_frame_tag "monthly_page_views" do %>
<h2 class="text-center mb-4">Monthly page views</h2>
<%= column_chart @monthly_page_views, id: :monthly_page_views_chart %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/analytics/dashboards/monthly_visits.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= turbo_frame_tag "monthly_visits" do %>
<h2 class="text-center mb-4">Monthly visits</h2>
<%= column_chart @monthly_visits, id: :monthly_visits_chart %>
<% end %>
2 changes: 2 additions & 0 deletions app/views/analytics/dashboards/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<%= turbo_frame_tag "daily_visits", src: daily_visits_analytics_dashboards_path, lazy: true %>
<%= turbo_frame_tag "daily_page_views", src: daily_page_views_analytics_dashboards_path, lazy: true %>
<%= turbo_frame_tag "monthly_visits", src: monthly_visits_analytics_dashboards_path, lazy: true %>
<%= turbo_frame_tag "monthly_page_views", src: monthly_page_views_analytics_dashboards_path, lazy: true %>
</div>
</div>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
resource :dashboards, only: [:show] do
get :daily_page_views
get :daily_visits
get :monthly_page_views
get :monthly_visits
end
end
resources :talks, param: :slug, only: [:index, :show, :update, :edit] do
Expand Down

0 comments on commit ccbbec9

Please sign in to comment.