govuk_frontend_toolkit 8.0.0 → 8.1.0

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
  SHA256:
3
- metadata.gz: 9eca4727e35446219cf80f79e8559264aa2bab79f6d1d371829b78f4106a2a65
4
- data.tar.gz: b8d4e65a9307cf1c589c16c30500b056db62cf99dca73afcf63de1618cfd199c
3
+ metadata.gz: f34afb05f748a38078739d9b2595d60192ca1c27c47d693f4088e880dd339913
4
+ data.tar.gz: 19e14e37a076eabb3bcac4c252de97136bca744cee4ca378b7ad6c8502eddf12
5
5
  SHA512:
6
- metadata.gz: 8712fe56b8b70f7a957fa762dd49662ff7be56a914e9d82528f22c2c059b2dd850da9c2f7b3d1bcf7012500a0a28cd61749b13300d5f2ef427749fe7062bad3d
7
- data.tar.gz: 708b14100e3bdc27546944cacbd980df28dc6083d8e8d1ace9007d3ff7ed3434ecdada07a97019501181f6d57c6513fc8f83167569b73e84993159c866cd5f3a
6
+ metadata.gz: add984158bb8c3260fec46decd67bdfbe6feac075e00b28e581ae46561ab89f1c310d6845d69b27fa0a192b618b66d66c9504d722420024b44e180c89ccfee6f
7
+ data.tar.gz: 09bc9cd4dcac41b40ab1e8a16b138c139bbc2836d1a335e42cbfa0b0c290a5b35966d3f5db86f2383edde8590dc7fe98f9b2f58bc1fac920acdc24140ab1b61e
@@ -1,5 +1,12 @@
1
1
  # Unreleased
2
2
 
3
+ # 8.1.0
4
+
5
+ - Enables cross domain event tracking. Preserves previous cross domain pageview tracking behaviours but adds optional
6
+ abilities to send events to linked GA trackers.
7
+
8
+ ([PR 472](https://github.com/alphagov/govuk_frontend_toolkit/pull/472)).
9
+
3
10
  # 8.0.0
4
11
 
5
12
  - Breaking change: Add support for Google Analytics Universal in stageprompt.js
@@ -1 +1 @@
1
- 8.0.0
1
+ 8.1.0
@@ -74,6 +74,7 @@
74
74
  GoogleAnalyticsUniversalTracker.prototype.trackEvent = function (category, action, options) {
75
75
  options = options || {}
76
76
  var value
77
+ var trackerName = ''
77
78
  var evt = {
78
79
  hitType: 'event',
79
80
  eventCategory: category,
@@ -97,6 +98,12 @@
97
98
  delete options.value
98
99
  }
99
100
 
101
+ // trackerName is optional
102
+ if (typeof options.trackerName === 'string') {
103
+ trackerName = options.trackerName + '.'
104
+ delete options.trackerName
105
+ }
106
+
100
107
  // Prevents an event from affecting bounce rate
101
108
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation
102
109
  if (options.nonInteraction) {
@@ -107,7 +114,7 @@
107
114
  $.extend(evt, options)
108
115
  }
109
116
 
110
- sendToGa('send', evt)
117
+ sendToGa(trackerName + 'send', evt)
111
118
  }
112
119
 
113
120
  /*
@@ -132,11 +139,13 @@
132
139
 
133
140
  /*
134
141
  https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain
135
- trackerId - the UA account code to track the domain against
136
- name - name for the tracker
137
- domain - the domain to track
142
+ trackerId - the UA account code to track the domain against
143
+ name - name for the tracker
144
+ domain - the domain to track
145
+ sendPageView - optional argument which controls the legacy behaviour of sending a pageview
146
+ on creation of the linked domain.
138
147
  */
139
- GoogleAnalyticsUniversalTracker.prototype.addLinkedTrackerDomain = function (trackerId, name, domain) {
148
+ GoogleAnalyticsUniversalTracker.prototype.addLinkedTrackerDomain = function (trackerId, name, domain, sendPageView) {
140
149
  sendToGa('create',
141
150
  trackerId,
142
151
  'auto',
@@ -151,7 +160,10 @@
151
160
 
152
161
  sendToGa(name + '.set', 'anonymizeIp', true)
153
162
  sendToGa(name + '.set', 'displayFeaturesTask', null)
154
- sendToGa(name + '.send', 'pageview')
163
+
164
+ if (typeof sendPageView === 'undefined' || sendPageView === true) {
165
+ sendToGa(name + '.send', 'pageview')
166
+ }
155
167
  }
156
168
 
157
169
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
@@ -114,6 +114,13 @@ describe('GOVUK.GoogleAnalyticsUniversalTracker', function () {
114
114
  )
115
115
  })
116
116
 
117
+ it('the option trackerName overrides the default tracker', function () {
118
+ universal.trackEvent('category', 'action', {trackerName: 'testTracker'})
119
+ expect(window.ga.calls.mostRecent().args).toEqual(
120
+ ['testTracker.send', {hitType: 'event', eventCategory: 'category', eventAction: 'action'}]
121
+ )
122
+ })
123
+
117
124
  it('only sends values if they are parseable as numbers', function () {
118
125
  universal.trackEvent('category', 'action', {label: 'label', value: '10'})
119
126
  expect(eventObjectFromSpy()['eventValue']).toEqual(10)
@@ -184,4 +191,27 @@ describe('GOVUK.GoogleAnalyticsUniversalTracker', function () {
184
191
  expect(window.ga.calls.mostRecent().args[2]).toContain('address=[email]')
185
192
  })
186
193
  })
194
+
195
+ describe('adding a linked tracker', function () {
196
+ var callIndex
197
+
198
+ beforeEach(function () {
199
+ callIndex = window.ga.calls.count()
200
+ universal.addLinkedTrackerDomain('UA-123456', 'testTracker', 'some.service.gov.uk')
201
+ })
202
+ it('creates a tracker for the ID', function () {
203
+ expect(window.ga.calls.argsFor(callIndex)).toEqual(['create', 'UA-123456', 'auto', Object({ name: 'testTracker' })])
204
+ })
205
+ it('requires and configures the linker plugin', function () {
206
+ expect(window.ga.calls.argsFor(callIndex + 1)).toEqual(['require', 'linker'])
207
+ expect(window.ga.calls.argsFor(callIndex + 2)).toEqual(['testTracker.require', 'linker'])
208
+ })
209
+ it('sends a pageview', function () {
210
+ expect(window.ga.calls.mostRecent().args).toEqual(['testTracker.send', 'pageview'])
211
+ })
212
+ it('can omit sending a pageview', function () {
213
+ universal.addLinkedTrackerDomain('UA-123456', 'testTracker', 'some.service.gov.uk', false)
214
+ expect(window.ga.calls.mostRecent().args).not.toEqual(['testTracker.send', 'pageview'])
215
+ })
216
+ })
187
217
  })
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: 8.0.0
4
+ version: 8.1.0
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: 2018-09-26 00:00:00.000000000 Z
11
+ date: 2018-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties