Skip to content

Commit 9ba9b11

Browse files
committed
Add GA4 tracking to the banner component
1 parent dd69bf5 commit 9ba9b11

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

app/views/components/_banner.html.erb

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
<%= text %>
1313
</p>
1414
<% end %>
15-
<section class="app-c-banner<% if aside %> app-c-banner--aside<% end %>" aria-label="Notice" lang="en">
15+
<section
16+
class="app-c-banner<% if aside %> app-c-banner--aside<% end %>"
17+
aria-label="Notice"
18+
lang="en"
19+
data-module="ga4-link-tracker"
20+
data-ga4-track-links-only
21+
data-ga4-link="<%= { event_name: "navigation", type: "callout" }.to_json %>">
1622
<%= content_block %>
1723
<% if aside %>
1824
<p class="app-c-banner__desc"><%= aside %></p>

test/components/banner_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ def component_name
4343
assert_select ".app-c-banner__desc", text: "This was published under the 2010 to 2015 Conservative government"
4444
assert_select ".app-c-banner__desc", text: "This consultation ran from 9:30am on 30 January 2017 to 5pm on 28 February 2017"
4545
end
46+
47+
test "renders a banner with GA4 tracking" do
48+
render_component(
49+
title: "Summary",
50+
text: "This was published under the 2010 to 2015 Conservative government",
51+
aside: "This consultation ran from 9:30am on 30 January 2017 to 5pm on 28 February 2017",
52+
)
53+
54+
assert_select ".app-c-banner--aside[data-module=ga4-link-tracker]"
55+
assert_select ".app-c-banner--aside[data-ga4-track-links-only]"
56+
assert_select ".app-c-banner--aside[data-ga4-link='{\"event_name\":\"navigation\",\"type\":\"callout\"}']"
57+
end
4658
end

0 commit comments

Comments
 (0)