Sha256: f2491fab12c86ba32c36510554f7881e7387b0303883bb3f6229653df48a39e6

Contents?: true

Size: 875 Bytes

Versions: 9

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true
class FileDownloadStat < Hyrax::Statistic
  self.cache_column = :downloads
  self.event_type = :totalEvents

  class << self
    # Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download
    # see Legato::ProfileMethods.method_name_from_klass
    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

    # this is called by the parent class
    def filter(file)
      { file_id: file.id }
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/models/file_download_stat.rb
hyrax-5.0.0 app/models/file_download_stat.rb
hyrax-5.0.0.rc3 app/models/file_download_stat.rb
hyrax-5.0.0.rc2 app/models/file_download_stat.rb
hyrax-5.0.0.rc1 app/models/file_download_stat.rb
hyrax-4.0.0 app/models/file_download_stat.rb
hyrax-4.0.0.rc3 app/models/file_download_stat.rb
hyrax-4.0.0.rc2 app/models/file_download_stat.rb
hyrax-4.0.0.rc1 app/models/file_download_stat.rb