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, query_works, resource_types, statistics, statistics_for, #to_flot, work_types

Class Method Details

.filter(file) ⇒ Object

this is called by the parent class



23
24
25
# File 'app/models/file_download_stat.rb', line 23

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



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

def ga_statistics(start_date, file)
  profile = Hyrax::Analytics.profile
  unless profile
    Hyrax.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,
                          limit: 10_000)
         .for_file(file.id)
end