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

Switch from trackClick to gemTrackClick script #1944

Merged
merged 2 commits into from
Feb 25, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## Unreleased

* Switch from `trackClick` to `gemTrackClick` script ([PR #1944](https://github.com/alphagov/govuk_publishing_components/pull/1944))
* Add spacing to cookie banner confirmation message ([PR #1936](https://github.com/alphagov/govuk_publishing_components/pull/1936))
* Fix Sass warning for extending a compound selector ([PR #1933](https://github.com/alphagov/govuk_publishing_components/pull/1933))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<%= raw JSON.pretty_generate(breadcrumb_presenter.structured_data) %>
</script>

<div class="<%= classes %>" data-module="track-click">
<div class="<%= classes %>" data-module="gem-track-click">
<ol class="govuk-breadcrumbs__list">
<% breadcrumbs.each_with_index do |crumb, index| %>
<% breadcrumb = GovukPublishingComponents::Presenters::Breadcrumb.new(crumb, index) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"aria-label": aria_label,
role: "navigation",
data: {
module: "track-click"
module: "gem-track-click"
}
) do %>
<%= content_tag(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
text = raw(text)

cookie_preferences_href ||= "/help/cookies"
confirmation_message ||= raw("You can <a class='govuk-link' href='#{cookie_preferences_href}' data-module='track-click' data-track-category='cookieBanner' data-track-action='Cookie banner settings clicked from confirmation'>change your cookie settings</a> at any time.")
confirmation_message ||= raw("You can <a class='govuk-link' href='#{cookie_preferences_href}' data-module='gem-track-click' data-track-category='cookieBanner' data-track-action='Cookie banner settings clicked from confirmation'>change your cookie settings</a> at any time.")
services_cookies ||= nil
css_classes = %w(gem-c-cookie-banner govuk-clearfix)
css_classes << "gem-c-cookie-banner--services" if services_cookies
Expand All @@ -35,12 +35,12 @@
<%= render "govuk_publishing_components/components/button", {
name: "cookies",
text: services_cookies.dig(:yes, :text) || "Yes",
data_attributes: { module: "track-click", "accept-cookies": "true", }.merge(services_cookies.dig(:yes, :data_attributes) || {})
data_attributes: { module: "gem-track-click", "accept-cookies": "true", }.merge(services_cookies.dig(:yes, :data_attributes) || {})
} %>
<%= render "govuk_publishing_components/components/button", {
name: "cookies",
text: services_cookies.dig(:no, :text) || "No",
data_attributes: { module: "track-click", "reject-cookies": "true", }.merge(services_cookies.dig(:no, :data_attributes) || {})
data_attributes: { module: "gem-track-click", "reject-cookies": "true", }.merge(services_cookies.dig(:no, :data_attributes) || {})
} %>
<% if services_cookies[:cookie_preferences] %>
<%= link_to services_cookies.dig(:cookie_preferences, :text), services_cookies.dig(:cookie_preferences, :href), class: "govuk-link" %>
Expand All @@ -52,7 +52,7 @@
name: "cookies",
text: "Accept additional cookies",
data_attributes: {
module: "track-click",
module: "gem-track-click",
"accept-cookies": "true",
"track-category": "cookieBanner",
"track-action": "Cookie banner accepted",
Expand All @@ -63,7 +63,7 @@
name: "cookies",
text: "Reject additional cookies",
data_attributes: {
module: "track-click",
module: "gem-track-click",
"reject-cookies": "true",
"track-category": "cookieBanner",
"track-action": "Cookie banner rejected",
Expand All @@ -77,7 +77,7 @@
<div class="gem-c-cookie-banner__confirmation govuk-width-container" tabindex="-1" hidden>
<p class="gem-c-cookie-banner__confirmation-message" role="alert"><%= confirmation_message %></p>
<div class="govuk-button-group">
<button class="gem-c-cookie-banner__hide-button govuk-button" data-hide-cookie-banner="true" data-module="track-click" data-track-category="cookieBanner" data-track-action="Hide cookie banner">Hide this message</button>
<button class="gem-c-cookie-banner__hide-button govuk-button" data-hide-cookie-banner="true" data-module="gem-track-click" data-track-category="cookieBanner" data-track-action="Hide cookie banner">Hide this message</button>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%>
<% if items.any? %>
<% unless within_multitype_list %>
<ol class="gem-c-highlight-boxes" <%= "data-module=track-click" if highlight_boxes_helper.data_tracking? %>>
<ol class="gem-c-highlight-boxes" <%= "data-module=gem-track-click" if highlight_boxes_helper.data_tracking? %>>
<% end %>
<% items.each do |content_item| %>
<li class="gem-c-highlight-boxes__item-wrapper <%= half_width_class %>">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%>
<% if card_helper.href || card_helper.extra_links.any? %>
<div class="<%= classes %> <%= brand_helper.brand_class %>"
<%= "data-module=track-click" if card_helper.is_tracking? %>
<%= "data-module=gem-track-click" if card_helper.is_tracking? %>
<%= "lang=#{card_helper.lang}" if card_helper.lang %>>
<div class="gem-c-image-card__text-wrapper">
<div class="gem-c-image-card__header-and-context-wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
classes << "gem-c-metadata--inverse" if inverse
%>
<%= content_tag :div, class: classes, data: { module: "gem-toggle" } do %>
<dl data-module="track-click">
<dl data-module="gem-track-click">
<% if from.any? %>
<dt class="gem-c-metadata__term"><%= t("govuk_component.metadata.from", default: "From") %>:</dt>
<dd class="gem-c-metadata__definition">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
%>
<<%= wrapping_element %>
class="<%= wrapper_classes.join(" ") %>"
<%= "data-module=track-click" if organisation[:data_attributes] %>
<%= "data-module=gem-track-click" if organisation[:data_attributes] %>
>
<% if organisation[:url] %>
<%= link_to organisation[:url],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
role="navigation"
aria-label="<%= t("govuk_component.previous_and_next_navigation.pagination", default: "Pagination") %>"
>
<ul class="gem-c-pagination__list" data-module="track-click">
<ul class="gem-c-pagination__list" data-module="gem-track-click">
<% if local_assigns.include?(:previous_page) %>
<li class="gem-c-pagination__item gem-c-pagination__item--previous">
<a href="<%= previous_page[:url] %>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
classes << brand_helper.brand_class

data_attributes ||= {}
data_attributes[:module] = 'track-click'
data_attributes[:module] = 'gem-track-click'
%>
<% if links.any? %>
<%= tag.div(class: classes, data: data_attributes) do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<%= raw JSON.pretty_generate(breadcrumb_presenter.structured_data) %>
</script>

<h2 class="<%= classes %>" data-module="track-click">
<h2 class="<%= classes %>" data-module="gem-track-click">
<span class="gem-c-step-nav-header__part-of">Part of</span>
<% if path %>
<a href="<%= path %>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<% if links.any? %>
<div
class="gem-c-step-nav-related <%= "gem-c-step-nav-related--singular" if links.length == 1 %>"
data-module="track-click">
data-module="gem-track-click">
<h2 class="gem-c-step-nav-related__heading">
<span class="gem-c-step-nav-related__pretitle"><%= pretitle %></span>
<% if links.length == 1 && !always_display_as_list %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<% end %>
<ul
class="gem-c-subscription-links__list<%= ' gem-c-subscription-links__list--small' if local_assigns[:small_form] == true %>"
<%= "data-module=track-click" if sl_helper.tracking_is_present? %>
<%= "data-module=gem-track-click" if sl_helper.tracking_is_present? %>
>
<% if sl_helper.email_signup_link.present? %>
<li class="gem-c-subscription-links__list-item<%= ' gem-c-subscription-links__list-item--small' if local_assigns[:small_form] == true %>" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
taxonomy_list_helper = GovukPublishingComponents::Presenters::TaxonomyListHelper.new(image_cards)
%>
<% if highlight_box || document_list || image_cards %>
<ul class="gem-c-taxonomy-list" data-module="track-click">
<ul class="gem-c-taxonomy-list" data-module="gem-track-click">
<% if image_cards %>
<% taxonomy_list_helper.image_card_data.each do |image_card| %>
<li class="gem-c-taxonomy-list__item">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<nav role="navigation"
class="gem-c-translation-nav <%= translation_helper.classes %> <%= brand_helper.brand_class %>"
aria-label="<%= t("common.translations") %>"
<%= "data-module=\"track-click\"" if translation_helper.tracking_is_present? %>
<%= "data-module=\"gem-track-click\"" if translation_helper.tracking_is_present? %>
>
<ul class="gem-c-translation-nav__list">
<% translation_helper.translations.each.with_index do |translation, i| %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% link_path = t("components.related_navigation.transition.link_path") %>

<% data_attributes = {
"module": "track-click",
"module": "gem-track-click",
"track-category": "relatedLinkClicked",
"track-action": "1.0 Transition",
"track-label": link_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ examples:
data:
padding_top: false
block: |
<div class="gem-c-breadcrumbs " data-module="track-click">
<div class="gem-c-breadcrumbs " data-module="gem-track-click">
<ol>
<li class="">
<a data-track-category="breadcrumbClicked" data-track-action="1" data-track-label="/section" data-track-options="{&quot;dimension28&quot;:&quot;2&quot;,&quot;dimension29&quot;:&quot;Section&quot;}" class="gem-c-breadcrumbs--inverse" aria-current="false" href="/section">Section</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
%>
<% end %>

<ul class="gem-c-related-navigation__link-list" data-module="track-click">
<ul class="gem-c-related-navigation__link-list" data-module="gem-track-click">
<% constructed_link_array = [] %>

<% section_link_limit = related_nav_helper.calculate_section_link_limit(links) %>
Expand Down
4 changes: 2 additions & 2 deletions spec/components/breadcrumbs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def assert_link_with_text_in(selector, link, text)
dimension29: "Section",
}

assert_select '.gem-c-breadcrumbs[data-module="track-click"]', 1
assert_select '.gem-c-breadcrumbs[data-module="gem-track-click"]', 1
assert_select '.govuk-breadcrumbs__list-item:first-child a[data-track-action="1"]', 1
assert_select '.govuk-breadcrumbs__list-item:first-child a[data-track-label="/section"]', 1
assert_select '.govuk-breadcrumbs__list-item:first-child a[data-track-category="breadcrumbClicked"]', 1
Expand All @@ -75,7 +75,7 @@ def assert_link_with_text_in(selector, link, text)
dimension29: "Section",
}

assert_select '.gem-c-breadcrumbs[data-module="track-click"]', 1
assert_select '.gem-c-breadcrumbs[data-module="gem-track-click"]', 1

assert_select '.govuk-breadcrumbs__list-item:nth-child(1) a[data-track-action="1"]', 1
assert_select '.govuk-breadcrumbs__list-item:nth-child(1) a[data-track-label="/section"]', 1
Expand Down
2 changes: 1 addition & 1 deletion spec/components/contents_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def assert_tracking_link(name, value, total = 1)
it "renders data attributes for tracking" do
render_component(contents: nested_contents_list)

assert_select ".gem-c-contents-list[data-module='track-click']"
assert_select ".gem-c-contents-list[data-module='gem-track-click']"

assert_tracking_link("category", "contentsClicked", 6)
assert_tracking_link("action", "content_item 1")
Expand Down
14 changes: 7 additions & 7 deletions spec/components/cookie_banner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def component_name
it "renders a button for accepting cookies" do
render_component({})
assert_select ".govuk-button-group .gem-c-button", text: "Accept additional cookies"
assert_select '.govuk-button-group .gem-c-button[data-module=track-click][data-track-category=cookieBanner][data-track-action="Cookie banner accepted"]'
assert_select '.govuk-button-group .gem-c-button[data-module=gem-track-click][data-track-category=cookieBanner][data-track-action="Cookie banner accepted"]'
end

it "renders a button for rejecting cookies" do
render_component({})
assert_select ".govuk-button-group .gem-c-button", text: "Reject additional cookies"
assert_select '.govuk-button-group .gem-c-button[data-module=track-click][data-track-category=cookieBanner][data-track-action="Cookie banner rejected"]'
assert_select '.govuk-button-group .gem-c-button[data-module=gem-track-click][data-track-category=cookieBanner][data-track-action="Cookie banner rejected"]'
end

it "renders a link for viewing cookie settings" do
Expand All @@ -40,14 +40,14 @@ def component_name
it "renders a link to the settings page within the confirmation message" do
render_component({})
assert_select ".gem-c-cookie-banner__confirmation-message a", text: "change your cookie settings"
assert_select '.gem-c-cookie-banner__confirmation-message a[data-module=track-click][data-track-category=cookieBanner][data-track-action="Cookie banner settings clicked from confirmation"]'
assert_select '.gem-c-cookie-banner__confirmation-message a[data-module=gem-track-click][data-track-category=cookieBanner][data-track-action="Cookie banner settings clicked from confirmation"]'
end

it "renders a hide link within the confirmation banner" do
render_component({})

assert_select ".gem-c-cookie-banner__confirmation .gem-c-cookie-banner__hide-button", text: "Hide this message"
assert_select '.gem-c-cookie-banner__hide-button[data-module=track-click][data-track-category=cookieBanner][data-track-action="Hide cookie banner"]'
assert_select '.gem-c-cookie-banner__hide-button[data-module=gem-track-click][data-track-category=cookieBanner][data-track-action="Hide cookie banner"]'
end

it "renders with custom content" do
Expand Down Expand Up @@ -78,7 +78,7 @@ def component_name

# Check that the confirmation message also includes the custom URL
assert_select ".gem-c-cookie-banner__confirmation-message a[href='/cookies']", text: "change your cookie settings"
assert_select '.gem-c-cookie-banner__confirmation-message a[data-module=track-click][data-track-category=cookieBanner][data-track-action="Cookie banner settings clicked from confirmation"]'
assert_select '.gem-c-cookie-banner__confirmation-message a[data-module=gem-track-click][data-track-category=cookieBanner][data-track-action="Cookie banner settings clicked from confirmation"]'
end

it "renders the 'analytics only' version" do
Expand Down Expand Up @@ -106,8 +106,8 @@ def component_name
)

assert_select ".gem-c-cookie-banner.gem-c-cookie-banner--services"
assert_select ".govuk-button-group button[data-module=track-click][data-track-category=cookieBanner][data-accept-cookies=true]", text: "Yes"
assert_select ".govuk-button-group button[data-module=track-click][data-track-category=cookieBanner][data-reject-cookies=true]", text: "No"
assert_select ".govuk-button-group button[data-module=gem-track-click][data-track-category=cookieBanner][data-accept-cookies=true]", text: "Yes"
assert_select ".govuk-button-group button[data-module=gem-track-click][data-track-category=cookieBanner][data-reject-cookies=true]", text: "No"
assert_select ".govuk-button-group .govuk-link[href='/cookies']", text: "How we use cookies"
end
end
6 changes: 3 additions & 3 deletions spec/components/image_card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def component_name
it "shows an image" do
render_component(href: "#", image_src: "/moo.jpg", image_alt: "some meaningful alt text")
assert_select ".gem-c-image-card .gem-c-image-card__image[src='/moo.jpg'][alt='some meaningful alt text']"
assert_select ".gem-c-image-card[data-module='track-click']", false
assert_select ".gem-c-image-card[data-module='gem-track-click']", false
end

it "shows heading text" do
Expand Down Expand Up @@ -89,13 +89,13 @@ def component_name

it "applies tracking attributes" do
render_component(href: "#", href_data_attributes: { track_category: "cat" }, heading_text: "test")
assert_select ".gem-c-image-card[data-module='track-click']"
assert_select ".gem-c-image-card[data-module='gem-track-click']"
assert_select ".gem-c-image-card__title-link[data-track-category='cat']"
end

it "applies tracking attributes for extra links" do
render_component(href: "#", extra_links: [{ href: "/", text: "1", data_attributes: { track_category: "cat" } }])
assert_select ".gem-c-image-card[data-module='track-click']"
assert_select ".gem-c-image-card[data-module='gem-track-click']"
assert_select ".gem-c-image-card__list-item a[data-track-category='cat']"
end

Expand Down
2 changes: 1 addition & 1 deletion spec/components/organisation_logo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def component_name

render_component(organisation: { url: "/some-link", data_attributes: data_attributes })

assert_select ".gem-c-organisation-logo[data-module='track-click']"
assert_select ".gem-c-organisation-logo[data-module='gem-track-click']"
assert_select ".gem-c-organisation-logo a.gem-c-organisation-logo__container.gem-c-organisation-logo__link[data-track-category='someLinkClicked']"
assert_select ".gem-c-organisation-logo a.gem-c-organisation-logo__container.gem-c-organisation-logo__link[data-track-action='1']"
assert_select ".gem-c-organisation-logo a.gem-c-organisation-logo__container.gem-c-organisation-logo__link[data-track-label='/some-link']"
Expand Down
2 changes: 1 addition & 1 deletion spec/components/related_navigation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def construct_links(type, base_path, title, document_type = nil, locale = nil)
)
render_component(content_item: content_item)

assert_select ".gem-c-related-navigation__nav-section ul[data-module='track-click']"
assert_select ".gem-c-related-navigation__nav-section ul[data-module='gem-track-click']"
assert_select ".gem-c-related-navigation__section-link[data-track-category='relatedLinkClicked']"
assert_select ".gem-c-related-navigation__section-link[data-track-action='1.1 Explore the topic']"
assert_select ".gem-c-related-navigation__section-link[data-track-label='/apprenticeships']"
Expand Down
8 changes: 4 additions & 4 deletions spec/components/subscription_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def component_name
it "renders both email signup and feed links" do
render_component(email_signup_link: "email-signup", feed_link: "singapore.atom")
assert_select ".gem-c-subscription-links[data-module='gem-toggle']", false
assert_select ".gem-c-subscription-links__list[data-module='track-click']", false
assert_select ".gem-c-subscription-links__list[data-module='gem-track-click']", false
assert_select ".gem-c-subscription-links__item[href=\"email-signup\"]", text: "Get emails"
assert_select ".gem-c-subscription-links__item[href=\"singapore.atom\"]", text: "Subscribe to feed"
end
Expand Down Expand Up @@ -65,18 +65,18 @@ def component_name

it "adds tracking for email signup link" do
render_component(email_signup_link: "email-signup", email_signup_link_data_attributes: { 'track_category': "test" })
assert_select ".gem-c-subscription-links__list[data-module=\"track-click\"] .gem-c-subscription-links__item[data-track-category=\"test\"]"
assert_select ".gem-c-subscription-links__list[data-module=\"gem-track-click\"] .gem-c-subscription-links__item[data-track-category=\"test\"]"
end

it "adds tracking for feed link" do
render_component(feed_link: "feed", feed_link_data_attributes: { 'track_category': "test" })
assert_select ".gem-c-subscription-links__list[data-module=\"track-click\"] .gem-c-subscription-links__item[data-track-category=\"test\"]"
assert_select ".gem-c-subscription-links__list[data-module=\"gem-track-click\"] .gem-c-subscription-links__item[data-track-category=\"test\"]"
end

it "adds tracking for feed link when it is a toggle" do
render_component(feed_link_box_value: "feed", feed_link_data_attributes: { 'track_category': "test" })
assert_select ".gem-c-subscription-links[data-module=\"gem-toggle\"]"
assert_select ".gem-c-subscription-links__list[data-module=\"track-click\"] .gem-c-subscription-links__item[data-track-category=\"test\"]"
assert_select ".gem-c-subscription-links__list[data-module=\"gem-track-click\"] .gem-c-subscription-links__item[data-track-category=\"test\"]"
end

it "adds small form modifier to the list of links" do
Expand Down
Loading