govuk_publishing_components 21.67.2 → 23.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -1
  3. data/app/assets/images/govuk_publishing_components/action-link-arrow--simple-light.png +0 -0
  4. data/app/assets/images/govuk_publishing_components/action-link-arrow--simple-light.svg +4 -0
  5. data/app/assets/javascripts/govuk_publishing_components/analytics.js +16 -0
  6. data/app/assets/javascripts/govuk_publishing_components/analytics/analytics.js +85 -0
  7. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js +30 -0
  8. data/app/assets/javascripts/govuk_publishing_components/analytics/custom-dimensions.js +120 -0
  9. data/app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js +41 -0
  10. data/app/assets/javascripts/govuk_publishing_components/analytics/ecommerce.js +101 -0
  11. data/app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js +51 -0
  12. data/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js +56 -0
  13. data/app/assets/javascripts/govuk_publishing_components/analytics/google-analytics-universal-tracker.js +198 -0
  14. data/app/assets/javascripts/govuk_publishing_components/analytics/init.js.erb +50 -0
  15. data/app/assets/javascripts/govuk_publishing_components/analytics/mailto-link-tracker.js +38 -0
  16. data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +129 -0
  17. data/app/assets/javascripts/govuk_publishing_components/analytics/pii.js +74 -0
  18. data/app/assets/javascripts/govuk_publishing_components/analytics/print-intent.js +39 -0
  19. data/app/assets/javascripts/govuk_publishing_components/analytics/scroll-tracker.js +513 -0
  20. data/app/assets/javascripts/govuk_publishing_components/analytics/static-analytics.js +132 -0
  21. data/app/assets/javascripts/govuk_publishing_components/lib/track-click.js +61 -0
  22. data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +26 -6
  23. data/app/assets/stylesheets/govuk_publishing_components/components/_feedback.scss +10 -2
  24. data/app/assets/stylesheets/govuk_publishing_components/components/_print-link.scss +23 -20
  25. data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +7 -1
  26. data/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +95 -45
  27. data/app/views/govuk_publishing_components/components/_action_link.html.erb +2 -0
  28. data/app/views/govuk_publishing_components/components/_contents_list.html.erb +8 -13
  29. data/app/views/govuk_publishing_components/components/_govspeak.html.erb +8 -12
  30. data/app/views/govuk_publishing_components/components/_input.html.erb +17 -4
  31. data/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +0 -1
  32. data/app/views/govuk_publishing_components/components/_layout_header.html.erb +6 -5
  33. data/app/views/govuk_publishing_components/components/_panel.html.erb +5 -2
  34. data/app/views/govuk_publishing_components/components/_print_link.html.erb +26 -11
  35. data/app/views/govuk_publishing_components/components/_search.html.erb +1 -1
  36. data/app/views/govuk_publishing_components/components/_subscription-links.html.erb +20 -9
  37. data/app/views/govuk_publishing_components/components/docs/action_link.yml +8 -0
  38. data/app/views/govuk_publishing_components/components/docs/contents_list.yml +0 -37
  39. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +1 -6
  40. data/app/views/govuk_publishing_components/components/docs/input.yml +7 -3
  41. data/app/views/govuk_publishing_components/components/docs/layout_header.yml +0 -3
  42. data/app/views/govuk_publishing_components/components/docs/panel.yml +4 -0
  43. data/app/views/govuk_publishing_components/components/docs/print_link.yml +5 -0
  44. data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +5 -5
  45. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +3 -1
  46. data/app/views/govuk_publishing_components/components/layout_header/_search.html.erb +0 -1
  47. data/config/initializers/assets.rb +1 -0
  48. data/config/locales/en.yml +1 -1
  49. data/config/locales/et.yml +4 -0
  50. data/config/locales/fr.yml +4 -0
  51. data/lib/govuk_publishing_components/version.rb +1 -1
  52. metadata +24 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dff3c8adb46566625a54c58136bffb72bbaec93fa9d803f04d6372c09065766a
