Module: Hyrax::Analytics::Google::VisitsDaily

Extended by:
Legato::Model
Defined in:
app/services/hyrax/analytics/google/visits_daily.rb

Class Method Summary collapse

Class Method Details

.new_visits(profile, start_date, end_date) ⇒ Object


14
15
16
17
18
19
20
# File 'app/services/hyrax/analytics/google/visits_daily.rb', line 14

def self.new_visits(profile, start_date, end_date)
  response = VisitsDaily.results(profile,
    start_date: start_date,
    end_date: end_date).new_visit.to_a
  dates = (start_date.to_date...end_date.to_date)
  results_array(response, dates)
end

.results_array(response, dates) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/hyrax/analytics/google/visits_daily.rb', line 30

def self.results_array(response, dates)
  results = []
  response.to_a.each do |result|
    results.push([result.date.to_date, result.sessions.to_i])
  end
  new_results = []
  dates.each do |date|
    match = results.detect { |a, _b| a == date }
    if match
      new_results.push(match)
    else
      new_results.push([date, 0])
    end
  end
  Hyrax::Analytics::Results.new(new_results)
end

.return_visits(profile, start_date, end_date) ⇒ Object


22
23
24
25
26
27
28
# File 'app/services/hyrax/analytics/google/visits_daily.rb', line 22

def self.return_visits(profile, start_date, end_date)
  response = VisitsDaily.results(profile,
    start_date: start_date,
    end_date: end_date).returning.to_a
  dates = (start_date.to_date...end_date.to_date)
  results_array(response, dates)
end