From b498460e296122807f36b52bb433dffc8eba58e3 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Fri, 29 Dec 2023 00:08:32 +0100 Subject: [PATCH] Fix: Google Analytics 4 tag (#424) * revert the change in ontologies_analytics to use last month analytics * Merge pull request #271 from ncbo/feature/ga4-migration/270 Universal Analytics -> Google Analytics 4 migration --- app/helpers/application_helper.rb | 7 +-- app/views/application/_ga_tracking.html.haml | 15 +++--- app/views/layouts/_footer.html.haml | 1 - app/views/layouts/_header.html.erb | 1 + app/views/layouts/appliance.html.haml | 1 + app/views/layouts/minimal.html.erb | 53 -------------------- app/views/layouts/popup.html.erb | 1 + 7 files changed, 13 insertions(+), 66 deletions(-) delete mode 100644 app/views/layouts/minimal.html.erb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c29cd7c35..6127033f9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -25,11 +25,8 @@ module ApplicationHelper def ontologies_analytics - LinkedData::Client::Analytics.all.to_h.map do |key, ontology_analytics| - next if key.eql?(:links) || key.eql?(:context) - - [key.to_s, ontology_analytics.to_h.values.map { |x| x&.values }.flatten.compact.sum] - end.compact.to_h + data = LinkedData::Client::Analytics.last_month.onts + data.map{|x| [x[:ont].to_s, x[:views]]}.to_h end def get_apikey diff --git a/app/views/application/_ga_tracking.html.haml b/app/views/application/_ga_tracking.html.haml index 73308e4cd..405f77c2b 100644 --- a/app/views/application/_ga_tracking.html.haml +++ b/app/views/application/_ga_tracking.html.haml @@ -1,9 +1,10 @@ --# Google Analytics -- unless $ANALYTICS_ID.nil? || $ANALYTICS_ID.empty? +-# Google tag +- tag_id = Rails.application.credentials.dig(:google_analytics, :tag_id) || $ANALYTICS_ID +- if tag_id.present? + %script - window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; - ga('create', '#{$ANALYTICS_ID}', 'auto'); - ga('send', 'pageview'); - + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); - \ No newline at end of file + gtag('config', '#{tag_id}'); \ No newline at end of file diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 4c582f1de..9d8908961 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -28,4 +28,3 @@ = javascript_include_tag "application" -= render partial: "ga_tracking" diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index b58dfe440..fcf060a9e 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -1,6 +1,7 @@ lang="<%=I18n.locale%>"> + <%= render partial: 'ga_tracking' %> diff --git a/app/views/layouts/appliance.html.haml b/app/views/layouts/appliance.html.haml index dff0e0108..817bd3026 100644 --- a/app/views/layouts/appliance.html.haml +++ b/app/views/layouts/appliance.html.haml @@ -1,6 +1,7 @@ !!! Strict %html %head + = render partial: 'ga_tracking' diff --git a/app/views/layouts/minimal.html.erb b/app/views/layouts/minimal.html.erb deleted file mode 100644 index 99fe12457..000000000 --- a/app/views/layouts/minimal.html.erb +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - <%= csrf_meta_tag %> - <%if @title.nil?%><%=$ORG_SITE%><%else%><%="#{@title} | #{$ORG_SITE}"%><%end%> - - - <%= stylesheet_link_tag "https://use.fontawesome.com/releases/v5.2.0/css/all.css", integrity: "sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ", crossorigin: "anonymous" %> - <%= stylesheet_link_tag "application" %> - <%=render partial: 'layouts/js_data'%> - <%=render partial: 'layouts/head_js'%> - - - -
- - <%if flash[:notice] %> -
-

- <%=flash[:notice] %> -

-
- <%end %> - -
- <% message_name = "" %> - <% unless $SITE_NOTICE.nil? || $SITE_NOTICE.empty? %> - <% $SITE_NOTICE.each_key { |k| message_name = k } %> - <% unless cookies[message_name.to_sym].eql?("true") %> - -
- <%=$SITE_NOTICE[message_name.to_sym]%>  [close] -
- <% end %> - <% end %> - - <%=yield%> -
- - - - diff --git a/app/views/layouts/popup.html.erb b/app/views/layouts/popup.html.erb index 86a2b772e..7262ec44f 100644 --- a/app/views/layouts/popup.html.erb +++ b/app/views/layouts/popup.html.erb @@ -1,6 +1,7 @@ + <%= render partial: "ga_tracking" %>