Skip to content

Commit

Permalink
hide-per-tenant-analytics-on-prod (#579)
Browse files Browse the repository at this point in the history
* use the default analytics as a default on prod only.

the per tenant analytics work was already merged to main and the defaults were hidden on staging. however, pals wants to hold off on deploying that code to production until the ga4 switch has happened so both major changes can happen at the same time.

putting the analytics defaults in a conditional ensures that we can still deploy to production from main.

related to: #569

* rubocop fix
  • Loading branch information
alishaevn authored Jun 22, 2023
1 parent d828877 commit 4b75f3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
20 changes: 20 additions & 0 deletions app/models/concerns/account_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ def reload_library_config

def reload_analytics
# rubocop:disable Style/RedundantSelf
if Rails.env.production?
# fall back to the default values if they aren't set in the tenant
unless self.google_analytics_id.present? &&
self.google_oauth_app_name.present? &&
self.google_oauth_app_version.present? &&
(self.google_oauth_private_key_value.present? || self.google_oauth_private_key_path.present?) &&
self.google_oauth_private_key_secret.present? &&
self.google_oauth_client_email.present?

config = Hyrax::Analytics::Config.load_from_yaml
self.google_analytics_id = self.google_analytics_id.presence || config.analytics_id
self.google_oauth_app_name = self.google_oauth_app_name.presence || config.app_name
self.google_oauth_app_version = self.google_oauth_app_version.presence || config.app_version
self.google_oauth_private_key_value = self.google_oauth_private_key_value.presence || config.privkey_value
self.google_oauth_private_key_path = self.google_oauth_private_key_path.presence || config.privkey_path
self.google_oauth_private_key_secret = self.google_oauth_private_key_secret.presence || config.privkey_secret
self.google_oauth_client_email = self.google_oauth_client_email.presence || config.client_email
end
end

# require the analytics to be set per tenant
Hyrax::Analytics.config.analytics_id = self.google_analytics_id
Hyrax::Analytics.config.app_name = self.google_oauth_app_name
Expand Down
18 changes: 9 additions & 9 deletions config/analytics.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#
# To integrate your app with Google Analytics, uncomment the lines below and add your API key information.
#
# analytics:
# google:
# analytics_id: <%= ENV['GOOGLE_ANALYTICS_ID'] %>
# app_name: <%= ENV['GOOGLE_OAUTH_APP_NAME'] %>
# app_version: <%= ENV['GOOGLE_OAUTH_APP_VERSION'] %>
# privkey_value: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_VALUE'] %>
# # OR privkey_path: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_PATH'] %>
# privkey_secret: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_SECRET'] %>
# client_email: <%= ENV['GOOGLE_OAUTH_CLIENT_EMAIL'] %>
analytics:
google:
analytics_id: <%= ENV['GOOGLE_ANALYTICS_ID'] %>
app_name: <%= ENV['GOOGLE_OAUTH_APP_NAME'] %>
app_version: <%= ENV['GOOGLE_OAUTH_APP_VERSION'] %>
privkey_value: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_VALUE'] %>
# OR privkey_path: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_PATH'] %>
privkey_secret: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_SECRET'] %>
client_email: <%= ENV['GOOGLE_OAUTH_CLIENT_EMAIL'] %>

0 comments on commit 4b75f3a

Please sign in to comment.