Skip to content

Commit 671dd75

Browse files
grahampaulcookeddgrant
authored andcommitted
TRG-317: Provide support for Google Tag Manager
This is a cherry-pick of 63b2a30 from grahampaulcook/tech-docs-gem which introduces support for Google Tag Manager. A pull request has been raised to include this change: alphagov#187 however GDS have not yet picked it up, so we're pulling it in here for use at HMRC in the meantime.
1 parent 4f8e20e commit 671dd75

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<% if config[:tech_docs][:gtm_id].is_a?(String) && !config[:tech_docs][:gtm_id].empty? %>
2+
<script>
3+
(function(w,d,s,l,i){
4+
w[l]=w[l]||[];
5+
w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});
6+
var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';
7+
j.async=true;
8+
j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;
9+
f.parentNode.insertBefore(j,f);
10+
})(window,document,'script','dataLayer','<%= config[:tech_docs][:gtm_id] %>');
11+
</script>
12+
<% end %>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<% if config[:tech_docs][:gtm_id].is_a?(String) && !config[:tech_docs][:gtm_id].empty? %>
2+
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=<%= config[:tech_docs][:gtm_id] %>"
3+
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
4+
<% end %>

lib/source/layouts/core.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
<%= tag :meta, property: property, content: content %>
2020
<% end %>
2121

22+
<%= partial 'layouts/google_tag_manager_js' %>
2223
<%= yield_content :head %>
2324
</head>
2425

2526
<body class="govuk-template__body">
27+
<%= partial 'layouts/google_tag_manager_non_js' %>
2628
<script>document.body.className = ((document.body.className) ? document.body.className + ' js-enabled' : 'js-enabled');</script>
2729

2830
<div class="app-pane">

0 commit comments

Comments
 (0)