Skip to content

Commit

Permalink
Previous/next enable GA4 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
andysellick committed Nov 15, 2023
1 parent 077cf96 commit de2d6d4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<%
add_gem_component_stylesheet("previous-and-next-navigation")
ga4_tracking ||= false
disable_ga4 ||= false

if local_assigns.include?(:next_page) || local_assigns.include?(:previous_page)
%>
<nav
class="govuk-pagination govuk-pagination--block"
role="navigation"
aria-label="<%= t("components.previous_and_next_navigation.pagination") %>"
<% if ga4_tracking %>
<% unless disable_ga4 %>
data-module="ga4-link-tracker"
<% end %>
>
Expand All @@ -27,7 +27,7 @@
data-track-label="<%= previous_page[:url] %>"
data-track-dimension="previous"
data-track-dimension-index="29"
<% if ga4_tracking %>
<% unless disable_ga4 %>
data-ga4-link = "<%= {
event_name: "navigation",
type: "previous and next",
Expand Down Expand Up @@ -63,7 +63,7 @@
data-track-label="<%= next_page[:url] %>"
data-track-dimension="next"
data-track-dimension-index="29"
<% if ga4_tracking %>
<% unless disable_ga4 %>
data-ga4-link = "<%= {
event_name: "navigation",
type: "previous and next",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ examples:
url: next-page
title: Next
label: 'Driver CPC part 1 test: theory'
with_ga4_tracking:
description: Enables the GA4 link tracker on the links.
without_ga4_tracking:
description: Disables the GA4 link tracker on the links. Tracking is enabled by default.
data:
ga4_tracking: true
disable_ga4: true
previous_page:
url: previous-page
title: Previous
Expand Down
21 changes: 19 additions & 2 deletions spec/components/previous_and_next_navigation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def component_name
assert_select ".govuk-pagination__next .govuk-pagination__link .govuk-visually-hidden", false
end

it "adds GA4 tracking when ga4_tracking is true" do
it "includes GA4 tracking" do
render_component(
previous_page: {
url: "previous-page",
Expand All @@ -78,7 +78,6 @@ def component_name
url: "next-page",
title: "Next page",
},
ga4_tracking: true,
)

assert_select ".govuk-pagination" do |pagination|
Expand Down Expand Up @@ -108,6 +107,24 @@ def component_name
end
end

it "allows GA4 tracking to be disabled" do
render_component(
disable_ga4: true,
previous_page: {
url: "previous-page",
title: "Previous page",
},
next_page: {
url: "next-page",
title: "Next page",
},
)

assert_select ".govuk-pagination[data-module='ga4-link-tracker']", false
assert_select ".govuk-pagination__prev a[data-ga4-link]", false
assert_select ".govuk-pagination__next a[data-ga4-link]", false
end

def assert_link(link)
assert_select "a[href=\"#{link}\"]"
end
Expand Down

0 comments on commit de2d6d4

Please sign in to comment.