Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ga4 stats not being able to retrieve events properly, add work show to user vitals #6886

Merged
merged 9 commits into from
Aug 13, 2024
2 changes: 1 addition & 1 deletion app/assets/javascripts/hyrax/analytics_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function trackAnalyticsEvents(provider) {
if(provider !== 'ga4') {
window.trackingTags.analytics().push([window.trackingTags.trackEvent(), eventSpan.data('category'), eventSpan.data('action'), eventSpan.data('name')]);
} else {
gtag('event', eventspan.data('action'), { 'content_type': eventspan.data('category'), 'content_id': eventspan.data('name')})
gtag('event', eventSpan.data('action'), { 'content_type': eventSpan.data('category'), 'content_id': eventSpan.data('name')})
}
})
}
Expand Down
10 changes: 1 addition & 9 deletions app/services/hyrax/analytics/ga4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ module Ga4
extend ActiveSupport::Concern
# rubocop:disable Metrics/BlockLength
class_methods do
def client
@client
end

def client=(value)
@client = value
end

# Loads configuration options from config/analytics.yml. You only need PRIVATE_KEY_PATH or
# PRIVATE_KEY_VALUE. VALUE takes precedence.
# Expected structure:
Expand Down Expand Up @@ -87,7 +79,7 @@ def account_info
end

def client
self.class.client ||= ::Google::Analytics::Data::V1beta::AnalyticsData::Client.new do |conf|
@client ||= ::Google::Analytics::Data::V1beta::AnalyticsData::Client.new do |conf|
conf.credentials = config.account_info
end
end
Expand Down
10 changes: 10 additions & 0 deletions app/services/hyrax/analytics/ga4/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ module Ga4
class Base
attr_reader :start_date, :end_date, :dimensions, :metrics

def initialize(start_date:,
end_date:,
dimensions: [],
metrics: [])
@start_date = start_date.to_date
@end_date = end_date.to_date
@dimensions = dimensions
@metrics = metrics
end

def filters
@filters ||= {}
end
Expand Down
4 changes: 0 additions & 4 deletions app/services/hyrax/analytics/ga4/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def initialize(start_date:,
dimensions: [{ name: 'eventName' }, { name: 'contentType' }, { name: 'contentId' }],
metrics: [{ name: 'eventCount' }])
super
@start_date = start_date.to_date
@end_date = end_date.to_date
@dimensions = dimensions
@metrics = metrics
end

def self.list(start_date, end_date, action)
Expand Down
4 changes: 0 additions & 4 deletions app/services/hyrax/analytics/ga4/events_daily.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def initialize(start_date:,
dimensions: [{ name: 'date' }, { name: 'eventName' }, { name: 'contentType' }, { name: 'contentId' }],
metrics: [{ name: 'eventCount' }])
super
@start_date = start_date.to_date
@end_date = end_date.to_date
@dimensions = dimensions
@metrics = metrics
end

# returns a daily number of events for a specific action
Expand Down
4 changes: 0 additions & 4 deletions app/services/hyrax/analytics/ga4/visits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module Ga4
class Visits < Hyrax::Analytics::Ga4::Base
def initialize(start_date:, end_date:, dimensions: [{ name: 'newVsReturning' }], metrics: [{ name: 'sessions' }])
super
@start_date = start_date.to_date
@end_date = end_date.to_date
@dimensions = dimensions
@metrics = metrics
end

def new_visits
Expand Down
4 changes: 0 additions & 4 deletions app/services/hyrax/analytics/ga4/visits_daily.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module Ga4
class VisitsDaily < Hyrax::Analytics::Ga4::Base
def initialize(start_date:, end_date:, dimensions: [{ name: 'date' }, { name: 'newVsReturning' }], metrics: [{ name: 'sessions' }])
super
@start_date = start_date.to_date
@end_date = end_date.to_date
@dimensions = dimensions
@metrics = metrics
end

def new_visits
Expand Down
5 changes: 3 additions & 2 deletions app/views/hyrax/users/_vitals.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<span class="fa fa-upload" aria-hidden="true"></span> <%= link_to_works(user) %>

<ul class="views-downloads-dashboard list-unstyled">
<li><span class="badge badge-optional dark-text"><%= user.total_file_views %></span> <%= t("hyrax.dashboard.stats.file_views").pluralize(user.total_file_views) %></li>
<li><span class="badge badge-optional dark-text"><%= user.total_file_downloads %></span> <%= t("hyrax.dashboard.stats.file_downloads").pluralize(user.total_file_downloads) %></li>
<li><span class="badge badge-optional dark-text"><%= user.total_work_views %></span> <%= t("hyrax.dashboard.stats.work_views").pluralize(user.total_work_views) %></li>
<li><span class="badge badge-optional dark-text"><%= user.total_file_views %></span> <%= t("hyrax.dashboard.stats.file_views").pluralize(user.total_file_views) %></li>
<li><span class="badge badge-optional dark-text"><%= user.total_file_downloads %></span> <%= t("hyrax.dashboard.stats.file_downloads").pluralize(user.total_file_downloads) %></li>
</ul>
</div>
5 changes: 3 additions & 2 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,9 @@ en:
graph_reports: Customized Graph Reports
stats:
collections: Collections created
file_downloads: Download
file_views: View
work_views: Metadata View
file_downloads: File Download
file_views: File View
files: Files deposited
heading: Your Statistics
joined_on: Joined on
Expand Down
Loading