diff --git a/app/helpers/common_helper.rb b/app/helpers/common_helper.rb index 1d8317554cf..6e37098d2d8 100644 --- a/app/helpers/common_helper.rb +++ b/app/helpers/common_helper.rb @@ -5,9 +5,15 @@ module CommonHelper end end - def render_google_tag_manager_code + def render_google_tag_manager_head_code if 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" end end end diff --git a/app/views/common/_google_tag_manager_body.html.erb b/app/views/common/_google_tag_manager_body.html.erb new file mode 100644 index 00000000000..6c98df81176 --- /dev/null +++ b/app/views/common/_google_tag_manager_body.html.erb @@ -0,0 +1,4 @@ + + + diff --git a/app/views/common/_google_tag_manager.html.erb b/app/views/common/_google_tag_manager_head.html.erb similarity index 58% rename from app/views/common/_google_tag_manager.html.erb rename to app/views/common/_google_tag_manager_head.html.erb index 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 %>]; - + + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 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 %> @@ -60,8 +61,7 @@ - <%= render_google_tag_manager_code %> - + <%= render_google_tag_manager_body_code %>