govuk_frontend_toolkit 5.1.2 → 5.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 177c21aaa74abca4dfa655928bb2f6742e1e046f
4
- data.tar.gz: 2743d40802f0408afcd2618e227f7f22432d8ec2
3
+ metadata.gz: a82ba1d90400414889eccb25aaa31d8bb7a501b1
4
+ data.tar.gz: ba6c1ef52e25342be951a80f9399fa0f2e1de113
5
5
  SHA512:
6
- metadata.gz: 2de75c8841daa62163dc4d7ec1cfa9c7390b897264ee35231bb594db1350b72690d8a1a1093746eb79d2ca33dd8e32d1c14f704d76142d4bc2e6a8f6f6a8b5b6
7
- data.tar.gz: 00e6cb4ccb8133885947b119987287667341d0d3ec0bf10d21754cb14ee6d2af79d551fbc0220f8c6e645e93e6b186b2971a08387e23a0732722f7df8d9d3f3a
6
+ metadata.gz: 96eb1d31eed114633be86dbed4b4882f64acf47f5694e861e7189b6f5a29656b3dcfe5ecdd6d035e9c6377d30f13d160be7c434f733dff65fff6cce383a11446
7
+ data.tar.gz: 5451ede4e5a42621ccb09482a817f4f3b033f85e860223b867b33870aac6a7e63426f927f42cb357e6e4c0d45a19355007d0e999600454abc1750322e2b56924
@@ -5,18 +5,11 @@ node_js:
5
5
  before_install:
6
6
  # Node project, so Ruby dependencies must be installed manually (see `govuk-lint`)
7
7
  - bundle install
8
- - git config --global user.name "Travis CI"
9
- - git config --global user.email "travis@travis-ci.org"
10
- - git remote add origin_ssh git@github.com:alphagov/govuk_frontend_toolkit.git
11
- # Encrypted SSH config used to `push.sh` to Github (See `.travis/README.md`)
12
- - 'if [ "$TRAVIS_PULL_REQUEST_BRANCH" = "master" ]; then openssl aes-256-cbc -K $encrypted_909ac1036a94_key -iv $encrypted_909ac1036a94_iv -in .travis/govuk_frontend_toolkit_push.enc -out ~/.ssh/id_rsa -d && chmod 600 ~/.ssh/id_rsa; fi'
13
- script:
14
- - npm test
15
8
  before_deploy:
16
9
  - test $TRAVIS_TEST_RESULT = 0
17
10
  deploy:
18
11
  - provider: script
19
- script: './push.sh'
12
+ script: './create-release.sh'
20
13
  on:
21
14
  branch: master
22
15
  - provider: script
@@ -6,7 +6,9 @@ The public key is a deploy key which has been added to the GitHub repo for push
6
6
 
7
7
  The private key is encrypted using `travis encrypt-file` and then committed to this repo.
8
8
 
9
- The decrypt commands are in `.travis.yml`.
9
+ The decrypt commands are in `.travis.yml`. We only decrypt these files on the master
10
+ branch because people who have forked the repo don't have access to the
11
+ `$encrypted` environment variables.
10
12
 
11
13
  ## Trigger script
12
14
 
