Skip to content

Commit

Permalink
add priv key from env for GA 4. Copies #6063 to the new GA4 code
Browse files Browse the repository at this point in the history
differentiate between collecting and reporting google analytics.
  • Loading branch information
orangewolf committed May 17, 2024
1 parent 288699e commit 2e535d8
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 14 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? && Hyrax.config.analytics_provider != 'ga4'

@accessible_works ||= accessible_works
@accessible_file_sets ||= accessible_file_sets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="col-sm-12">
<div class="collection-reports">

<% if Hyrax.config.analytics? %>
<% if Hyrax.config.analytics_reporting? && Hyrax.config.analytics_provider != 'ga4' %>
<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">
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? && Hyrax.config.analytics_provider != 'ga4' %>
<% 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? && Hyrax.config.analytics_provider != 'ga4' %>
<% # 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 2e535d8

Please sign in to comment.