Skip to content

Commit

Permalink
Merge pull request #2251 from rdunlop/add_google_analytics_4
Browse files Browse the repository at this point in the history
add google analytics 4 tracking code
  • Loading branch information
rdunlop authored Nov 24, 2022
2 parents eb3e6e8 + 0efb864 commit ab3167a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

= csrf_meta_tags
= render "shared/analytics/google"
= render "shared/analytics/google_4"
/[if lt IE 7]
<style media="screen" type="text/css">
\#container {
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/error.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
= javascript_include_tag "application"
= csrf_meta_tags
= render "shared/analytics/google"
= render "shared/analytics/google_4"
/[if lt IE 7]
<style media="screen" type="text/css">
\#container {
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/global.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
= javascript_include_tag "application"
= csrf_meta_tags
= render "shared/analytics/google"
= render "shared/analytics/google_4"
/[if lt IE 7]
<style media="screen" type="text/css">
\#container {
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/minimal.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
= javascript_include_tag "application"
= csrf_meta_tags
= render "shared/analytics/google"
= render "shared/analytics/google_4"
/[if lt IE 7]
<style media="screen" type="text/css">
\#container {
Expand Down
11 changes: 11 additions & 0 deletions app/views/shared/analytics/_google_4.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% if Rails.configuration.google_analytics_4_tracking_id.present? %>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= Rails.configuration.google_analytics_4_tracking_id %>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '<%= Rails.configuration.google_analytics_4_tracking_id %>');
</script>
<% end %>
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Application < Rails::Application
config.recaptcha_minimum_score = ENV["RECAPTCHA_MINIMUM_SCORE"].presence

config.google_analytics_tracking_id = ENV["GOOGLE_ANALYTICS_TRACKING_ID"]
config.google_analytics_4_tracking_id = ENV["GOOGLE_ANALYTICS_4_TRACKING_ID"]

config.hcaptcha_site_key = ENV['HCAPTCHA_SITE_KEY']
config.hcaptcha_secret = ENV['HCAPTCHA_SECRET']
Expand Down

0 comments on commit ab3167a

Please sign in to comment.