@@ -1,3 +1,7 @@
1
+ # 5.1.3
2
+
3
+ - Add an experimental GOV.UK analytics tracker. Given the URL to a single pixel GIF, it will encode analytics data as query string parameters on the call to the GIF ([PR #387](https://github.com/alphagov/govuk_frontend_toolkit/pull/387))
4
+
1
5
  # 5.1.2
2
6
 
3
7
  - Update show-hide-content.js to work with new `.multiple-choice` custom radio buttons and checkboxes, released in GOV.UK elements 3.0.0 ([PR #390](https://github.com/alphagov/govuk_frontend_toolkit/pull/390))
@@ -32,6 +32,7 @@ module.exports = function (grunt) {
32
32
  src: [
33
33
  'node_modules/jquery/dist/jquery.js',
34
34
  'javascripts/govuk/analytics/google-analytics-universal-tracker.js',
35
+ 'javascripts/govuk/analytics/govuk-tracker.js',
35
36
  'javascripts/govuk/analytics/analytics.js',
36
37
  'javascripts/**/*.js'
37
38
  ],
@@ -1 +1 @@
1
- 5.1.2
1
+ 5.1.3
@@ -0,0 +1,38 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ REPO_PATH="alphagov/govuk_frontend_toolkit"
5
+
6
+ echo "Add config for alphagov/$REPO_PATH"
7
+
8
+ git config --global user.name "Travis CI"
9
+ git config --global user.email "travis@travis-ci.org"
10
+ git remote add origin_ssh git@github.com:$REPO_PATH.git
11
+
12
+ # This openssl command was generated automatically by `travis encrypt-file`, see `.travis/README.md` for more details
13
+ openssl aes-256-cbc -K $encrypted_909ac1036a94_key -iv $encrypted_909ac1036a94_iv -in .travis/govuk_frontend_toolkit_push.enc -out ~/.ssh/id_rsa -d
14
+ chmod 600 ~/.ssh/id_rsa
15
+
16
+ echo "Check to see if the version file has been updated"
17
+
18
+ # get the version from the version file
19
+ VERSION_TAG="v`cat VERSION.txt`"
20
+
21
+ # Create a new tag - if the version file has been updated and a tag for that
22
+ # version doesn't already exist
23
+
24
+ # check to make sure the tag doesn't already exist
25
+ if ! git rev-parse $VERSION_TAG >/dev/null 2>&1; then
26
+ echo "Creating new tag: $VERSION_TAG"
27
+
28
+ # Create a new tag and push to Github
29
+ git tag $VERSION_TAG
30
+ git push origin_ssh $VERSION_TAG
31
+
32
+ # Alias branch for the most recently released tag, for easier diffing
33
+ # Force push local `master` branch to the `latest-release` branch on Github
34
+ git push --force origin_ssh master:latest-release
35
+ echo "Pushed latest-release branch to GitHub"
36
+ else
37
+ echo "Not creating a new tag, or updating the latest-release branch as the tag already exists..."
38
+ fi
@@ -13,6 +13,11 @@
13
13
  delete config.universalId
14
14
  this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config))
15
15
  }
16
+ if (typeof config.govukTrackerGifUrl !== 'undefined') {
17
+ var govukTrackerGifUrl = config.govukTrackerGifUrl
18
+ delete config.govukTrackerGifUrl
19
+ this.trackers.push(new GOVUK.GOVUKTracker(govukTrackerGifUrl))
20
+ }
16
21
  }
17
22
 
18
23
  Analytics.prototype.sendToTrackers = function (method, args) {
@@ -28,6 +33,7 @@
28
33
 
29
34
  Analytics.load = function () {
30
35
  GOVUK.GoogleAnalyticsUniversalTracker.load()
36
+ GOVUK.GOVUKTracker.load()
31
37
  }
32
38
 
33
39
  Analytics.prototype.trackPageview = function (path, title, options) {
@@ -0,0 +1,128 @@
1
+ ;(function (global) {
2
+ 'use strict'
3
+
4
+ var $ = global.jQuery
5
+ var GOVUK = global.GOVUK || {}
6
+
7
+ var GOVUKTracker = function (gifUrl) {
8
+ this.gifUrl = gifUrl
9
+ this.dimensions = []
10
+ if (global.ga) {
11
+ global.ga(function (tracker) {
12
+ this.gaClientId = tracker.get('clientId')
13
+ }.bind(this))
14
+ }
15
+ }
16
+
17
+ GOVUKTracker.load = function () {}
18
+
19
+ GOVUKTracker.prototype.trackPageview = function (path, title, options) {
20
+ var pageviewObject
21
+
22
+ if (typeof path === 'string') {
23
+ pageviewObject = { page: path }
24
+ }
25
+
26
+ if (typeof title === 'string') {
27
+ pageviewObject = pageviewObject || {}
28
+ pageviewObject.title = title
29
+ }
30
+
31
+ // Set an options object for the pageview (e.g. transport, sessionControl)
32
+ // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
33
+ if (typeof options === 'object') {
34
+ pageviewObject = $.extend(pageviewObject || {}, options)
35
+ }
36
+
37
+ if (!$.isEmptyObject(pageviewObject)) {
38
+ this.sendToTracker('pageview', pageviewObject)
39
+ } else {
40
+ this.sendToTracker('pageview')
41
+ }
42
+ }
43
+
44
+ // https://developers.google.com/analytics/devguides/collection/analyticsjs/events
45
+ GOVUKTracker.prototype.trackEvent = function (category, action, options) {
46
+ options = options || {}
47
+ var evt = {
48
+ eventCategory: category,
49
+ eventAction: action
50
+ }
51
+
52
+ if (options.label) {
53
+ evt.eventLabel = options.label
54
+ delete options.label
55
+ }
56
+
57
+ if (options.value) {
58
+ evt.eventValue = options.value.toString()
59
+ delete options.value
60
+ }
61
+
62
+ if (typeof options === 'object') {
63
+ $.extend(evt, options)
64
+ }
65
+
66
+ this.sendToTracker('event', evt)
67
+ }
68
+
69
+ GOVUKTracker.prototype.trackSocial = function (network, action, target) {
70
+ this.sendToTracker('social', {
71
+ 'socialNetwork': network,
72
+ 'socialAction': action,
73
+ 'socialTarget': target
74
+ })
75
+ }
76
+
77
+ GOVUKTracker.prototype.addLinkedTrackerDomain = function () { /* noop */ }
78
+
79
+ GOVUKTracker.prototype.setDimension = function (index, value) {
80
+ this.dimensions['dimension' + index] = value
81
+ }
82
+
83
+ GOVUKTracker.prototype.payloadParams = function (type, payload) {
84
+ var data = $.extend({},
85
+ payload,
86
+ this.dimensions,
87
+ {
88
+ eventType: type,
89
+ referrer: global.document.referrer,
90
+ gaClientId: this.gaClientId,
91
+ windowWidth: global.innerWidth,
92
+ windowHeight: global.innerHeight,
93
+ screenWidth: global.screen.width,
94
+ screenHeight: global.screen.height,
95
+ colorDepth: global.screen.colorDepth
96
+ }
97
+ )
98
+
99
+ if (global.performance) {
100
+ data.navigationType = global.performance.navigation.type.toString()
101
+ data.redirectCount = global.performance.navigation.redirectCount.toString()
102
+
103
+ for (var k in global.performance.timing) {
104
+ var v = global.performance.timing[k]
105
+ if (typeof v === 'string' || typeof v === 'number') {
106
+ data['timing_' + k] = v.toString()
107
+ }
108
+ }
109
+ }
110
+
111
+ return data
112
+ }
113
+
114
+ GOVUKTracker.prototype.sendData = function (params) {
115
+ var url = this.gifUrl + '?' + $.param(params)
116
+ $.get(url)
117
+ }
118
+
119
+ GOVUKTracker.prototype.sendToTracker = function (type, payload) {
120
+ $(global.document).ready(function () {
121
+ this.sendData(this.payloadParams(type, payload))
122
+ }.bind(this))
123
+ }
124
+
125
+ GOVUK.GOVUKTracker = GOVUKTracker
126
+
127
+ global.GOVUK = GOVUK
128
+ })(window)
@@ -12,6 +12,7 @@ var manifest = {
12
12
  '../../javascripts/govuk/stop-scrolling-at-footer.js',
13
13
  '../../javascripts/govuk/selection-buttons.js',
14
14
  '../../javascripts/govuk/analytics/google-analytics-universal-tracker.js',
15
+ '../../javascripts/govuk/analytics/govuk-tracker.js',
15
16
  '../../javascripts/govuk/analytics/analytics.js',
16
17
  '../../javascripts/govuk/analytics/error-tracking.js',
17
18
  '../../javascripts/govuk/analytics/external-link-tracker.js',
@@ -28,6 +29,7 @@ var manifest = {
28
29
  '../unit/stick-at-top-when-scrolling.spec.js',
29
30
  '../unit/selection-button.spec.js',
30
31
  '../unit/analytics/google-analytics-universal-tracker.spec.js',
32
+ '../unit/analytics/govuk-tracker.spec.js',
31
33
  '../unit/analytics/analytics.spec.js',
32
34
  '../unit/analytics/error-tracking.spec.js',
33
35
  '../unit/analytics/external-link-tracker.spec.js',
@@ -0,0 +1,152 @@
1
+ /* global describe it expect beforeEach spyOn jasmine */
2
+
3
+ var $ = window.jQuery
4
+
5
+ describe('GOVUK.GOVUKTracker', function () {
6
+ 'use strict'
7
+ var GOVUK = window.GOVUK
8
+
9
+ var tracker
10
+
11
+ beforeEach(function () {
12
+ tracker = new GOVUK.GOVUKTracker('http://www.example.com/a.gif')
13
+ })
14
+
15
+ describe('sendData', function () {
16
+ it('sends the data using AJAX', function () {
17
+ spyOn($, 'get')
18
+
19
+ tracker.sendData({foo: 'bar'})
20
+ expect($.get).toHaveBeenCalledWith('http://www.example.com/a.gif?foo=bar')
21
+ })
22
+ })
23
+
24
+ describe('payloadParams', function () {
25
+ it('adds the event type', function () {
26
+ var params = tracker.payloadParams('foo', {bar: 'qux'})
27
+
28
+ expect(params.eventType).toEqual('foo')
29
+ expect(params.bar).toEqual('qux')
30
+ })
31
+
32
+ it('adds the GA Client ID', function () {
33
+ tracker.gaClientId = '123456.789012'
34
+ var params = tracker.payloadParams('foo')
35
+
36
+ expect(params.gaClientId).toEqual('123456.789012')
37
+ })
38
+
39
+ it('adds the referrer', function () {
40
+ var params = tracker.payloadParams('foo')
41
+
42
+ // Can't stub window.referrer so just test that we got a string, not undefined
43
+ expect(typeof params.referrer).toEqual('string')
44
+ })
45
+
46
+ it('adds performance data', function () {
47
+ var params = tracker.payloadParams('foo')
48
+
49
+ expect(params.navigationType).toEqual('0')
50
+ expect(params.redirectCount).toEqual('0')
51
+
52
+ expect(params.timing_domComplete).toEqual(window.performance.timing.domComplete.toString())
53
+ })
54
+
55
+ it('adds custom dimensions', function () {
56
+ tracker.setDimension(1, 'foo')
57
+ tracker.setDimension(10, 'bar')
58
+ var params = tracker.payloadParams('foo')
59
+
60
+ expect(params.dimension1).toEqual('foo')
61
+ expect(params.dimension10).toEqual('bar')
62
+ })
63
+
64
+ it('adds screen and window measurements', function () {
65
+ var params = tracker.payloadParams('foo')
66
+
67
+ expect(params.screenWidth).toEqual(window.screen.width)
68
+ expect(params.screenHeight).toEqual(window.screen.height)
69
+ expect(params.windowWidth).toEqual(window.innerWidth)
70
+ expect(params.windowHeight).toEqual(window.innerHeight)
71
+ expect(params.colorDepth).toEqual(window.screen.colorDepth)
72
+ })
73
+ })
74
+
75
+ describe('sendToTracker', function () {
76
+ it('sends when the DOM is complete', function () {
77
+ spyOn(tracker, 'sendData')
78
+ tracker.sendToTracker('foo')
79
+
80
+ expect(tracker.sendData).toHaveBeenCalledWith(jasmine.any(Object))
81
+ })
82
+ })
83
+
84
+ describe('tracking', function () {
85
+ beforeEach(function () {
86
+ spyOn(tracker, 'sendToTracker')
87
+ })
88
+
89
+ describe('when pageviews are tracked', function () {
90
+ it('sends them to the tracker', function () {
91
+ tracker.trackPageview()
92
+ expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(['pageview'])
93
+ })
94
+ })
95
+
96
+ describe('when events are tracked', function () {
97
+ it('sends them to the tracker', function () {
98
+ tracker.trackEvent('category', 'action', {label: 'label'})
99
+ expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(
100
+ ['event', {eventCategory: 'category', eventAction: 'action', eventLabel: 'label'}]
101
+ )
102
+ })
103
+
104
+ it('tracks custom dimensions', function () {
105
+ tracker.trackEvent('category', 'action', {dimension29: 'Home'})
106
+ expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(
107
+ ['event', {eventCategory: 'category', eventAction: 'action', dimension29: 'Home'}]
108
+ )
109
+ })
110
+
111
+ it('the label is optional', function () {
112
+ tracker.trackEvent('category', 'action')
113
+ expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(
114
+ ['event', {eventCategory: 'category', eventAction: 'action'}]
115
+ )
116
+ })
117
+
118
+ it('sends the page if supplied', function () {
119
+ tracker.trackEvent('category', 'action', {page: '/path/to/page'})
120
+ expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(
121
+ ['event', {eventCategory: 'category', eventAction: 'action', page: '/path/to/page'}]
122
+ )
123
+ })
124
+
125
+ it('tracks multiple events', function () {
126
+ tracker.trackEvent('category', 'action', {label: 'foo'})
127
+ tracker.trackEvent('category', 'action', {label: 'bar'})
128
+
129
+ expect(tracker.sendToTracker).toHaveBeenCalledWith(
130
+ 'event', {eventCategory: 'category', eventAction: 'action', eventLabel: 'foo'}
131
+ )
132
+ expect(tracker.sendToTracker).toHaveBeenCalledWith(
133
+ 'event', {eventCategory: 'category', eventAction: 'action', eventLabel: 'bar'}
134
+ )
135
+ })
136
+ })
137
+
138
+ describe('when social events are tracked', function () {
139
+ it('sends them to Google Analytics', function () {
140
+ tracker.trackSocial('network', 'action', 'target')
141
+ expect(tracker.sendToTracker.calls.mostRecent().args).toEqual([
142
+ 'social',
143
+ {
144
+ 'socialNetwork': 'network',
145
+ 'socialAction': 'action',
146
+ 'socialTarget': 'target'
147
+ }
148
+ ])
149
+ })
150
+ })
151
+ })
152
+ })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_frontend_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.2
4
+ version: 5.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-17 00:00:00.000000000 Z
11
+ date: 2017-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -84,6 +84,7 @@ files:
84
84
  - app/assets/LICENCE
85
85
  - app/assets/README.md
86
86
  - app/assets/VERSION.txt
87
+ - app/assets/create-release.sh
87
88
  - app/assets/docs/analytics.md
88
89
  - app/assets/docs/functions.md
89
90
  - app/assets/docs/javascript.md
@@ -221,6 +222,7 @@ files:
221
222
  - app/assets/javascripts/govuk/analytics/error-tracking.js
222
223
  - app/assets/javascripts/govuk/analytics/external-link-tracker.js
223
224
  - app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js
225
+ - app/assets/javascripts/govuk/analytics/govuk-tracker.js
224
226
  - app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
225
227
  - app/assets/javascripts/govuk/analytics/print-intent.js
226
228
  - app/assets/javascripts/govuk/modules.js
@@ -237,7 +239,6 @@ files:
237
239
  - app/assets/javascripts/vendor/jquery/jquery.player.min.js
238
240
  - app/assets/javascripts/vendor/polyfills/bind.js
239
241
  - app/assets/package.json
240
- - app/assets/push.sh
241
242
  - app/assets/spec/manifest.js
242
243
  - app/assets/spec/stylesheets/_colour_contrast_spec.scss
243
244
  - app/assets/spec/support/LocalTestRunner.html
@@ -249,6 +250,7 @@ files:
249
250
  - app/assets/spec/unit/analytics/error-tracking.spec.js
250
251
  - app/assets/spec/unit/analytics/external-link-tracker.spec.js
251
252
  - app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js
253
+ - app/assets/spec/unit/analytics/govuk-tracker.spec.js
252
254
  - app/assets/spec/unit/analytics/mailto-link-tracker.spec.js
253
255
  - app/assets/spec/unit/modules.spec.js
254
256
  - app/assets/spec/unit/modules/auto-track-event.spec.js
@@ -1,23 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- # Create a new tag if the version file has been updated and a tag for that
5
- # version doesn't already exist
6
-
7
- # Are we on master branch, we shouldn't push tags for version bump branches
8
- MASTER_SHA=`git rev-parse origin/master`
9
- HEAD_SHA=`git rev-parse HEAD`
10
- if [ "$MASTER_SHA" == "$HEAD_SHA" ]; then
11
- # get the version from the version file
12
- VERSION_TAG="v`cat VERSION.txt`"
13
-
14
- # check to make sure the tag doesn't already exist
15
- if ! git rev-parse $VERSION_TAG >/dev/null 2>&1; then
16
- echo "Creating new tag: $VERSION_TAG"
17
- git tag $VERSION_TAG
18
- git push origin_ssh $VERSION_TAG
19
-
20
- # Alias branch for the most recently released tag, for easier diffing
21
- git push -f origin_ssh master:latest-release
22
- fi
23
- fi