Skip to content

Commit

Permalink
Merge pull request #1710 from alphagov/fix-spelling-suggestions-analy…
Browse files Browse the repository at this point in the history
…tics

Fix spelling suggestions analytics
  • Loading branch information
kr8n3r authored Nov 4, 2019
2 parents 1c9b77b + 05e469b commit 23b30b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 5 additions & 8 deletions app/assets/javascripts/live_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
window.ga('set', 'transport', 'beacon')
}

// track impressions of spelling suggestions
if (this.$suggestionsBlock) {
this.trackSpellingSuggestionsImpressions(this.$suggestionsBlock)
}

if (GOVUK.support.history()) {
this.saveState()

Expand Down Expand Up @@ -151,9 +146,11 @@
}

LiveSearch.prototype.trackSpellingSuggestionsImpressions = function trackSpellingSuggestionsImpressions ($suggestions) {
$($suggestions).find('a').each(function () {
GOVUK.SearchAnalytics.setDimension(81, $(this).data('track-options').dimension81)
})
var $spellingSuggestionMetaTag = $("meta[name='govuk:spelling-suggestion']")
// currently there's ever only one suggestion
var spellingSuggestionAvailable = this.$suggestionsBlock.find('a').length > 0
var suggestion = spellingSuggestionAvailable ? this.$suggestionsBlock.find('a').data('track-options').dimension81 : ''
$spellingSuggestionMetaTag.attr('content', suggestion)
}

/**
Expand Down
8 changes: 7 additions & 1 deletion app/views/finders/_spelling_suggestion.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<% # we want an empty string if there are no suggestions on page load %>
<% _spelling_suggestion = '' %>
<% if @spelling_suggestion_presenter.suggestions.any? %>
<p class="govuk-body">Did you mean
<% @spelling_suggestion_presenter.suggestions.each do |suggestion| %>
<%= link_to suggestion[:keywords], suggestion[:link],
class: "govuk-link govuk-!-font-weight-bold",
:data => suggestion[:data_attributes]
%>
<% _spelling_suggestion = suggestion[:keywords] %>
<% end %>
</p>
<% end %>
<% end %>
<% content_for :head do %>
<meta name="govuk:spelling-suggestion" content="<%= _spelling_suggestion %>">
<% end %>

0 comments on commit 23b30b9

Please sign in to comment.