diff --git a/govuk/public/javascripts/govuk/analytics/error-tracking.js b/govuk/public/javascripts/govuk/analytics/error-tracking.js index 58c46bde6..31135cf54 100644 --- a/govuk/public/javascripts/govuk/analytics/error-tracking.js +++ b/govuk/public/javascripts/govuk/analytics/error-tracking.js @@ -1,20 +1,40 @@ // Extension to track errors using google analytics as a data store. (function() { - "use strict"; - GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}; - GOVUK.analyticsPlugins.error = function () { + GOVUK.analyticsPlugins.error = function (options) { + var options = options || {}, + filenameMustMatch = options.filenameMustMatch; + var trackJavaScriptError = function (e) { - var errorSource = e.filename + ': ' + e.lineno; - GOVUK.analytics.trackEvent('JavaScript Error', e.message, { - label: errorSource, - value: 1, - nonInteraction: true - }); + var errorFilename = e.filename, + errorSource = errorFilename + ': ' + e.lineno; + + if (shouldTrackThisError(errorFilename)) { + GOVUK.analytics.trackEvent('JavaScript Error', e.message, { + label: errorSource, + value: 1, + nonInteraction: true + }); + } }; + function shouldTrackThisError(errorFilename) { + // Errors in page should always be tracked + // If there's no filename filter, everything is tracked + if (!errorFilename || !filenameMustMatch) { + return true; + } + + // If there's a filter and the error matches it, track it + if (filenameMustMatch.test(errorFilename)) { + return true; + } + + return false; + } + if (window.addEventListener) { window.addEventListener('error', trackJavaScriptError, false); } else if (window.attachEvent) { @@ -23,5 +43,4 @@ window.onerror = trackJavaScriptError; } } - }()); diff --git a/govuk/public/javascripts/govuk/selection-buttons.js b/govuk/public/javascripts/govuk/selection-buttons.js index b230832d2..69d0284b3 100644 --- a/govuk/public/javascripts/govuk/selection-buttons.js +++ b/govuk/public/javascripts/govuk/selection-buttons.js @@ -19,7 +19,7 @@ $elms = $(elmsOrSelector); this.selector = elmsOrSelector; this.setInitialState($(this.selector)); - } else { + } else if (elmsOrSelector !== undefined) { this.$elms = elmsOrSelector; this.setInitialState(this.$elms); } diff --git a/package.json b/package.json index 293e5d276..791335d28 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "consolidate": "^0.10.0", "express": "^3.18.4", "express-writer": "0.0.4", - "govuk_frontend_toolkit": "^4.2.1", + "govuk_frontend_toolkit": "^4.3.0", "govuk_template_mustache": "^0.15.1", "grunt": "^0.4.2", "grunt-concurrent": "^0.4.3",