Skip to content

Commit

Permalink
Add tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
andysellick committed May 8, 2018
1 parent ca3c544 commit bfdfbe6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
<%
email_signup_link ||= false
email_signup_link_text ||= t("govuk_component.subscription_links.email_signup_link_text", default: "Get email alerts")
email_signup_link_data_attributes ||= false
feed_link ||= false
feed_link_text ||= t("govuk_component.subscription_links.feed_link_text", default: "Subscribe to feed")
feed_link_box_value ||= false
feed_link_data = false
feed_link_data_attributes ||= {}

tracking_is_present = true if email_signup_link_data_attributes || !feed_link_data_attributes.empty?

brand ||= false
brand_helper = GovukPublishingComponents::Presenters::BrandHelper.new(brand)

if feed_link_box_value
feed_link = "#"
feed_link_data = {
controls: "feed-reader",
expanded: "false"
}
feed_link_data_attributes[:controls] = "feed-reader"
feed_link_data_attributes[:expanded] = "false"
end
%>
<% if email_signup_link || feed_link || feed_link_box_value %>
<section class="gem-c-subscription-links <%= brand_helper.get_brand %>" data-module="gem-toggle">
<section class="gem-c-subscription-links <%= brand_helper.get_brand %>"
<%= "data-module=gem-toggle" if feed_link_box_value %>
>
<h2 class="visuallyhidden"><%= t("govuk_component.subscription_links.subscriptions", default: "Subscriptions") %></h2>
<ul class="gem-c-subscription-links__list">
<ul class="gem-c-subscription-links__list"
<%= "data-module=track-click" if tracking_is_present %>
>
<% if email_signup_link.present? %>
<li class="gem-c-subscription-links__list-item">
<%= link_to email_signup_link_text, email_signup_link,
class: "gem-c-subscription-links__link gem-c-subscription-links__link--email-alerts #{brand_helper.get_brand_element("color")}"
class: "gem-c-subscription-links__link gem-c-subscription-links__link--email-alerts #{brand_helper.get_brand_element("color")}",
data: (email_signup_link_data_attributes if email_signup_link_data_attributes)
%>
</li>
<% end %>

<% if feed_link_box_value || feed_link.present? %>
<li class="gem-c-subscription-links__list-item">
<%= link_to feed_link_text, feed_link,
class: "gem-c-subscription-links__link gem-c-subscription-links__link--feed #{brand_helper.get_brand_element("color")}",
data: feed_link_data
class: "gem-c-subscription-links__link gem-c-subscription-links__link--feed #{brand_helper.get_brand_element("color")}",
data: (feed_link_data_attributes if feed_link_data_attributes)
%>
</li>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,27 @@ examples:
brand: 'attorney-generals-office'
email_signup_link: '/foreign-travel-advice/singapore/email-signup'
feed_link: '/foreign-travel-advice/singapore.atom'
with_tracking:
description: Data attributes can be passed for each link as shown.
data:
brand: 'attorney-generals-office'
email_signup_link: '/foreign-travel-advice/singapore/email-signup'
email_signup_link_data_attributes: {
track_category: 'email_link_category',
track_action: 1.1,
track_label: 'email_link_label',
track_options: {
dimension28: 1,
dimension29: 'dimension29EmailLink'
}
}
feed_link_box_value: 'https://www.gov.uk/government/organisations/attorney-generals-office.atom'
feed_link_data_attributes: {
track_category: 'feed_link_category',
track_action: 1.2,
track_label: 'feed_link_label',
track_options: {
dimension28: 7,
dimension29: 'dimension29feedLink'
}
}
16 changes: 16 additions & 0 deletions spec/components/subscription_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ def component_name
assert_select ".gem-c-subscription-links__link--email-alerts.brand__color"
assert_select ".gem-c-subscription-links__link--feed.brand__color"
end

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__link--email-alerts[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__link--feed[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__link--feed[data-track-category=\"test\"]"
end
end

0 comments on commit bfdfbe6

Please sign in to comment.