Skip to content

Commit

Permalink
Fix: Google Analytics 4 tag (#424)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
syphax-bouazzouni authored Dec 28, 2023
1 parent d18a700 commit b498460
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 66 deletions.
7 changes: 2 additions & 5 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions app/views/application/_ga_tracking.html.haml
Original file line number Diff line number Diff line change
@@ -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 async src="https://www.googletagmanager.com/gtag/js?id=#{tag_id}"></script>
%script
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', '#{$ANALYTICS_ID}', 'auto');
ga('send', 'pageview');
<script async src='https://www.google-analytics.com/analytics.js'></script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());


gtag('config', '#{tag_id}');
1 change: 0 additions & 1 deletion app/views/layouts/_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@


= javascript_include_tag "application"
= render partial: "ga_tracking"
1 change: 1 addition & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <%="xml:lang=\"#{I18n.locale}\""%> lang="<%=I18n.locale%>">
<head>
<%= render partial: 'ga_tracking' %>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />

<!-- Force IE to use latest rendering engine -->
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/appliance.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
!!! Strict
%html
%head
= render partial: 'ga_tracking'
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta name="turbo-cache-control" content="no-cache">

Expand Down
53 changes: 0 additions & 53 deletions app/views/layouts/minimal.html.erb

This file was deleted.

1 change: 1 addition & 0 deletions app/views/layouts/popup.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="background: none !important;">
<head>
<%= render partial: "ga_tracking" %>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta name="google-site-verification" content="IBxfKu6VbYH9atd5OLu2zXVD2ZRWi9SgMKTi8nvw3ks" />
Expand Down

0 comments on commit b498460

Please sign in to comment.