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

Fix spelling suggestions analytics #1710

Merged
merged 2 commits into from
Nov 4, 2019
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
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 %>