Skip to content

Commit

Permalink
Remove GA4 callout tracking from notice & warning text components
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS committed Mar 22, 2024
1 parent 1c7402e commit a486fb0
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 63 deletions.
Expand Up @@ -25,27 +25,15 @@
aria_attributes[:labelledby] = banner_title_id if show_banner_title

description_present = description.present? || description_text.present? || description_govspeak.present?
disable_ga4 ||= false

if description_govspeak
govspeak_data_attributes = {
content: description_govspeak,
}
end

unless disable_ga4
section_data_attributes = {
module: "ga4-link-tracker",
ga4_track_links_only: "",
ga4_link: {
event_name: "navigation",
type: "callout"
}.to_json
}
end
%>
<% if title || description_present %>
<%= tag.section class: css_classes, aria: aria_attributes, lang: lang, role: "region", data: section_data_attributes do %>
<%= tag.section class: css_classes, aria: aria_attributes, lang: lang, role: "region" do %>
<%= tag.div class: "govuk-notification-banner__header" do %>
<%= tag.h2 banner_title, class: "govuk-notification-banner__title", id: banner_title_id %>
<% end if show_banner_title %>
Expand Down
Expand Up @@ -14,18 +14,9 @@
text_classes << "gem-c-warning-text__text--no-indent" if text_icon.empty?
text_classes << "gem-c-warning-text__text--large" if large_font
text_classes << "gem-c-warning-text__text--highlight" if highlight_text

disable_ga4 ||= false

ga4_data_attributes = {
"module": "ga4-link-tracker",
"ga4-track-links-only": "",
"ga4-link": { "event_name": "navigation", "type": "callout" }.to_json
} unless disable_ga4

%>
<%= tag.div id: id, class: "gem-c-warning-text govuk-warning-text", data: ga4_data_attributes do %>
<%= tag.div id: id, class: "gem-c-warning-text govuk-warning-text" do %>
<% unless text_icon.empty? %>
<%= tag.span text_icon, class: "govuk-warning-text__icon", "aria-hidden": "true" %>
<% end %>
Expand Down
26 changes: 0 additions & 26 deletions spec/components/notice_spec.rb
Expand Up @@ -103,30 +103,4 @@ def component_name
assert_select ".gem-c-notice h2.govuk-notification-banner__title", text: "Notice"
assert_select "h3.gem-c-notice__title", text: "Your settings have been saved"
end

it "has GA4 tracking enabled on the component, and disabled on the nested govspeak render" do
render_component(title: "Title", description_govspeak: "<marquee>It's 1998</marquee>".html_safe)

assert_select ".gem-c-notice[data-module='ga4-link-tracker']"
assert_select ".gem-c-notice[data-ga4-track-links-only]"
assert_select '.gem-c-notice[data-ga4-link="{\"event_name\":\"navigation\",\"type\":\"callout\"}"]'

assert_no_selector ".gem-c-govspeak[data-module='govspeak ga4-link-tracker']"
assert_no_selector ".gem-c-govspeak[data-ga4-track-links-only]"
assert_no_selector ".gem-c-govspeak[data-ga4-limit-to-element-class='call-to-action, info-notice, help-notice, advisory']"
assert_no_selector '.gem-c-govspeak[data-ga4-link="{\"event_name\":\"navigation\",\"type\":\"callout\"}"]'
end

it "can have GA4 tracking disabled" do
render_component(title: "Title", description_govspeak: "<marquee>It's 1998</marquee>".html_safe)

assert_no_selector ".gem-c-notice[data-module='ga4-link-tracker']"
assert_no_selector ".gem-c-notice[data-ga4-track-links-only]"
assert_no_selector '.gem-c-notice[data-ga4-link="{\"event_name\":\"navigation\",\"type\":\"callout\"}"]'

assert_no_selector ".gem-c-govspeak[data-module='govspeak ga4-link-tracker']"
assert_no_selector ".gem-c-govspeak[data-ga4-track-links-only]"
assert_no_selector ".gem-c-govspeak[data-ga4-limit-to-element-class='call-to-action, info-notice, help-notice, advisory']"
assert_no_selector '.gem-c-govspeak[data-ga4-link="{\"event_name\":\"navigation\",\"type\":\"callout\"}"]'
end
end
14 changes: 0 additions & 14 deletions spec/components/warning_text_spec.rb
Expand Up @@ -48,18 +48,4 @@ def component_name
assert_select("h1.govuk-warning-text__text", text: /Because/i)
assert_select("h1.govuk-warning-text__text .govuk-warning-text__assistive", text: /Warning/i)
end

it "has GA4 link tracking" do
render_component(text: "Because", heading_level: 1)
assert_select("[data-module='ga4-link-tracker']")
assert_select('[data-ga4-link="{\"event_name\":\"navigation\",\"type\":\"callout\"}"]')
assert_select("[data-ga4-track-links-only]")
end

it "can disable GA4 link tracking" do
render_component(disable_ga4: true, text: "Because", heading_level: 1)
assert_select("[data-module='ga4-link-tracker']", false)
assert_select('[data-ga4-link="{\"event_name\":\"navigation\",\"type\":\"callout\"}"]', false)
assert_select("[data-ga4-track-links-only]", false)
end
end

0 comments on commit a486fb0

Please sign in to comment.