Class: FileDownloadStat

Inherits:
Hyrax::Statistic show all
Defined in:
app/models/file_download_stat.rb

Class Method Summary collapse

Methods inherited from Hyrax::Statistic

build_for, convert_date, statistics, statistics_for, #to_flot

Class Method Details

.filter(file) ⇒ Object

this is called by the parent class



21
22
23
# File 'app/models/file_download_stat.rb', line 21

def filter(file)
  { file_id: file.id }
end

.ga_statistics(start_date, file) ⇒ Object

Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download see Legato::ProfileMethods.method_name_from_klass



8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/file_download_stat.rb', line 8

def ga_statistics(start_date, file)
  profile = Hyrax::Analytics.profile
  unless profile
    Rails.logger.error("Google Analytics profile has not been established. Unable to fetch statistics.")
    return []
  end
  profile.hyrax__download(sort: 'date',
                          start_date: start_date,
                          end_date: Date.yesterday)
         .for_file(file.id)
end