Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GA4 tracking to the banner component #3102

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/views/components/_banner.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
<%= text %>
</p>
<% end %>
<section class="app-c-banner<% if aside %> app-c-banner--aside<% end %>" aria-label="Notice" lang="en">
<section
class="app-c-banner<% if aside %> app-c-banner--aside<% end %>"
aria-label="Notice"
lang="en"
data-module="ga4-link-tracker"
data-ga4-track-links-only
data-ga4-link="<%= { event_name: "navigation", type: "callout" }.to_json %>">
<%= content_block %>
<% if aside %>
<p class="app-c-banner__desc"><%= aside %></p>
Expand Down
12 changes: 12 additions & 0 deletions test/components/banner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ def component_name
assert_select ".app-c-banner__desc", text: "This was published under the 2010 to 2015 Conservative government"
assert_select ".app-c-banner__desc", text: "This consultation ran from 9:30am on 30 January 2017 to 5pm on 28 February 2017"
end

test "renders a banner with GA4 tracking" do
render_component(
title: "Summary",
text: "This was published under the 2010 to 2015 Conservative government",
aside: "This consultation ran from 9:30am on 30 January 2017 to 5pm on 28 February 2017",
)

assert_select ".app-c-banner--aside[data-module=ga4-link-tracker]"
assert_select ".app-c-banner--aside[data-ga4-track-links-only]"
assert_select ".app-c-banner--aside[data-ga4-link='{\"event_name\":\"navigation\",\"type\":\"callout\"}']"
end
end
Loading