Skip to content

Commit

Permalink
Merge pull request #3339 from alphagov/global-bar-ga4-tracking
Browse files Browse the repository at this point in the history
Add GA4 tracking to global bar
  • Loading branch information
AshGDS authored May 31, 2024
2 parents 0668db3 + 1c41f72 commit a319c22
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/views/components/_global_bar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@
title_classes = %w(global-bar-title)
title_classes << "js-call-to-action" if title_href
title_classes << "govuk-link" if title_href

ga4_data = {
event_name: "navigation",
type: "global bar",
section: title,
}.to_json

-%>

<% if show_global_bar %>
<!--[if gt IE 7]><!-->
<div id="global-bar" class="<%= global_bar_classes.join(' ') %>" data-module="global-bar" <%= "data-global-bar-permanent=true" if always_visible %> data-nosnippet>
<div id="global-bar" class="<%= global_bar_classes.join(' ') %>" data-ga4-global-bar data-module="global-bar" <%= "data-global-bar-permanent=true" if always_visible %> data-nosnippet>
<p class="global-bar-message govuk-width-container">
<% if title %>
<% if title_href %>
<a class="<%= title_classes.join(' ') %>" href="<%= title_href %>"><%= title %></a>
<a class="<%= title_classes.join(' ') %>" href="<%= title_href %>" data-module="ga4-link-tracker" data-ga4-link="<%= ga4_data %>"><%= title %></a>
<% else %>
<span class="<%= title_classes.join(' ') %>"><%= title %></span>
<% end %>
Expand All @@ -37,7 +44,11 @@
link_text,
link_href,
rel: "external noreferrer",
class: "govuk-link js-call-to-action"
class: "govuk-link js-call-to-action",
data: {
module: "ga4-link-tracker",
ga4_link: ga4_data,
},
) %>
<% else %>
<%= link_text %>
Expand Down

0 comments on commit a319c22

Please sign in to comment.