Skip to content

Commit

Permalink
Divide analytics collecting and reporting (#6801)
Browse files Browse the repository at this point in the history
* Google Analytics 4 reporting support

* add priv key from env for GA 4 (#6107)

* add priv key from env for GA 4. Copies #6063 to the new GA4 code

* add priv key from env for GA 4. Copies #6063 to the new GA4 code
differentiate between collecting and reporting google analytics.

* clean up merge

* remove ga4 bleed over from this pr

---------

Co-authored-by: Daniel Pierce <[email protected]>
  • Loading branch information
orangewolf and dlpierce authored May 24, 2024
1 parent 7197138 commit 334d9ad
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Analytics
class CollectionReportsController < AnalyticsController
include Hyrax::BreadcrumbsForCollectionAnalytics
def index
return unless Hyrax.config.analytics?
return unless Hyrax.config.analytics_reporting?

@pageviews = Hyrax::Analytics.daily_events('collection-page-view')
@work_page_views = Hyrax::Analytics.daily_events('work-in-collection-view')
Expand All @@ -21,7 +21,7 @@ def index
end

def show
return unless Hyrax.config.analytics?
return unless Hyrax.config.analytics_reporting?
@document = ::SolrDocument.find(params[:id])
@pageviews = Hyrax::Analytics.daily_events_for_id(@document.id, 'collection-page-view')
@work_page_views = Hyrax::Analytics.daily_events_for_id(@document.id, 'work-in-collection-view')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class WorkReportsController < AnalyticsController
include Hyrax::BreadcrumbsForWorksAnalytics

def index
return unless Hyrax.config.analytics?
return unless Hyrax.config.analytics_reporting?

@accessible_works ||= accessible_works
@accessible_file_sets ||= accessible_file_sets
Expand Down
2 changes: 0 additions & 2 deletions app/services/hyrax/analytics/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def initialize(config)
# @return [Boolean] are all the required values present?
def valid?
return false unless @config['privkey_value'].present? || @config['privkey_path'].present?

REQUIRED_KEYS.all? { |required| @config[required].present? }
end

Expand Down Expand Up @@ -209,4 +208,3 @@ def total_visitors(period = 'month', date = default_date_range)
# rubocop:enable Metrics/ModuleLength
end
end
# rubocop:enable Metrics/ModuleLength
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<div class="col-sm-12">
<div class="collection-reports">

<% if Hyrax.config.analytics? %>
<% if Hyrax.config.analytics_reporting? %>
<div class="card">
<div class="card-header"><%= t('.repo_summary') %> <b><%= pluralize(Collection.count, "collection") %></b>, <%= t('.repo_summary_2') %> <b><%= @pageviews.all %> <%= t('.views') %></b> <%= t('.and') %> <b><%= @downloads.all %> <%= t('.downloads') %></b>.</div>
<div class="card-body">

<div class="row text-center">
<div class="nav nav-pills btn-group" role="group">
<% if params[:start_date] %>
Expand Down Expand Up @@ -54,7 +54,7 @@
<%= render "hyrax/admin/analytics/date_range_form", redirect_path: hyrax.admin_analytics_collection_reports_path %>
<%= render "custom_range" %></div>
</div>

</div>
</div>
<p class="text-center"><%= t('.report_generated_on') %> <b><%= Time.current %></b>.</p>
Expand All @@ -67,4 +67,4 @@
<% end %>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="work-reports">

<div class="card">
<% if Hyrax.config.analytics? %>
<% if Hyrax.config.analytics_reporting? %>
<% if current_user.ability.admin? %>
<div class="card-header"><b><%= @works_count %> <%= t('.works') %></b> <%= t('.repo_summary') %> <b><%= @pageviews.all if @pageviews %> <%= t('.views') %></b> <%= t('.and') %> <b><%= @downloads.all if @downloads %> <%= t('.downloads') %></b>.</div>
<% else %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/base/_show_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class: presenter.display_unfeature_link? ? 'btn btn-secondary' : 'btn btn-secondary collapse' %>
<% end %>
<% end %>
<% if Hyrax.config.analytics? %>
<% if Hyrax.config.analytics_reporting? %>
<% # turbolinks needs to be turned off or the page will use the cache and the %>
<% # analytics graph will not show unless the page is refreshed. %>
<%= link_to t('.analytics'), presenter.stats_path, id: 'stats', class: 'btn btn-secondary', data: { turbolinks: false } %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/base/_work_button_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
data: { behavior: 'unfeature' },
class: presenter.display_feature_link? ? 'btn btn-secondary collapse' : 'btn btn-secondary' %>
<% end %>
<% if Hyrax.config.analytics? %>
<% if Hyrax.config.analytics_reporting? %>
<%= link_to t(".analytics"), presenter.stats_path, id: 'stats', class: 'btn btn-secondary' %>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/hyrax/dashboard/_user_activity.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= t('.title') %>
</div>
<div class="card-body d-flex justify-content-center">
<% if Hyrax.config.analytics? %>
<% if Hyrax.config.analytics_reporting? %>
<%= render 'user_activity_graph' %>

<!-- FIXME: This is like embedded a card in a card...seems odd -->
Expand All @@ -22,4 +22,4 @@
</div>
<% end %>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/hyrax/dashboard/show_admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% end %>

<div class="spaced-rows">
<% if Hyrax.config.analytics? %>
<% if Hyrax.config.analytics_reporting? %>
<div class="row">
<div class="col">
<div class="card">
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/dashboard/sidebar/_activity.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<% end %>
<% end %>
<% if current_ability.can_create_any_work? && Hyrax.config.analytics? %>
<% if current_ability.can_create_any_work? && Hyrax.config.analytics_reporting? %>
<li class="nav-item">
<%= menu.collapsable_section t('hyrax.admin.sidebar.analytics'),
icon_class: "fa fa-pie-chart",
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/file_sets/_show_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="form-actions">
<% if Hyrax.config.analytics? %>
<% if Hyrax.config.analytics_reporting? %>
<% # turbolinks needs to be turned off or the page will use the cache and the %>
<% # analytics graph will not show unless the page is refreshed. %>
<%= link_to t('.analytics'), @presenter.stats_path, id: 'stats', class: 'btn btn-secondary', data: { turbolinks: false } %>
Expand Down
11 changes: 11 additions & 0 deletions lib/hyrax/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,24 @@ def register_roles

# @!group Analytics

# This value determines whether to collect analytics or not
attr_writer :analytics
attr_reader :analytics
def analytics?
@analytics ||=
ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYRAX_ANALYTICS', false))
end

# This value determines whether to show reports on the dashboard, work and collection report pages
# With Google: it's dependent on the GOOGLE_OAUTH_XXX values
# With Matomo: TODO
attr_writer :analytics_reporting
attr_reader :analytics_reporting
def analytics_reporting?
@analytics_reporting ||=
ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYRAX_ANALYTICS_REPORTING', false))
end

# Currently supports 'google' or 'matomo'
# google is default for backward compatability
attr_writer :analytics_provider
Expand Down

0 comments on commit 334d9ad

Please sign in to comment.