Skip to content

Commit 7fe0aea

Browse files
authored
Add Google Analytics 4 script (#791)
* feat: add google analytics 4 script * chore: add new variable in app.json * feat: move script logic to a partial
1 parent b9997e6 commit 7fe0aea

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ PUSHER_PORT="8888"
2828
PUSHER_WS_HOST="127.0.0.1"
2929
PUSHER_WS_PORT="45449"
3030
EARLY_V2_EMAIL="@codeminer42.com"
31+
GOOGLE_ANALYTICS_ID=

app.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
},
7676
"CLOUDINARY_UPLOAD_PRESET": {
7777
"required": true
78+
},
79+
"GOOGLE_ANALYTICS_ID": {
80+
"required": false
7881
}
7982
},
8083
"formation": {

app/views/layouts/application.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<%= stylesheet_link_tag "https://www.authy.com/form.authy.min.css" %>
1111
<%= stylesheet_link_tag "https://fonts.googleapis.com/css?family=Noto+Sans:400,700" %>
1212
<%= stylesheet_link_tag "https://use.fontawesome.com/releases/v5.5.0/css/all.css" %>
13+
<%= render 'shared/google_analytics'%>
1314
</head>
1415
<body class='<%= "board" if @layout_settings[:fluid] %>'
1516
data-page='<%= "#{params[:controller]}.#{params[:action]}" %>'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<% if ENV['GOOGLE_ANALYTICS_ID'] %>
2+
<!-- Global site tag (gtag.js) - Google Analytics -->
3+
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= ENV['GOOGLE_ANALYTICS_ID'] %>"></script>
4+
<script>
5+
window.dataLayer = window.dataLayer || [];
6+
function gtag(){dataLayer.push(arguments);}
7+
gtag('js', new Date());
8+
9+
gtag('config', '<%= ENV['GOOGLE_ANALYTICS_ID'] %>');
10+
</script>
11+
<% end %>

0 commit comments

Comments
 (0)