Skip to content

Commit

Permalink
Merge pull request #1286 from alphagov/update-gtm
Browse files Browse the repository at this point in the history
Don't use GTM from govuk_publishing_components until we can upgrade
  • Loading branch information
MahmudH authored Jul 17, 2024
2 parents dddb809 + cc03f68 commit cc91ade
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gem "elasticsearch-rails", "~> 7.2.1"
gem "faraday"
gem "faraday_middleware"
gem "govuk_elements_rails"
gem "govuk_publishing_components", "~> 28.7.1"
gem "govuk_publishing_components", "~> 28.7.1" # TODO: Revert https://github.com/alphagov/datagovuk_find/pull/1286 once 39.2.3+
gem "htmlentities"
gem "jbuilder"
gem "jquery-rails"
Expand Down
22 changes: 17 additions & 5 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
<html class="govuk-template">
<head>
<% if ENV["GOOGLE_TAG_MANAGER_ID"] %>
<%= render "govuk_publishing_components/components/google_tag_manager_script", {
gtm_id: ENV["GOOGLE_TAG_MANAGER_ID"],
gtm_auth: ENV["GOOGLE_TAG_MANAGER_AUTH"],
gtm_preview: ENV["GOOGLE_TAG_MANAGER_PREVIEW"]
} %>
<%
gtm_auth = ENV["GOOGLE_TAG_MANAGER_AUTH"]
gtm_preview = ENV["GOOGLE_TAG_MANAGER_PREVIEW"]

gtm_attributes = []
gtm_attributes << "gtm_auth=" + gtm_auth if gtm_auth
gtm_attributes << "gtm_preview=#{gtm_preview}&gtm_cookies_win=x" if gtm_preview
gtm_attributes = gtm_attributes.join('&')
%>
<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+'&<%= raw gtm_attributes %>';f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<%= ENV["GOOGLE_TAG_MANAGER_ID"] %>');
</script>
<% end %>

<script>
<% if Rails.application.config.analytics_tracking_id.present? %>
var analyticsInit = function() {
Expand Down

0 comments on commit cc91ade

Please sign in to comment.