4
- data.tar.gz: 48b13db7e001c01cbf4f230195f42248a3378e8f263e7abcb9dae8e88a4e382d
3
+ metadata.gz: 20fcbde55a95f5ca3e7ac5744c94f69b573b563e9c5df919681864c6662dff16
4
+ data.tar.gz: 9d65b762cc90d4e8bfa3ba37b2c811778af94f55a3d88d0e45ca0ed7f0d0161a
5
5
  SHA512:
6
- metadata.gz: be93ed1a460324911d7e4626a028f5352b7d4a5cbe0838ec67516f1ed03ca6373559f45c60faa572acc112d56d52c035700d4e205dc01f60c057e6355a473dfe
7
- data.tar.gz: a46214b1b651dffebaf202c8c1a003c9b2275abd042f458dc8fab883e97a9aeacba0e9d1dbb76070e14f76b87c9d353a63a6a332bad3b291d1ed4d032f744293
6
+ metadata.gz: 10d6c20ed45850b0bc92826e009dd10d8cbc5a6e09368ad9822e33d97a7bf6b8b59b43c50b18cf630e109455df35e4b993b6c1e497d0eeb94adc2081b128da41
7
+ data.tar.gz: b3fdb29493b563ef3893f1c2d33f21feb2f9817d38952cff97091e6b318bd0d11c2ddd3c85ba08f0baf80560a30150651ed283fbaf06700b4045d161cb187740
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- GOV.UK Publishing Components
1
+ GOV.UK Publishing Components
2
2
  [![status](https://badgen.net/github/status/alphagov/govuk_publishing_components/master)](https://ci.integration.publishing.service.gov.uk/job/govuk_publishing_components/job/master/)
3
3
  [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
4
4
  [![Stylelint Style Guide](https://img.shields.io/badge/code_style-stylelint-brightgreen.svg)](https://github.com/alphagov/stylelint-config-gds/)
@@ -59,6 +59,10 @@ bundle install
59
59
  yarn install
60
60
  ```
61
61
 
62
+ ### Running a local app with a local gem
63
+
64
+ The GDS Developer Docs has a [guide on local frontend development](https://docs.publishing.service.gov.uk/manual/local-frontend-development.html) that covers setting up a local app to use the local version of the components gem in Docker and using the `./startup.sh` script.
65
+
62
66
  ### Running tests
63
67
 
64
68
  The default rake task runs all the linting and test tasks:
@@ -0,0 +1,4 @@
1
+ <svg width="23" height="23" viewBox="0 0 23 23" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M14.9429 11.7949L10.4402 7.29222L11.7327 5.99967L17.528 11.7949L11.7327 17.5902L10.4402 16.2976L14.9429 11.7949Z" fill="#ffffff"/>
3
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M3.95631 10.881L15.4414 10.881L15.4414 12.709L3.95631 12.709L3.95631 10.881Z" fill="#ffffff"/>
4
+ </svg>
@@ -0,0 +1,16 @@
1
+ //= require govuk_publishing_components/lib/cookie-functions
2
+ //= require ./analytics/pii
3
+ //= require ./analytics/google-analytics-universal-tracker
4
+ //= require ./analytics/analytics
5
+ //= require ./analytics/print-intent
6
+ //= require ./analytics/error-tracking
7
+ //= require ./analytics/mailto-link-tracker
8
+ //= require ./analytics/external-link-tracker
9
+ //= require ./analytics/download-link-tracker
10
+ //= require ./analytics/auto-track-event
11
+ //= require ./analytics/page-content
12
+ //= require ./analytics/custom-dimensions
13
+ //= require ./analytics/static-analytics
14
+ //= require ./analytics/ecommerce
15
+ //= require ./analytics/init
16
+ //= require ./analytics/scroll-tracker
@@ -0,0 +1,85 @@
1
+ ;(function (global) {
2
+ 'use strict'
3
+
4
+ var GOVUK = global.GOVUK || {}
5
+ // For usage and initialisation see:
6
+ // https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#create-an-analytics-tracker
7
+
8
+ var Analytics = function (config) {
9
+ this.pii = new GOVUK.Pii()
10
+ this.trackers = []
11
+ if (typeof config.universalId !== 'undefined') {
12
+ var universalId = config.universalId
13
+ delete config.universalId
14
+ this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config))
15
+ }
16
+ }
17
+
18
+ var PIISafe = function (value) {
19
+ this.value = value
20
+ }
21
+ Analytics.PIISafe = PIISafe
22
+
23
+ Analytics.prototype.sendToTrackers = function (method, args) {
24
+ for (var i = 0, l = this.trackers.length; i < l; i++) {
25
+ var tracker = this.trackers[i]
26
+ var fn = tracker[method]
27
+
28
+ if (typeof fn === 'function') {
29
+ fn.apply(tracker, args)
30
+ }
31
+ }
32
+ }
33
+
34
+ Analytics.load = function () {
35
+ GOVUK.GoogleAnalyticsUniversalTracker.load()
36
+ }
37
+
38
+ Analytics.prototype.defaultPathForTrackPageview = function (location) {
39
+ // Get the page path including querystring, but ignoring the anchor
40
+ // as per default behaviour of GA (see: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages#overview)
41
+ // we ignore the possibility of there being campaign variables in the
42
+ // anchor because we wouldn't know how to detect and parse them if they
43
+ // were present
44
+ return this.pii.stripPIIFromString(location.href.substring(location.origin.length).split('#')[0])
45
+ }
46
+
47
+ Analytics.prototype.trackPageview = function (path, title, options) {
48
+ arguments[0] = arguments[0] || this.defaultPathForTrackPageview(window.location)
49
+ if (arguments.length === 0) { arguments.length = 1 }
50
+ this.sendToTrackers('trackPageview', this.pii.stripPII(arguments))
51
+ }
52
+
53
+ /*
54
+ https://developers.google.com/analytics/devguides/collection/analyticsjs/events
55
+ options.label – Useful for categorizing events (eg nav buttons)
56
+ options.value – Values must be non-negative. Useful to pass counts
57
+ options.nonInteraction – Prevent event from impacting bounce rate
58
+ */
59
+ Analytics.prototype.trackEvent = function (category, action, options) {
60
+ this.sendToTrackers('trackEvent', this.pii.stripPII(arguments))
61
+ }
62
+
63
+ Analytics.prototype.trackShare = function (network, options) {
64
+ this.sendToTrackers('trackSocial', this.pii.stripPII([network, 'share', global.location.pathname, options]))
65
+ }
66
+
67
+ /*
68
+ The custom dimension index must be configured within the
69
+ Universal Analytics profile
70
+ */
71
+ Analytics.prototype.setDimension = function (index, value) {
72
+ this.sendToTrackers('setDimension', this.pii.stripPII(arguments))
73
+ }
74
+
75
+ /*
76
+ Add a beacon to track a page in another GA account on another domain.
77
+ */
78
+ Analytics.prototype.addLinkedTrackerDomain = function (trackerId, name, domain) {
79
+ this.sendToTrackers('addLinkedTrackerDomain', arguments)
80
+ }
81
+
82
+ GOVUK.Analytics = Analytics
83
+
84
+ global.GOVUK = GOVUK
85
+ })(window)
@@ -0,0 +1,30 @@
1
+ ;(function (global) {
2
+ 'use strict'
3
+
4
+ var GOVUK = global.GOVUK || {}
5
+ GOVUK.Modules = GOVUK.Modules || {}
6
+
7
+ GOVUK.Modules.AutoTrackEvent = function () {
8
+ this.start = function (element) {
9
+ var options = { nonInteraction: 1 } // automatic events shouldn't affect bounce rate
10
+ var category = element.data('track-category')
11
+ var action = element.data('track-action')
12
+ var label = element.data('track-label')
13
+ var value = element.data('track-value')
14
+
15
+ if (typeof label === 'string') {
16
+ options.label = label
17
+ }
18
+
19
+ if (value || value === 0) {
20
+ options.value = value
21
+ }
22
+
23
+ if (GOVUK.analytics && GOVUK.analytics.trackEvent) {
24
+ GOVUK.analytics.trackEvent(category, action, options)
25
+ }
26
+ }
27
+ }
28
+
29
+ global.GOVUK = GOVUK
30
+ })(window)
@@ -0,0 +1,120 @@
1
+ /* global GOVUK, $ */
2
+
3
+ (function () {
4
+ 'use strict'
5
+ window.GOVUK = window.GOVUK || {}
6
+ var CustomDimensions = function () { }
7
+
8
+ CustomDimensions.getAndExtendDefaultTrackingOptions = function (extraOptions) {
9
+ var trackingOptions = this.customDimensions()
10
+ return $.extend(trackingOptions, extraOptions)
11
+ }
12
+
13
+ CustomDimensions.customDimensions = function () {
14
+ var dimensions = $.extend(
15
+ {},
16
+ customDimensionsFromBrowser(),
17
+ customDimensionsFromMetaTags(),
18
+ customDimensionsFromDom(),
19
+ abTestCustomDimensions()
20
+ )
21
+
22
+ return $.each(dimensions, function (key, value) {
23
+ dimensions[key] = new GOVUK.Analytics.PIISafe(String(value))
24
+ })
25
+ }
26
+
27
+ function customDimensionsFromBrowser () {
28
+ var customDimensions = {
29
+ dimension15: window.httpStatusCode || 200,
30
+ dimension16: GOVUK.cookie('TLSversion') || 'unknown',
31
+ dimension95: GOVUK.analytics.gaClientId
32
+ }
33
+
34
+ if (window.devicePixelRatio) {
35
+ customDimensions.dimension11 = window.devicePixelRatio
36
+ }
37
+
38
+ return customDimensions
39
+ }
40
+
41
+ function customDimensionsFromMetaTags () {
42
+ var dimensionMappings = {
43
+ section: { dimension: 1 },
44
+ format: { dimension: 2 },
45
+ themes: { dimension: 3, defaultValue: 'other' },
46
+ 'content-id': { dimension: 4, defaultValue: '00000000-0000-0000-0000-000000000000' },
47
+ 'search-result-count': { dimension: 5 },
48
+ 'publishing-government': { dimension: 6 },
49
+ 'political-status': { dimension: 7 },
50
+ 'analytics:organisations': { dimension: 9 },
51
+ 'analytics:world-locations': { dimension: 10 },
52
+ withdrawn: { dimension: 12, defaultValue: 'not withdrawn' },
53
+ 'schema-name': { dimension: 17 },
54
+ 'rendering-application': { dimension: 20 },
55
+ 'search-autocomplete-status': { dimension: 21 },
56
+ 'navigation-legacy': { dimension: 30, defaultValue: 'none' },
57
+ 'navigation-page-type': { dimension: 32, defaultValue: 'none' },
58
+ 'taxon-slug': { dimension: 56, defaultValue: 'other' },
59
+ 'taxon-id': { dimension: 57, defaultValue: 'other' },
60
+ 'taxon-slugs': { dimension: 58, defaultValue: 'other' },
61
+ 'taxon-ids': { dimension: 59, defaultValue: 'other' },
62
+ 'content-has-history': { dimension: 39, defaultValue: 'false' },
63
+ 'publishing-application': { dimension: 89 },
64
+ stepnavs: { dimension: 96 },
65
+ 'relevant-result-shown': { dimension: 83 },
66
+ 'spelling-suggestion': { dimension: 81 }
67
+ }
68
+
69
+ var $metas = $('meta[name^="govuk:"]')
70
+ var customDimensions = {}
71
+ var tags = {}
72
+
73
+ $metas.each(function () {
74
+ var $meta = $(this)
75
+ var key = $meta.attr('name').split('govuk:')[1]
76
+
77
+ var dimension = dimensionMappings[key]
78
+ if (dimension) {
79
+ tags[key] = $meta.attr('content')
80
+ }
81
+ })
82
+
83
+ $.each(dimensionMappings, function (key, dimension) {
84
+ var value = tags[key] || dimension.defaultValue
85
+ if (typeof value !== 'undefined') {
86
+ customDimensions['dimension' + dimension.dimension] = value
87
+ }
88
+ })
89
+
90
+ return customDimensions
91
+ }
92
+
93
+ function customDimensionsFromDom () {
94
+ return {
95
+ dimension26: GOVUK.PageContent.getNumberOfSections(),
96
+ dimension27: GOVUK.PageContent.getNumberOfLinks(),
97
+ dimension23: $('main[id="content"]').attr('lang') || 'unknown',
98
+ dimension38: $('[data-module="global-bar"]').is(':visible') && 'Global Banner viewed'
99
+ }
100
+ }
101
+
102
+ function abTestCustomDimensions () {
103
+ var $abMetas = $('meta[name^="govuk:ab-test"]')
104
+ var customDimensions = {}
105
+
106
+ $abMetas.each(function () {
107
+ var $meta = $(this)
108
+ var dimension = parseInt($meta.data('analytics-dimension'))
109
+ var testNameAndBucket = $meta.attr('content')
110
+
111
+ if (dimension) {
112
+ customDimensions['dimension' + dimension] = testNameAndBucket
113
+ }
114
+ })
115
+
116
+ return customDimensions
117
+ }
118
+
119
+ GOVUK.CustomDimensions = CustomDimensions
120
+ })()
@@ -0,0 +1,41 @@
1
+ ;(function (global) {
2
+ 'use strict'
3
+
4
+ var $ = global.jQuery
5
+ var GOVUK = global.GOVUK || {}
6
+
7
+ GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
8
+ GOVUK.analyticsPlugins.downloadLinkTracker = function (options) {
9
+ options = options || {}
10
+ var downloadLinkSelector = options.selector
11
+
12
+ if (downloadLinkSelector) {
13
+ $('body').on('click', downloadLinkSelector, trackDownload)
14
+ }
15
+
16
+ function trackDownload (evt) {
17
+ var $link = getLinkFromEvent(evt)
18
+ var href = $link.attr('href')
19
+ var evtOptions = { transport: 'beacon' }
20
+ var linkText = $.trim($link.text())
21
+
22
+ if (linkText) {
23
+ evtOptions.label = linkText
24
+ }
25
+
26
+ GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions)
27
+ }
28
+
29
+ function getLinkFromEvent (evt) {
30
+ var $target = $(evt.target)
31
+
32
+ if (!$target.is('a')) {
33
+ $target = $target.parents('a')
34
+ }
35
+
36
+ return $target
37
+ }
38
+ }
39
+
40
+ global.GOVUK = GOVUK
41
+ })(window)
@@ -0,0 +1,101 @@
1
+ // https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce
2
+ /* global GOVUK, $, ga */
3
+
4
+ (function () {
5
+ 'use strict'
6
+ window.GOVUK = window.GOVUK || {}
7
+
8
+ var DEFAULT_LIST_TITLE = 'Site search results'
9
+ var DEFAULT_TRACK_CLICK_LABEL = 'Results'
10
+
11
+ var Ecommerce = function (config) {
12
+ this.init = function (element) {
13
+ // Limiting to 100 characters to avoid noise from extra longs search queries
14
+ // and to stop the size of the payload going over 8k limit.
15
+ var searchQuery = GOVUK.analytics.stripPII(element.attr('data-search-query')).substring(0, 100).toLowerCase()
16
+ var ecommerceRows = element.find('[data-ecommerce-row]')
17
+ var startPosition = parseInt(element.data('ecommerce-start-index'), 10)
18
+ var listTitle = element.data('list-title') || DEFAULT_LIST_TITLE
19
+ var variant = element.data('ecommerce-variant')
20
+ var trackClickLabel = element.data('track-click-label') || DEFAULT_TRACK_CLICK_LABEL
21
+
22
+ ecommerceRows.each(function (index, ecommerceRow) {
23
+ var $ecommerceRow = $(ecommerceRow)
24
+ var listSubheading = $ecommerceRow.data('ecommerce-subheading') || undefined
25
+ var contentId = $ecommerceRow.attr('data-ecommerce-content-id')
26
+ var path = $ecommerceRow.attr('data-ecommerce-path')
27
+
28
+ var indexOverride = $ecommerceRow.attr('data-ecommerce-index')
29
+ index = indexOverride ? parseInt(indexOverride, 10) - 1 : index
30
+
31
+ addImpression(contentId, path, index + startPosition, searchQuery, listTitle, listSubheading, variant)
32
+ trackProductOnClick($ecommerceRow, contentId, path, index + startPosition, searchQuery, listTitle, listSubheading, variant, trackClickLabel)
33
+ })
34
+ }
35
+
36
+ function constructData (contentId, path, position, listTitle, listSubheading, searchQuery, variant) {
37
+ var data = {
38
+ position: position,
39
+ list: listTitle,
40
+ dimension71: searchQuery
41
+ }
42
+
43
+ if (listSubheading !== undefined) {
44
+ data.dimension94 = listSubheading
45
+ }
46
+
47
+ if (contentId !== undefined) {
48
+ data.id = contentId
49
+ }
50
+
51
+ if (path !== undefined) {
52
+ data.name = path
53
+ }
54
+
55
+ if (variant !== undefined) {
56
+ data.variant = variant
57
+ }
58
+
59
+ return data
60
+ }
61
+
62
+ function addImpression (contentId, path, position, searchQuery, listTitle, listSubheading, variant) {
63
+ if (contentId || path) {
64
+ var impressionData = constructData(contentId, path, position, listTitle, listSubheading, searchQuery, variant)
65
+ ga('ec:addImpression', impressionData)
66
+ }
67
+ }
68
+
69
+ function trackProductOnClick (row, contentId, path, position, searchQuery, listTitle, listSubheading, variant, trackClickLabel) {
70
+ row.click(function () {
71
+ if (contentId || path) {
72
+ var clickData = constructData(contentId, path, position, listTitle, listSubheading, searchQuery, variant)
73
+ ga('ec:addProduct', clickData)
74
+ }
75
+
76
+ ga('ec:setAction', 'click', { list: listTitle })
77
+ GOVUK.analytics.trackEvent('UX', 'click',
78
+ GOVUK.CustomDimensions.getAndExtendDefaultTrackingOptions({ label: trackClickLabel })
79
+ )
80
+ })
81
+ }
82
+ }
83
+
84
+ Ecommerce.ecLoaded = false
85
+ Ecommerce.start = function (element) {
86
+ if (!window.ga) { return }
87
+ element = element || $('[data-analytics-ecommerce]')
88
+ if (element.length > 0) {
89
+ if (!Ecommerce.ecLoaded) {
90
+ ga('require', 'ec')
91
+ Ecommerce.ecLoaded = true
92
+ }
93
+ element.each(function (index) {
94
+ var ecommerce = new Ecommerce()
95
+ ecommerce.init($(this))
96
+ })
97
+ }
98
+ }
99
+
100
+ GOVUK.Ecommerce = Ecommerce
101
+ })()
@@ -0,0 +1,51 @@
1
+ // Extension to track errors using google analytics as a data store.
2
+ ;(function (global) {
3
+ 'use strict'
4
+
5
+ var GOVUK = global.GOVUK || {}
6
+
7
+ GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
8
+
9
+ GOVUK.analyticsPlugins.error = function (options) {
10
+ options = options || {}
11
+ var filenameMustMatch = options.filenameMustMatch
12
+
13
+ var trackJavaScriptError = function (e) {
14
+ var errorFilename = e.filename
15
+ var errorSource = errorFilename + ': ' + e.lineno
16
+
17
+ if (shouldTrackThisError(errorFilename)) {
18
+ GOVUK.analytics.trackEvent('JavaScript Error', e.message, {
19
+ label: errorSource,
20
+ value: 1,
21
+ nonInteraction: true
22
+ })
23
+ }
24
+ }
25
+
26
+ function shouldTrackThisError (errorFilename) {
27
+ // Errors in page should always be tracked
28
+ // If there's no filename filter, everything is tracked
29
+ if (!errorFilename || !filenameMustMatch) {
30
+ return true
31
+ }
32
+
33
+ // If there's a filter and the error matches it, track it
34
+ if (filenameMustMatch.test(errorFilename)) {
35
+ return true
36
+ }
37
+
38
+ return false
39
+ }
40
+
41
+ if (global.addEventListener) {
42
+ global.addEventListener('error', trackJavaScriptError, false)
43
+ } else if (global.attachEvent) {
44
+ global.attachEvent('onerror', trackJavaScriptError)
45
+ } else {
46
+ global.onerror = trackJavaScriptError
47
+ }
48
+ }
49
+
50
+ global.GOVUK = GOVUK
51
+ })(window)