Skip to content

Commit

Permalink
Update spelling suggestion meta string dynamically
Browse files Browse the repository at this point in the history
Update the way we track what spellign suggestions are being shown.
As we're adding a meta tag for GA tracking, we now need to only update
the meta tag content where there is and isn't a spelling suggestion.
  • Loading branch information
kr8n3r committed Nov 4, 2019
1 parent 7270f13 commit 7657911
Showing 1 changed file with 5 additions and 8 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

0 comments on commit 7657911

Please sign in to comment.