Class: AhoyCaptain::DashboardPresenter

Inherits:
Object
  • Object
show all
Includes:
CompareMode, RangeOptions, Rangeable
Defined in:
app/presenters/ahoy_captain/dashboard_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CompareMode

#comparison_mode, included

Methods included from Rangeable

#period

Constructor Details

#initialize(params) ⇒ DashboardPresenter

Returns a new instance of DashboardPresenter.



9
10
11
# File 'app/presenters/ahoy_captain/dashboard_presenter.rb', line 9

def initialize(params)
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'app/presenters/ahoy_captain/dashboard_presenter.rb', line 7

def params
  @params
end

Instance Method Details

#bounce_rateObject



29
30
31
32
33
34
35
36
# File 'app/presenters/ahoy_captain/dashboard_presenter.rb', line 29

def bounce_rate
  query = Stats::BounceRatesQuery.call(params)
  if compare_mode?
    query.with_comparison(true)
  else
    query.average("bounce_rate").try(:round, 2) || 0
  end
end

#total_pageviewsObject



21
22
23
# File 'app/presenters/ahoy_captain/dashboard_presenter.rb', line 21

def total_pageviews
  Stats::TotalPageviewsQuery.call(params).with_comparison(compare_mode?).count
end

#total_visitsObject



17
18
19
# File 'app/presenters/ahoy_captain/dashboard_presenter.rb', line 17

def total_visits
  Stats::TotalVisitorsQuery.call(params).with_comparison(compare_mode?).count
end

#unique_visitorsObject



13
14
15
# File 'app/presenters/ahoy_captain/dashboard_presenter.rb', line 13

def unique_visitors
  Stats::UniqueVisitorsQuery.call(params).with_comparison(compare_mode?).count
end

#views_per_visitObject



25
26
27
# File 'app/presenters/ahoy_captain/dashboard_presenter.rb', line 25

def views_per_visit
  Stats::AverageViewsPerVisitQuery.call(params).with_comparison(compare_mode?).average("count")
end

#visit_durationObject



38
39
40
41
42
43
44
45
# File 'app/presenters/ahoy_captain/dashboard_presenter.rb', line 38

def visit_duration
  query = Stats::AverageVisitDurationQuery.call(params)
  if compare_mode?
    query.with_comparison(true)
  else
    query[0].average_visit_duration
  end
end