Skip to content

Commit

Permalink
Merge pull request #863 from alphagov/add-tracking-data-attributes-to…
Browse files Browse the repository at this point in the history
…-breadcrumbs

Add tracking data attributes to breadcrumbs
  • Loading branch information
carvil authored Dec 15, 2016
2 parents e570be2 + b92face commit 5c24070
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem 'rack_strip_client_ip', '0.0.1'
gem 'actionpack-page_caching', '1.0.2'

gem 'uglifier', ">= 1.3.0"
gem 'sass-rails', "5.0.4"
gem 'sass-rails', "5.0.6"
gem 'airbrake', '~> 4.3.1'

gem 'nokogiri', "~> 1.6.6.4"
Expand Down
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ GEM
method_source (0.8.2)
mime-types (2.99.2)
mini_portile (0.6.2)
minitest (5.9.0)
minitest (5.10.1)
minitest-capybara (0.7.2)
capybara (~> 2.2)
minitest (~> 5.0)
Expand All @@ -150,7 +150,7 @@ GEM
slop (~> 3.4)
quiet_assets (1.1.0)
railties (>= 3.1, < 5.0)
rack (1.6.4)
rack (1.6.5)
rack-cache (1.5.1)
rack (>= 0.4)
rack-test (0.6.3)
Expand Down Expand Up @@ -196,9 +196,9 @@ GEM
tins (<= 1.6.0)
ruby-progressbar (1.7.5)
safe_yaml (1.0.4)
sass (3.4.18)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (3.4.22)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
Expand All @@ -222,9 +222,9 @@ GEM
sprockets (>= 2.8, < 4.0)
test-unit (3.1.3)
power_assert
thor (0.19.1)
thor (0.19.4)
thread_safe (0.3.5)
tilt (2.0.1)
tilt (2.0.5)
tins (1.6.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
Expand Down Expand Up @@ -270,7 +270,7 @@ DEPENDENCIES
quiet_assets (= 1.1.0)
rack_strip_client_ip (= 0.0.1)
rails (= 4.2.7.1)
sass-rails (= 5.0.4)
sass-rails (= 5.0.6)
shoulda
sprockets-rails (= 2.3.3)
test-unit
Expand Down
13 changes: 11 additions & 2 deletions app/views/govuk_component/breadcrumbs.raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
%>
<div class="govuk-breadcrumbs">
<ol>
<% breadcrumbs.each do |crumb| %>
<% breadcrumbs.each_with_index do |crumb, index| %>
<li>
<% if crumb[:url] %>
<a href="<%= crumb[:url] %>"><%= crumb[:title] %></a>
<%= link_to(
crumb[:title],
crumb[:url],
data: {
track_category: 'breadcrumbClicked',
track_action: index + 1,
track_label: crumb[:url],
track_dimension: crumb[:title]
}
) %>
<% else %>
<%= crumb[:title] %>
<% end %>
Expand Down
9 changes: 9 additions & 0 deletions test/govuk_component/breadcrumbs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def component_name
assert_link_with_text_in('ol li:first-child', '/section', 'Section')
end

test "renders all data attributes for tracking" do
render_component(breadcrumbs: [{ title: 'Section', url: '/section' }])

assert('ol li:first-child a[data-track-action=1]')
assert('ol li:first-child a[data-track-label="/section"]')
assert('ol li:first-child a[data-track-dimension="Section"]')
assert('ol li:first-child a[data-track-category="breadcrumbClicked"]')
end

test "renders a list of breadcrumbs" do
render_component({
breadcrumbs: [
Expand Down

0 comments on commit 5c24070

Please sign in to comment.