A platform for community discussion. Free, open, simple.
FIX: update Google Tag Manager javascript
Neil Lalondeb7ecdb72d682
diff --git a/app/helpers/common_helper.rb b/app/helpers/common_helper.rbindex 1d8317554cf..6e37098d2d8 100644--- a/app/helpers/common_helper.rb+++ b/app/helpers/common_helper.rb@@ -5,9 +5,15 @@ module CommonHelperendend- def render_google_tag_manager_code+ def render_google_tag_manager_head_codeif Rails.env.production? && SiteSetting.gtm_container_id.present?- render partial: "common/google_tag_manager"+ render partial: "common/google_tag_manager_head"+ end+ end++ def render_google_tag_manager_body_code+ if Rails.env.production? && SiteSetting.gtm_container_id.present?+ render partial: "common/google_tag_manager_body"endendenddiff --git a/app/views/common/_google_tag_manager_body.html.erb b/app/views/common/_google_tag_manager_body.html.erbnew file mode 100644index 00000000000..6c98df81176--- /dev/null+++ b/app/views/common/_google_tag_manager_body.html.erb@@ -0,0 +1,4 @@+<!-- Google Tag Manager (noscript) -->+<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=<%= SiteSetting.gtm_container_id %>"+height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>+<!-- End Google Tag Manager (noscript) -->diff --git a/app/views/common/_google_tag_manager.html.erb b/app/views/common/_google_tag_manager_head.html.erbsimilarity index 58%rename from app/views/common/_google_tag_manager.html.erbrename to app/views/common/_google_tag_manager_head.html.erbindex dca75352a06..2320f2c7b02 100644--- a/app/views/common/_google_tag_manager.html.erb+++ b/app/views/common/_google_tag_manager_head.html.erb@@ -2,10 +2,10 @@dataLayer = [<%= google_tag_manager_json %>];</script>-<noscript><iframe src="//www.googletagmanager.com/ns.html?id=<%= SiteSetting.gtm_container_id %>"-height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>+<!-- Google Tag Manager --><script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=-'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);+'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','<%= SiteSetting.gtm_container_id %>');</script>+<!-- End Google Tag Manager -->diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erbindex 361466c3544..58fff0c1a15 100644--- a/app/views/layouts/application.html.erb+++ b/app/views/layouts/application.html.erb@@ -44,6 +44,7 @@<%= raw theme_lookup("head_tag") %><%- end %>+ <%= render_google_tag_manager_head_code %><%= render_google_universal_analytics_code %><link rel="manifest" href="<%= Discourse.base_uri %>/manifest.json">@@ -60,8 +61,7 @@</head><body class="<%= body_classes %>">- <%= render_google_tag_manager_code %>-+ <%= render_google_tag_manager_body_code %><noscript data-path="<%= request.env['PATH_INFO'] %>"><%= render partial: 'header' %><div id="main-outlet" class="wrap">