Browse Source

CLDC-1620 Add Google Tag Manager scripts to layout

pull/964/head
Sam Collard 3 years ago
parent
commit
aa2e760ed2
  1. 35
      app/views/layouts/application.html.erb

35
app/views/layouts/application.html.erb

@ -21,6 +21,34 @@
</script>
<%= javascript_include_tag "vendor/polyfill-output-value.js" %>
<%= javascript_include_tag "vendor/outerHTML.js" %>
<% gtm_container = "GTM-M6GS7FF" %>
<% gtm_id = "G-1RH26G5KVP" %>
<!-- Google Tag Manager (doesn't store personal info until permission given) -->
<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=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<%= gtm_container %>');</script>
<!-- End Google Tag Manager -->
<% if cookies[:accept_analytics_cookies] == "on" %>
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= gtm_id %>"></script>
<% else %>
<script>
// For adding the script once the user has given permission
window.ecfAnalyticsScript = "https://www.googletagmanager.com/gtag/js?id=<%= gtm_id %>";
</script>
<% end %>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<%= gtm_id %>');
</script>
<%= javascript_include_tag "application", defer: true %>
<% if content_for?(:head) %>
@ -44,6 +72,13 @@
document.body.className = ((document.body.className) ? document.body.className + " js-enabled" : "js-enabled");
</script>
<!-- Google Tag Manager (noscript) -->
<% if cookies[:accept_analytics_cookies] %>
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=<% gtm_container %>" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<% end %>
<%= govuk_skip_link %>
<%= govuk_header(

Loading…
Cancel
Save