diff --git a/.env_deployment_sample b/.env_deployment_sample index fd1a36ac8..da100764c 100644 --- a/.env_deployment_sample +++ b/.env_deployment_sample @@ -8,6 +8,9 @@ SECRET_KEY_BASE=33d83bc35b707a1f70ac9475cdaabd4224fca0d3edc07e0ce6db13515d1c1e3a SAML_PRIVATE_KEY= SAML_CERTIFICATE= ROLLBAR_TOKEN= +GOOGLE_ANALYTICS_TOKEN= +MATOMO_URL= +MATOMO_SITE_ID= # Postgres environment variables PGDATA=/var/lib/postgresql/data/pgdata diff --git a/app/assets/javascripts/jupiter/analytics.js.erb b/app/assets/javascripts/jupiter/analytics.js.erb new file mode 100644 index 000000000..a4ee447e3 --- /dev/null +++ b/app/assets/javascripts/jupiter/analytics.js.erb @@ -0,0 +1,12 @@ +$(document).on('turbolinks:load', function() { + // Google Analytics + if (typeof gtag === 'function') { + return gtag('config', '<%= Rails.application.secrets.google_analytics_token %>', { + 'page_path': window.location.pathname + }); + } + // Matomo Analytics + if (window._paq != null) { + return _paq.push(['trackPageView']); + } +}); diff --git a/app/views/application/_analytics.html.erb b/app/views/application/_analytics.html.erb new file mode 100644 index 000000000..17348185a --- /dev/null +++ b/app/views/application/_analytics.html.erb @@ -0,0 +1,34 @@ + <% if Rails.application.secrets.google_analytics_token.present? %> + + + + +<% end %> + +<% if Rails.application.secrets.matomo_url.present? && Rails.application.secrets.matomo_site_id.present? %> + + + + + + + +<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 143784362..209f05208 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -22,6 +22,8 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= render partial: 'analytics' %> + <%= yield(:head) %> diff --git a/config/secrets.yml b/config/secrets.yml index 457091589..ba155e55f 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -25,6 +25,9 @@ shared: ezid_default_shoulder: <%= ENV['EZID_DEFAULT_SHOULDER'] %> ezid_user: <%= ENV['EZID_USER'] %> ezid_password: <%= ENV['EZID_PASSWORD'] %> + google_analytics_token: <%= ENV['GOOGLE_ANALYTICS_TOKEN'] %> + matomo_url: <%= ENV['MATOMO_URL'] %> + matomo_site_id: <%= ENV['MATOMO_SITE_ID'] %> development: secret_key_base: c0a4bf2c5890d0fa86e1459dd189bc4c5a02f412067b610490885c8c312bf0cea5d988e075761ba7277a8291041c1b2e7cf6c373d4d6f43d4522bc48db76cc1a