govuk_frontend_toolkit 4.2.1 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ # 4.3.0
2
+
3
+ - Allow javascript error tracking to be filtered to avoid noise from plugins
4
+
1
5
  # 4.2.1
2
6
 
3
7
  - Track download links using events not pageviews
data/app/assets/README.md CHANGED
@@ -125,8 +125,10 @@ In production:
125
125
  * [Virtual pageviews](/docs/analytics.md#virtual-pageviews)
126
126
  * [Custom events](/docs/analytics.md#custom-events)
127
127
  * [Custom dimensions and custom variables](/docs/analytics.md#custom-dimensions-and-custom-variables)
128
- * [Print tracking](/docs/analytics.md#print-tracking)
129
- * [Error tracking](/docs/analytics.md#error-tracking)
128
+ * [Print tracking](/docs/analytics.md#print-tracking-print-intentjs)
129
+ * [Error tracking](/docs/analytics.md#error-tracking-error-trackingjs)
130
+ * [External link tracking](/docs/analytics.md#external-link-tracking-external-link-trackerjs)
131
+ * [Download link tracking](/docs/analytics.md#download-link-tracking-download-link-trackerjs)
130
132
 
131
133
  ## Licence
132
134
 
@@ -1 +1 @@
1
- 4.2.1
1
+ 4.3.0
@@ -172,7 +172,11 @@ Example pageview:
172
172
 
173
173
  ### Error tracking (`error-tracking.js`)
174
174
 
175
- Track JavaScript errors, capturing the error message, file and line number. These events don’t affect bounce rate.
175
+ Track JavaScript errors, capturing the error message, file and line number. These events don’t affect bounce rate. Errors can be filtered to include only files of interest by passing in an options argument with a regexp matcher (to avoid tracking errors generated by browser plugins):
176
+
177
+ ```js
178
+ GOVUK.analyticsPlugins.error({filenameMustMatch: /gov\.uk/});
179
+ ```
176
180
 
177
181
  Category | Action | Label | Value
178
182
  ---------|--------|-------|-------
@@ -180,7 +184,7 @@ JavaScript Error | The error message | file.js: line number | 1
180
184
 
181
185
  ### External link tracking (`external-link-tracker.js`)
182
186
 
183
- The tracker will send an analytics event for clicks on links beginning, `http` and linking outside of the current host. By default the plugin uses Google Analytics’ `transport: beacon` method so that events are tracked even if the page unloads.
187
+ The tracker will send an event for clicks on links beginning, `http` and linking outside of the current host. By default the plugin uses Google Analytics’ `transport: beacon` method so that events are tracked even if the page unloads.
184
188
 
185
189
  Category | Action | Label
186
190
  ---------|--------|-------
@@ -189,12 +193,12 @@ External Link Clicked | http://www.some-external-website.com | Link text
189
193
 
190
194
  ### Download link tracking (`download-link-tracker.js`)
191
195
 
192
- The tracker will send a pageview for clicks on any link that matches the selector passed in. A selector must be provided. By default the plugin uses Google Analytics’ `transport: beacon` method so that pageviews are tracked even if the page unloads.
196
+ The tracker will send an event for clicks on any link that matches the selector passed in. A selector must be provided. By default the plugin uses Google Analytics’ `transport: beacon` method so that events are tracked even if the page unloads.
193
197
 
194
198
  ```js
195
- GOVUK.analyticsPlugins.downloadTracker({selector: 'a[rel=download]'});
199
+ GOVUK.analyticsPlugins.downloadTracker({selector: 'a[rel="download"]'});
196
200
  ```
197
201
 
198
- Page | Page title
199
- -----|-----------
200
- `/some/upload/attachment/file.pdf` | Link text
202
+ Category | Action | Label
203
+ ---------|--------|-------
204
+ Download Link Clicked | `/some/upload/attachment/file.pdf` | Link text
@@ -1,20 +1,40 @@
1
1
  // Extension to track errors using google analytics as a data store.
2
2
  (function() {
3
-
4
3
  "use strict";
5
-
6
4
  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
7
5
 
8
- GOVUK.analyticsPlugins.error = function () {
6
+ GOVUK.analyticsPlugins.error = function (options) {
7
+ var options = options || {},
8
+ filenameMustMatch = options.filenameMustMatch;
9
+
9
10
  var trackJavaScriptError = function (e) {
10
- var errorSource = e.filename + ': ' + e.lineno;
11
- GOVUK.analytics.trackEvent('JavaScript Error', e.message, {
12
- label: errorSource,
13
- value: 1,
14
- nonInteraction: true
15
- });
11
+ var errorFilename = e.filename,
12
+ errorSource = errorFilename + ': ' + e.lineno;
13
+
14
+ if (shouldTrackThisError(errorFilename)) {
15
+ GOVUK.analytics.trackEvent('JavaScript Error', e.message, {
16
+ label: errorSource,
17
+ value: 1,
18
+ nonInteraction: true
19
+ });
20
+ }
16
21
  };
17
22
 
23
+ function shouldTrackThisError(errorFilename) {
24
+ // Errors in page should always be tracked
25
+ // If there's no filename filter, everything is tracked
26
+ if (!errorFilename || !filenameMustMatch) {
27
+ return true;
28
+ }
29
+
30
+ // If there's a filter and the error matches it, track it
31
+ if (filenameMustMatch.test(errorFilename)) {
32
+ return true;
33
+ }
34
+
35
+ return false;
36
+ }
37
+
18
38
  if (window.addEventListener) {
19
39
  window.addEventListener('error', trackJavaScriptError, false);
20
40
  } else if (window.attachEvent) {
@@ -23,5 +43,4 @@
23
43
  window.onerror = trackJavaScriptError;
24
44
  }
25
45
  }
26
-
27
46
  }());
@@ -19,7 +19,7 @@
19
19
  $elms = $(elmsOrSelector);
20
20
  this.selector = elmsOrSelector;
21
21
  this.setInitialState($(this.selector));
22
- } else {
22
+ } else if (elmsOrSelector !== undefined) {
23
23
  this.$elms = elmsOrSelector;
24
24
  this.setInitialState(this.$elms);
25
25
  }
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
  set -e
3
3
 
4
- bundle install
4
+ bundle install --path "${HOME}/bundles/${JOB_NAME}"
5
5
  npm install
6
6
  npm test
7
7
 
@@ -9,6 +9,7 @@ var manifest = {
9
9
  '../../javascripts/govuk/selection-buttons.js',
10
10
  '../../javascripts/govuk/analytics/google-analytics-universal-tracker.js',
11
11
  '../../javascripts/govuk/analytics/analytics.js',
12
+ '../../javascripts/govuk/analytics/error-tracking.js',
12
13
  '../../javascripts/govuk/analytics/external-link-tracker.js',
13
14
  '../../javascripts/govuk/analytics/download-link-tracker.js'
14
15
  ],
@@ -19,6 +20,7 @@ var manifest = {
19
20
  '../unit/SelectionButtonSpec.js',
20
21
  '../unit/analytics/GoogleAnalyticsUniversalTrackerSpec.js',
21
22
  '../unit/analytics/AnalyticsSpec.js',
23
+ '../unit/analytics/ErrorTrackingSpec.js',
22
24
  '../unit/analytics/ExternalLinkTrackerSpec.js',
23
25
  '../unit/analytics/DownloadLinkTrackerSpec.js'
24
26
  ]
@@ -0,0 +1,60 @@
1
+ describe("GOVUK.analyticsPlugins.error", function() {
2
+ GOVUK.analyticsPlugins.error({filenameMustMatch: /gov\.uk/});
3
+
4
+ beforeEach(function() {
5
+ GOVUK.analytics = {trackEvent:function(){}};
6
+ spyOn(GOVUK.analytics, 'trackEvent');
7
+ });
8
+
9
+ afterEach(function() {
10
+ delete GOVUK.analytics;
11
+ });
12
+
13
+ it('sends errors to Google Analytics', function() {
14
+ triggerError('https://www.gov.uk/filename.js', 2, 'Error message');
15
+
16
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
17
+ 'JavaScript Error',
18
+ 'Error message',
19
+ { label: 'https://www.gov.uk/filename.js: 2', value: 1, nonInteraction: true });
20
+ });
21
+
22
+ it('tracks only errors with a matching or blank filename', function() {
23
+ triggerError('http://www.gov.uk/somefile.js', 2, 'Error message');
24
+ triggerError('', 2, 'In page error');
25
+ triggerError('http://www.broken-external-plugin-site.com/horrible.js', 2, 'Error message');
26
+
27
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
28
+ 'JavaScript Error',
29
+ 'Error message',
30
+ {
31
+ label: 'http://www.gov.uk/somefile.js: 2',
32
+ value: 1,
33
+ nonInteraction: true });
34
+
35
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
36
+ 'JavaScript Error',
37
+ 'In page error',
38
+ {
39
+ label: ': 2',
40
+ value: 1,
41
+ nonInteraction: true });
42
+
43
+ expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith(
44
+ 'JavaScript Error',
45
+ 'Error message',
46
+ {
47
+ label: 'http://www.broken-external-plugin-site.com/horrible.js: 2',
48
+ value: 1,
49
+ nonInteraction: true });
50
+ });
51
+
52
+ function triggerError(filename, lineno, message) {
53
+ var event = document.createEvent('Event');
54
+ event.initEvent('error', true, true);
55
+ event.filename = filename;
56
+ event.lineno = lineno;
57
+ event.message = message;
58
+ window.dispatchEvent(event);
59
+ }
60
+ });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_frontend_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-10 00:00:00.000000000 Z
12
+ date: 2015-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -258,6 +258,7 @@ files:
258
258
  - app/assets/spec/unit/StickAtTopWhenScrollingSpec.js
259
259
  - app/assets/spec/unit/analytics/AnalyticsSpec.js
260
260
  - app/assets/spec/unit/analytics/DownloadLinkTrackerSpec.js
261
+ - app/assets/spec/unit/analytics/ErrorTrackingSpec.js
261
262
  - app/assets/spec/unit/analytics/ExternalLinkTrackerSpec.js
262
263
  - app/assets/spec/unit/analytics/GoogleAnalyticsUniversalTrackerSpec.js
263
264
  - app/assets/stylesheets/.gitkeep
@@ -290,7 +291,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
290
291
  version: '0'
291
292
  segments:
292
293
  - 0
293
- hash: 1621947879198533180
294
+ hash: 1001305014484830517
294
295
  required_rubygems_version: !ruby/object:Gem::Requirement
295
296
  none: false
296
297
  requirements:
@@ -299,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
299
300
  version: '0'
300
301
  segments:
301
302
  - 0
302
- hash: 1621947879198533180
303
+ hash: 1001305014484830517
303
304
  requirements: []
304
305
  rubyforge_project:
305
306
  rubygems_version: 1.8.23