govuk_frontend_toolkit 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,11 @@
1
+ # 4.2.0
2
+
3
+ - Add two analytics plugins for download and external link tracking
4
+ - Update typography mixins to be mobile first (PR #157)
5
+
1
6
  # 4.1.1
2
7
 
3
- - Update Accessible Media Player to remove dependency on $.browser (PR #206)
8
+ - Update Accessible Media Player to remove dependency on $.browser (PR #206)
4
9
 
5
10
  # 4.1.0
6
11
 
@@ -1 +1 @@
1
- 4.1.1
1
+ 4.2.0
@@ -140,14 +140,6 @@ function setPixelDensityDimension(pixelDensity) {
140
140
  }
141
141
  ```
142
142
 
143
- ## Print tracking
144
-
145
- Pull `print-intent.js` into your project, and initialise it after analytics (see [Create an analytics tracker, above](#create-an-analytics-tracker)), to track when users are attempting to print content.
146
-
147
- ## Error tracking
148
-
149
- Pull `error-tracking.js` into your project, and initialise it after analytics (see [Create an analytics tracker, above](#create-an-analytics-tracker)), to track JavaScript errors.
150
-
151
143
  ## Tracking across domains
152
144
 
153
145
  Once an Analytics instance has been created, tracking across domains can be set up
@@ -159,3 +151,50 @@ GOVUK.analytics.addLinkedTrackerDomain(trackerIdHere, nameForTracker, domainToLi
159
151
 
160
152
  Once this is done hits to that page will be tracked in both your local and the
161
153
  named tracker, and sessions will persist to the other domain.
154
+
155
+ ## Plugins
156
+
157
+ Plugins are namespaced to `GOVUK.analyticsPlugins`. They should be pulled in by your project and initialised after `GOVUK.analytics` (see [Create an analytics tracker, above](#create-an-analytics-tracker)).
158
+
159
+ ### Print tracking (`print-intent.js`)
160
+
161
+ Track when users are attempting to print content. The plugin sends a `Print intent` event and a `/print` prefixed pageview:
162
+
163
+ Example event:
164
+
165
+ Category | Action
166
+ ---------|-------
167
+ Print Intent | `/current/page`
168
+
169
+ Example pageview:
170
+
171
+ `/print/current/page`
172
+
173
+ ### Error tracking (`error-tracking.js`)
174
+
175
+ Track JavaScript errors, capturing the error message, file and line number. These events don’t affect bounce rate.
176
+
177
+ Category | Action | Label | Value
178
+ ---------|--------|-------|-------
179
+ JavaScript Error | The error message | file.js: line number | 1
180
+
181
+ ### External link tracking (`external-link-tracker.js`)
182
+
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.
184
+
185
+ Category | Action | Label
186
+ ---------|--------|-------
187
+ External Link Clicked | http://www.some-external-website.com | Link text
188
+
189
+
190
+ ### Download link tracking (`download-link-tracker.js`)
191
+
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.
193
+
194
+ ```js
195
+ GOVUK.analyticsPlugins.downloadTracker({selector: 'a[rel=download]'});
196
+ ```
197
+
198
+ Page | Page title
199
+ -----|-----------
200
+ `/some/upload/attachment/file.pdf` | Link text
@@ -350,6 +350,8 @@ Tabular numbers have numerals of a standard fixed width. As all numbers have the
350
350
  @include core-24($tabular-numbers: true);
351
351
  }
352
352
 
353
+ [See an example of tabular numbers in a table](http://govuk-elements.herokuapp.com/#data-in-a-table)
354
+
353
355
  #### external links
354
356
 
355
357
  `external-link-default` sets up the background image for all external links.
@@ -27,7 +27,7 @@
27
27
  GOVUK.GoogleAnalyticsUniversalTracker.load();
28
28
  };
29
29
 
30
- Analytics.prototype.trackPageview = function(path, title) {
30
+ Analytics.prototype.trackPageview = function(path, title, options) {
31
31
  this.sendToTrackers('trackPageview', arguments);
32
32
  };
33
33
 
@@ -0,0 +1,30 @@
1
+ (function() {
2
+ "use strict";
3
+ GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
4
+ GOVUK.analyticsPlugins.downloadLinkTracker = function (options) {
5
+ var options = options || {},
6
+ downloadLinkSelector = options.selector;
7
+
8
+ if (downloadLinkSelector) {
9
+ $('body').on('click', downloadLinkSelector, trackDownload);
10
+ }
11
+
12
+ function trackDownload(evt) {
13
+ var $link = getLinkFromEvent(evt),
14
+ href = $link.attr('href'),
15
+ linkText = $.trim($link.text());
16
+
17
+ GOVUK.analytics.trackPageview(href, linkText, {transport: 'beacon'});
18
+ }
19
+
20
+ function getLinkFromEvent(evt) {
21
+ var $target = $(evt.target);
22
+
23
+ if (!$target.is('a')) {
24
+ $target = $target.parents('a');
25
+ }
26
+
27
+ return $target;
28
+ }
29
+ }
30
+ }());
@@ -0,0 +1,38 @@
1
+ (function() {
2
+ "use strict";
3
+ GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
4
+ GOVUK.analyticsPlugins.externalLinkTracker = function () {
5
+
6
+ var currentHost = GOVUK.analyticsPlugins.externalLinkTracker.getHostname(),
7
+ externalLinkSelector = 'a[href^="http"]:not(a[href*="' + currentHost + '"])';
8
+
9
+ $('body').on('click', externalLinkSelector, trackClickEvent);
10
+
11
+ function trackClickEvent(evt) {
12
+ var $link = getLinkFromEvent(evt),
13
+ options = {transport: 'beacon'},
14
+ href = $link.attr('href'),
15
+ linkText = $.trim($link.text());
16
+
17
+ if (linkText) {
18
+ options.label = linkText;
19
+ }
20
+
21
+ GOVUK.analytics.trackEvent('External Link Clicked', href, options);
22
+ }
23
+
24
+ function getLinkFromEvent(evt) {
25
+ var $target = $(evt.target);
26
+
27
+ if (!$target.is('a')) {
28
+ $target = $target.parents('a');
29
+ }
30
+
31
+ return $target;
32
+ }
33
+ }
34
+
35
+ GOVUK.analyticsPlugins.externalLinkTracker.getHostname = function() {
36
+ return window.location.hostname;
37
+ }
38
+ }());
@@ -24,7 +24,9 @@
24
24
  };
25
25
 
26
26
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
27
- GoogleAnalyticsUniversalTracker.prototype.trackPageview = function(path, title) {
27
+ GoogleAnalyticsUniversalTracker.prototype.trackPageview = function(path, title, options) {
28
+ var options = options || {};
29
+
28
30
  if (typeof path === "string") {
29
31
  var pageviewObject = {
30
32
  page: path
@@ -33,6 +35,14 @@
33
35
  if (typeof title === "string") {
34
36
  pageviewObject.title = title;
35
37
  }
38
+
39
+ // Set the transport method for the pageview
40
+ // Typically used for enabling `navigator.sendBeacon` when the page might be unloading
41
+ // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
42
+ if (options.transport) {
43
+ pageviewObject.transport = options.transport;
44
+ }
45
+
36
46
  sendToGa('send', 'pageview', pageviewObject);
37
47
  } else {
38
48
  sendToGa('send', 'pageview');
@@ -75,6 +85,13 @@
75
85
  evt.nonInteraction = 1;
76
86
  }
77
87
 
88
+ // Set the transport method for the event
89
+ // Typically used for enabling `navigator.sendBeacon` when the page might be unloading
90
+ // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
91
+ if (options.transport) {
92
+ evt.transport = options.transport;
93
+ }
94
+
78
95
  sendToGa('send', evt);
79
96
  };
80
97
 
@@ -3,3 +3,21 @@ set -e
3
3
 
4
4
  npm install
5
5
  npm test
6
+
7
+ # Create a new tag if the version file has been updated and a tag for that
8
+ # version doesn't already exist
9
+
10
+ # Are we on master branch, we shouldn't push tags for version bump branches
11
+ MASTER_SHA=`git rev-parse origin/master`
12
+ HEAD_SHA=`git rev-parse HEAD`
13
+ if [ "$MASTER_SHA" == "$HEAD_SHA" ]; then
14
+ # get the version from the version file
15
+ VERSION_TAG="v`cat VERSION.TXT`"
16
+
17
+ # check to make sure the tag doesn't already exist
18
+ if ! git rev-parse $VERSION_TAG >/dev/null 2>&1; then
19
+ echo "Creating new tag: $VERSION_TAG"
20
+ git tag $VERSION_TAG
21
+ git push origin $VERSION_TAG
22
+ fi
23
+ fi
@@ -8,8 +8,9 @@ var manifest = {
8
8
  '../../javascripts/govuk/stop-scrolling-at-footer.js',
9
9
  '../../javascripts/govuk/selection-buttons.js',
10
10
  '../../javascripts/govuk/analytics/google-analytics-universal-tracker.js',
11
- '../../javascripts/govuk/analytics/analytics.js'
12
-
11
+ '../../javascripts/govuk/analytics/analytics.js',
12
+ '../../javascripts/govuk/analytics/external-link-tracker.js',
13
+ '../../javascripts/govuk/analytics/download-link-tracker.js'
13
14
  ],
14
15
  test : [
15
16
  '../unit/MultivariateTestSpec.js',
@@ -17,6 +18,8 @@ var manifest = {
17
18
  '../unit/StickAtTopWhenScrollingSpec.js',
18
19
  '../unit/SelectionButtonSpec.js',
19
20
  '../unit/analytics/GoogleAnalyticsUniversalTrackerSpec.js',
20
- '../unit/analytics/AnalyticsSpec.js'
21
+ '../unit/analytics/AnalyticsSpec.js',
22
+ '../unit/analytics/ExternalLinkTrackerSpec.js',
23
+ '../unit/analytics/DownloadLinkTrackerSpec.js'
21
24
  ]
22
25
  };
@@ -6,6 +6,10 @@ describe("MultivariateTest", function() {
6
6
  spyOn(GOVUK.analytics, "trackEvent");
7
7
  });
8
8
 
9
+ afterEach(function() {
10
+ delete GOVUK.analytics;
11
+ });
12
+
9
13
  describe("#run", function() {
10
14
  it("should pick a random cohort on first run", function() {
11
15
  GOVUK.cookie.and.returnValue(null);
@@ -0,0 +1,61 @@
1
+ describe("GOVUK.analyticsPlugins.downloadLinkTracker", function() {
2
+ var $links;
3
+
4
+ beforeEach(function() {
5
+ $links = $('\
6
+ <div class="download-links">\
7
+ <a href="/one.pdf">PDF</a>\
8
+ <a href="/two.xslt">Spreadsheet</a>\
9
+ <a href="/something/uploads/system/three.doc">Document</a>\
10
+ <a href="/an/image/link.png"><img src="/img" /></a>\
11
+ </div>\
12
+ <div class="normal-links">\
13
+ <a href="/normal-link">Normal link</a>\
14
+ <a href="/another-link">Another link</a>\
15
+ </div>');
16
+
17
+ $('html').on('click', function(evt) { evt.preventDefault(); });
18
+ $('body').append($links);
19
+ GOVUK.analytics = {trackPageview:function(){}};
20
+ GOVUK.analyticsPlugins.downloadLinkTracker({selector: 'a[href$=".pdf"], a[href$=".xslt"], a[href$=".doc"], a[href$=".png"]'});
21
+ });
22
+
23
+ afterEach(function() {
24
+ $('html').off();
25
+ $('body').off();
26
+ $links.remove();
27
+ delete GOVUK.analytics;
28
+ });
29
+
30
+ it('listens to clicks on links that match the selector', function() {
31
+ spyOn(GOVUK.analytics, 'trackPageview');
32
+
33
+ $('.download-links a').each(function() {
34
+ $(this).trigger('click');
35
+ expect(GOVUK.analytics.trackPageview).toHaveBeenCalled();
36
+ GOVUK.analytics.trackPageview.calls.reset();
37
+ });
38
+
39
+ $('.normal-links a').each(function() {
40
+ $(this).trigger('click');
41
+ expect(GOVUK.analytics.trackPageview).not.toHaveBeenCalled();
42
+ GOVUK.analytics.trackPageview.calls.reset();
43
+ });
44
+ });
45
+
46
+ it('listens to click events on elements within download links', function() {
47
+ spyOn(GOVUK.analytics, 'trackPageview');
48
+
49
+ $('.download-links a img').trigger('click');
50
+ expect(GOVUK.analytics.trackPageview).toHaveBeenCalledWith('/an/image/link.png', '', {transport: 'beacon'});
51
+ });
52
+
53
+ it('tracks a download link as a pageview with a custom title', function() {
54
+ spyOn(GOVUK.analytics, 'trackPageview');
55
+ $('.download-links a').trigger('click');
56
+
57
+ expect(GOVUK.analytics.trackPageview).toHaveBeenCalledWith('/one.pdf', 'PDF', {transport: 'beacon'});
58
+ expect(GOVUK.analytics.trackPageview).toHaveBeenCalledWith('/two.xslt', 'Spreadsheet', {transport: 'beacon'});
59
+ expect(GOVUK.analytics.trackPageview).toHaveBeenCalledWith('/something/uploads/system/three.doc', 'Document', {transport: 'beacon'});
60
+ });
61
+ });
@@ -0,0 +1,69 @@
1
+ describe("GOVUK.analyticsPlugins.externalLinkTracker", function() {
2
+ var $links;
3
+
4
+ beforeEach(function() {
5
+ $links = $('\
6
+ <div class="external-links">\
7
+ <a href="http://www.nationalarchives.gov.uk"> National Archives </a>\
8
+ <a href="https://www.nationalarchives.gov.uk"></a>\
9
+ <a href="https://www.nationalarchives.gov.uk/one.pdf">National Archives PDF</a>\
10
+ <a href="https://www.nationalarchives.gov.uk/an/image/link.png"><img src="/img" /></a>\
11
+ </div>\
12
+ <div class="internal-links">\
13
+ <a href="/some-path">Local link</a>\
14
+ <a href="http://fake-hostname.com/some-path">Another local link</a>\
15
+ </div>');
16
+
17
+ $('html').on('click', function(evt) { evt.preventDefault(); });
18
+ $('body').append($links);
19
+ GOVUK.analytics = {trackEvent:function(){}};
20
+
21
+ spyOn(GOVUK.analyticsPlugins.externalLinkTracker, 'getHostname').and.returnValue('fake-hostname.com');
22
+ GOVUK.analyticsPlugins.externalLinkTracker();
23
+ });
24
+
25
+ afterEach(function() {
26
+ $('html').off();
27
+ $('body').off();
28
+ $links.remove();
29
+ delete GOVUK.analytics;
30
+ });
31
+
32
+ it('listens to click events on only external links', function() {
33
+ spyOn(GOVUK.analytics, 'trackEvent');
34
+
35
+ $('.external-links a').each(function() {
36
+ $(this).trigger('click');
37
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalled();
38
+ GOVUK.analytics.trackEvent.calls.reset();
39
+ });
40
+
41
+ $('.internal-links a').each(function() {
42
+ $(this).trigger('click');
43
+ expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalled();
44
+ GOVUK.analytics.trackEvent.calls.reset();
45
+ });
46
+ });
47
+
48
+ it('listens to click events on elements within external links', function() {
49
+ spyOn(GOVUK.analytics, 'trackEvent');
50
+
51
+ $('.external-links a img').trigger('click');
52
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
53
+ 'External Link Clicked', 'https://www.nationalarchives.gov.uk/an/image/link.png', {transport: 'beacon'});
54
+ });
55
+
56
+ it('tracks an external link\'s href and link text', function() {
57
+ spyOn(GOVUK.analytics, 'trackEvent');
58
+ $('.external-links a').trigger('click');
59
+
60
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
61
+ 'External Link Clicked', 'http://www.nationalarchives.gov.uk', {transport: 'beacon', label: 'National Archives'});
62
+
63
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
64
+ 'External Link Clicked', 'https://www.nationalarchives.gov.uk', {transport: 'beacon'});
65
+
66
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
67
+ 'External Link Clicked', 'https://www.nationalarchives.gov.uk/one.pdf', {transport: 'beacon', label: 'National Archives PDF'});
68
+ });
69
+ });
@@ -49,6 +49,11 @@ describe("GOVUK.GoogleAnalyticsUniversalTracker", function() {
49
49
  universal.trackPageview('/nicholas-page', 'Nicholas Page');
50
50
  expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', {page: '/nicholas-page', title: 'Nicholas Page'}]);
51
51
  });
52
+
53
+ it('can set the transport method on a pageview', function() {
54
+ universal.trackPageview('/t', 'T', {transport: 'beacon'});
55
+ expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', {page: '/t', title: 'T', transport: 'beacon'}]);
56
+ });
52
57
  });
53
58
 
54
59
  describe('when events are tracked', function() {
@@ -101,6 +106,13 @@ describe("GOVUK.GoogleAnalyticsUniversalTracker", function() {
101
106
  ['send', {hitType: 'event', eventCategory: 'category', eventAction: 'action', page: '/path/to/page'}]
102
107
  );
103
108
  });
109
+
110
+ it('can set the transport method on an event', function() {
111
+ universal.trackEvent('category', 'action', {transport: 'beacon'});
112
+ expect(window.ga.calls.mostRecent().args).toEqual(
113
+ ['send', {hitType: 'event', eventCategory: 'category', eventAction: 'action', transport: 'beacon'}]
114
+ );
115
+ });
104
116
  });
105
117
 
106
118
  describe('when social events are tracked', function() {
@@ -25,17 +25,16 @@ $is-print: false !default;
25
25
  } @else {
26
26
  font-family: $NTA-Light;
27
27
  }
28
- @if $is-print == false {
29
- font-size: $font-size;
30
- } @else {
31
- font-size: $font-size-print;
32
- }
33
- line-height: $line-height;
28
+ font-size: $font-size-640;
29
+ line-height: $line-height-640;
34
30
  font-weight: $font-weight;
35
31
  text-transform: none;
36
- @media (max-width: 640px) {
37
- font-size: $font-size-640;
38
- line-height: $line-height-640;
32
+ @include media(tablet) {
33
+ font-size: $font-size;
34
+ line-height: $line-height;
35
+ }
36
+ @if $is-print {
37
+ font-size: $font-size-print;
39
38
  }
40
39
  }
41
40
 
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.1.1
4
+ version: 4.2.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-07-23 00:00:00.000000000 Z
12
+ date: 2015-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -231,7 +231,9 @@ files:
231
231
  - app/assets/images/player-icon-rewind.png
232
232
  - app/assets/images/player-icon-volume.png
233
233
  - app/assets/javascripts/govuk/analytics/analytics.js
234
+ - app/assets/javascripts/govuk/analytics/download-link-tracker.js
234
235
  - app/assets/javascripts/govuk/analytics/error-tracking.js
236
+ - app/assets/javascripts/govuk/analytics/external-link-tracker.js
235
237
  - app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js
236
238
  - app/assets/javascripts/govuk/analytics/print-intent.js
237
239
  - app/assets/javascripts/govuk/multivariate-test.js
@@ -255,6 +257,8 @@ files:
255
257
  - app/assets/spec/unit/SelectionButtonSpec.js
256
258
  - app/assets/spec/unit/StickAtTopWhenScrollingSpec.js
257
259
  - app/assets/spec/unit/analytics/AnalyticsSpec.js
260
+ - app/assets/spec/unit/analytics/DownloadLinkTrackerSpec.js
261
+ - app/assets/spec/unit/analytics/ExternalLinkTrackerSpec.js
258
262
  - app/assets/spec/unit/analytics/GoogleAnalyticsUniversalTrackerSpec.js
259
263
  - app/assets/stylesheets/.gitkeep
260
264
  - app/assets/stylesheets/_colours.scss
@@ -286,7 +290,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
286
290
  version: '0'
287
291
  segments:
288
292
  - 0
289
- hash: 1782922996850505618
293
+ hash: 793058166375182819
290
294
  required_rubygems_version: !ruby/object:Gem::Requirement
291
295
  none: false
292
296
  requirements:
@@ -295,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
299
  version: '0'
296
300
  segments:
297
301
  - 0
298
- hash: 1782922996850505618
302
+ hash: 793058166375182819
299
303
  requirements: []
300
304
  rubyforge_project:
301
305
  rubygems_version: 1.8.23