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

Upgrade govuk_frontend_toolkit #1899

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -9,7 +9,7 @@ gem 'rails', '4.2.2'
gem 'rails-i18n'
gem 'json'
gem 'plek', '1.7.0'
gem 'govuk_frontend_toolkit', '3.1.0'
gem 'govuk_frontend_toolkit', '~> 4.2.1'
gem 'airbrake', '~> 3.1.17'
gem 'logstasher', '0.4.8'
gem 'rack_strip_client_ip', '0.0.1'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -104,7 +104,7 @@ GEM
kramdown (~> 1.4.1)
nokogiri (~> 1.5)
sanitize (~> 2.1.0)
govuk_frontend_toolkit (3.1.0)
govuk_frontend_toolkit (4.2.1)
rails (>= 3.1.0)
sass (>= 3.2.0)
hike (1.2.3)
Expand Down Expand Up @@ -299,7 +299,7 @@ DEPENDENCIES
gds-api-adapters (= 20.1.1)
google-api-client
govspeak (~> 3.3.0)
govuk_frontend_toolkit (= 3.1.0)
govuk_frontend_toolkit (~> 4.2.1)
htmlentities (~> 4)
json
logstasher (= 0.4.8)
Expand Down
16 changes: 6 additions & 10 deletions app/views/smart_answers/_result.html.erb
Expand Up @@ -23,15 +23,11 @@

<script type="text/javascript">
var flowName = '<%= @name %>';
event = {
hitType: 'event',
eventCategory: 'Smart Answer',
eventAction: 'Completed',
eventLabel: flowName,
nonInteraction: 1,
page: document.location.pathname
};
if (typeof window.ga === "function") {
window.ga('send', event);
var page = document.location.pathname;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's worth worrying about, but this makes page and options variables available globally. They're rather generic names and if I'm correct it could in theory cause problems with other JS that may rely on if(options === undefined) or similar code. Putting it in a closure would avoid this problem e.g.:

(function(){
  var flowName = '<%= @name %>';
  var page = document.location.pathname;
  var options = {
    label: flowName,
    nonInteraction: true,
    page: page
  };
  GOVUK.analytics.trackEvent('Smart Answer', 'Completed', options);
})();

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. I'll make the change and update this pull request.

var options = {
label: flowName,
nonInteraction: true,
page: page
};
GOVUK.analytics.trackEvent('Smart Answer', 'Completed', options);
</script>