Module: Hyrax::Analytics::Google::Visits

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

Class Method Summary collapse

Class Method Details

.new_visits(profile, start_date, end_date) ⇒ Object



19
20
21
22
23
24
# File 'app/services/hyrax/analytics/google/visits.rb', line 19

def self.new_visits(profile, start_date, end_date)
  x = Visits.results(profile,
    start_date: start_date,
    end_date: end_date).to_a
  x.first.sessions.to_i
end

.results_array(response) ⇒ Object



11
12
13
14
15
16
17
# File 'app/services/hyrax/analytics/google/visits.rb', line 11

def self.results_array(response)
  results = []
  response.to_a.each do |result|
    results.push([result.date.to_date, result.result.sessions.to_i])
  end
  Hyrax::Analytics::Results.new(results)
end

.return_visits(profile, start_date, end_date) ⇒ Object



26
27
28
29
30
31
# File 'app/services/hyrax/analytics/google/visits.rb', line 26

def self.return_visits(profile, start_date, end_date)
  x = Visits.results(profile,
    start_date: start_date,
    end_date: end_date).to_a
  x.last.sessions.to_i
end

.total_visits(profile, start_date, end_date) ⇒ Object



33
34
35
36
37
38
39
40
# File 'app/services/hyrax/analytics/google/visits.rb', line 33

def self.total_visits(profile, start_date, end_date)
  x = Visits.results(profile,
    start_date: start_date,
    end_date: end_date).to_a
  new_visits = x.first.sessions.to_i
  returning_visits = x.last.sessions.to_i
  new_visits + returning_visits
end