govuk_frontend_toolkit 8.2.0 → 9.0.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 +4 -4
- data/README.md +9 -0
- data/app/assets/CHANGELOG.md +7 -1
- data/app/assets/Gruntfile.js +0 -3
- data/app/assets/README.md +3 -13
- data/app/assets/VERSION.txt +1 -1
- metadata +4 -19
- data/app/assets/docs/analytics.md +0 -272
- data/app/assets/javascripts/govuk/analytics/analytics.js +0 -153
- data/app/assets/javascripts/govuk/analytics/download-link-tracker.js +0 -41
- data/app/assets/javascripts/govuk/analytics/error-tracking.js +0 -51
- data/app/assets/javascripts/govuk/analytics/external-link-tracker.js +0 -56
- data/app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js +0 -194
- data/app/assets/javascripts/govuk/analytics/govuk-tracker.js +0 -134
- data/app/assets/javascripts/govuk/analytics/mailto-link-tracker.js +0 -38
- data/app/assets/javascripts/govuk/analytics/print-intent.js +0 -39
- data/app/assets/spec/unit/analytics/analytics.spec.js +0 -403
- data/app/assets/spec/unit/analytics/download-link-tracker.spec.js +0 -72
- data/app/assets/spec/unit/analytics/error-tracking.spec.js +0 -65
- data/app/assets/spec/unit/analytics/external-link-tracker.spec.js +0 -109
- data/app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js +0 -221
- data/app/assets/spec/unit/analytics/govuk-tracker.spec.js +0 -171
- data/app/assets/spec/unit/analytics/mailto-link-tracker.spec.js +0 -62
@@ -1,171 +0,0 @@
|
|
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
|
-
function setupFakeGa (clientId) {
|
12
|
-
window.ga = function (cb) {
|
13
|
-
cb({
|
14
|
-
get: function () { return clientId }
|
15
|
-
})
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
beforeEach(function () {
|
20
|
-
tracker = new GOVUK.GOVUKTracker('http://www.example.com/a.gif')
|
21
|
-
})
|
22
|
-
|
23
|
-
describe('sendData', function () {
|
24
|
-
it('sends the data using AJAX', function () {
|
25
|
-
spyOn($, 'get')
|
26
|
-
|
27
|
-
tracker.sendData({foo: 'bar'})
|
28
|
-
expect($.get).toHaveBeenCalledWith('http://www.example.com/a.gif?foo=bar')
|
29
|
-
})
|
30
|
-
})
|
31
|
-
|
32
|
-
describe('payloadParams', function () {
|
33
|
-
it('adds the event type', function () {
|
34
|
-
var params = tracker.payloadParams('foo', {bar: 'qux'})
|
35
|
-
|
36
|
-
expect(params.eventType).toEqual('foo')
|
37
|
-
expect(params.bar).toEqual('qux')
|
38
|
-
})
|
39
|
-
|
40
|
-
it('adds the GA Client ID', function () {
|
41
|
-
tracker.gaClientId = '123456.789012'
|
42
|
-
var params = tracker.payloadParams('foo')
|
43
|
-
|
44
|
-
expect(params.gaClientId).toEqual('123456.789012')
|
45
|
-
})
|
46
|
-
|
47
|
-
it('adds the referrer', function () {
|
48
|
-
var params = tracker.payloadParams('foo')
|
49
|
-
|
50
|
-
// Can't stub window.referrer so just test that we got a string, not undefined
|
51
|
-
expect(typeof params.referrer).toEqual('string')
|
52
|
-
})
|
53
|
-
|
54
|
-
it('adds performance data', function () {
|
55
|
-
var params = tracker.payloadParams('foo')
|
56
|
-
|
57
|
-
expect(params.navigationType).toEqual('0')
|
58
|
-
expect(params.redirectCount).toEqual('0')
|
59
|
-
|
60
|
-
expect(params.timing_domComplete).toEqual(window.performance.timing.domComplete.toString())
|
61
|
-
})
|
62
|
-
|
63
|
-
it('adds custom dimensions', function () {
|
64
|
-
tracker.setDimension(1, 'foo')
|
65
|
-
tracker.setDimension(10, 'bar')
|
66
|
-
var params = tracker.payloadParams('foo')
|
67
|
-
|
68
|
-
expect(params.dimension1).toEqual('foo')
|
69
|
-
expect(params.dimension10).toEqual('bar')
|
70
|
-
})
|
71
|
-
|
72
|
-
it('adds screen and window measurements', function () {
|
73
|
-
var params = tracker.payloadParams('foo')
|
74
|
-
|
75
|
-
expect(params.screenWidth).toEqual(window.screen.width)
|
76
|
-
expect(params.screenHeight).toEqual(window.screen.height)
|
77
|
-
expect(params.windowWidth).toEqual(window.innerWidth)
|
78
|
-
expect(params.windowHeight).toEqual(window.innerHeight)
|
79
|
-
expect(params.colorDepth).toEqual(window.screen.colorDepth)
|
80
|
-
})
|
81
|
-
})
|
82
|
-
|
83
|
-
describe('sendToTracker', function () {
|
84
|
-
it('sends when the DOM is complete', function () {
|
85
|
-
setupFakeGa('123456.789012')
|
86
|
-
|
87
|
-
spyOn(tracker, 'sendData')
|
88
|
-
tracker.sendToTracker('foo')
|
89
|
-
|
90
|
-
expect(tracker.sendData).toHaveBeenCalledWith(jasmine.any(Object))
|
91
|
-
})
|
92
|
-
|
93
|
-
it('sets the ga Client ID', function () {
|
94
|
-
setupFakeGa('123456.789012')
|
95
|
-
|
96
|
-
spyOn(tracker, 'sendData')
|
97
|
-
tracker.sendToTracker('foo')
|
98
|
-
|
99
|
-
expect(tracker.gaClientId).toEqual('123456.789012')
|
100
|
-
})
|
101
|
-
})
|
102
|
-
|
103
|
-
describe('tracking', function () {
|
104
|
-
beforeEach(function () {
|
105
|
-
spyOn(tracker, 'sendToTracker')
|
106
|
-
})
|
107
|
-
|
108
|
-
describe('when pageviews are tracked', function () {
|
109
|
-
it('sends them to the tracker', function () {
|
110
|
-
tracker.trackPageview()
|
111
|
-
expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(['pageview'])
|
112
|
-
})
|
113
|
-
})
|
114
|
-
|
115
|
-
describe('when events are tracked', function () {
|
116
|
-
it('sends them to the tracker', function () {
|
117
|
-
tracker.trackEvent('category', 'action', {label: 'label'})
|
118
|
-
expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(
|
119
|
-
['event', {eventCategory: 'category', eventAction: 'action', eventLabel: 'label'}]
|
120
|
-
)
|
121
|
-
})
|
122
|
-
|
123
|
-
it('tracks custom dimensions', function () {
|
124
|
-
tracker.trackEvent('category', 'action', {dimension29: 'Home'})
|
125
|
-
expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(
|
126
|
-
['event', {eventCategory: 'category', eventAction: 'action', dimension29: 'Home'}]
|
127
|
-
)
|
128
|
-
})
|
129
|
-
|
130
|
-
it('the label is optional', function () {
|
131
|
-
tracker.trackEvent('category', 'action')
|
132
|
-
expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(
|
133
|
-
['event', {eventCategory: 'category', eventAction: 'action'}]
|
134
|
-
)
|
135
|
-
})
|
136
|
-
|
137
|
-
it('sends the page if supplied', function () {
|
138
|
-
tracker.trackEvent('category', 'action', {page: '/path/to/page'})
|
139
|
-
expect(tracker.sendToTracker.calls.mostRecent().args).toEqual(
|
140
|
-
['event', {eventCategory: 'category', eventAction: 'action', page: '/path/to/page'}]
|
141
|
-
)
|
142
|
-
})
|
143
|
-
|
144
|
-
it('tracks multiple events', function () {
|
145
|
-
tracker.trackEvent('category', 'action', {label: 'foo'})
|
146
|
-
tracker.trackEvent('category', 'action', {label: 'bar'})
|
147
|
-
|
148
|
-
expect(tracker.sendToTracker).toHaveBeenCalledWith(
|
149
|
-
'event', {eventCategory: 'category', eventAction: 'action', eventLabel: 'foo'}
|
150
|
-
)
|
151
|
-
expect(tracker.sendToTracker).toHaveBeenCalledWith(
|
152
|
-
'event', {eventCategory: 'category', eventAction: 'action', eventLabel: 'bar'}
|
153
|
-
)
|
154
|
-
})
|
155
|
-
})
|
156
|
-
|
157
|
-
describe('when social events are tracked', function () {
|
158
|
-
it('sends them to Google Analytics', function () {
|
159
|
-
tracker.trackSocial('network', 'action', 'target')
|
160
|
-
expect(tracker.sendToTracker.calls.mostRecent().args).toEqual([
|
161
|
-
'social',
|
162
|
-
{
|
163
|
-
'socialNetwork': 'network',
|
164
|
-
'socialAction': 'action',
|
165
|
-
'socialTarget': 'target'
|
166
|
-
}
|
167
|
-
])
|
168
|
-
})
|
169
|
-
})
|
170
|
-
})
|
171
|
-
})
|
@@ -1,62 +0,0 @@
|
|
1
|
-
/* global describe it expect afterEach beforeEach spyOn */
|
2
|
-
|
3
|
-
var $ = window.jQuery
|
4
|
-
|
5
|
-
describe('GOVUK.analyticsPlugins.mailtoLinkTracker', function () {
|
6
|
-
'use strict'
|
7
|
-
var GOVUK = window.GOVUK
|
8
|
-
|
9
|
-
var $links
|
10
|
-
|
11
|
-
beforeEach(function () {
|
12
|
-
$links = $(
|
13
|
-
'<div class="mailto-links">' +
|
14
|
-
'<a href="mailto:name1@email.com"></a>' +
|
15
|
-
'<a href="mailto:name2@email.com">The link for a mailto</a>' +
|
16
|
-
'<a href="mailto:name3@email.com"><img src="/img" /></a>' +
|
17
|
-
'</div>'
|
18
|
-
)
|
19
|
-
|
20
|
-
$('html').on('click', function (evt) { evt.preventDefault() })
|
21
|
-
$('body').append($links)
|
22
|
-
GOVUK.analytics = {trackEvent: function () {}}
|
23
|
-
|
24
|
-
GOVUK.analyticsPlugins.mailtoLinkTracker()
|
25
|
-
})
|
26
|
-
|
27
|
-
afterEach(function () {
|
28
|
-
$('html').off()
|
29
|
-
$('body').off()
|
30
|
-
$links.remove()
|
31
|
-
delete GOVUK.analytics
|
32
|
-
})
|
33
|
-
|
34
|
-
it('listens to click events on mailto links', function () {
|
35
|
-
spyOn(GOVUK.analytics, 'trackEvent')
|
36
|
-
|
37
|
-
$('.mailto-links a').each(function () {
|
38
|
-
$(this).trigger('click')
|
39
|
-
expect(GOVUK.analytics.trackEvent).toHaveBeenCalled()
|
40
|
-
GOVUK.analytics.trackEvent.calls.reset()
|
41
|
-
})
|
42
|
-
})
|
43
|
-
|
44
|
-
it('tracks mailto addresses and link text', function () {
|
45
|
-
spyOn(GOVUK.analytics, 'trackEvent')
|
46
|
-
$('.mailto-links a').trigger('click')
|
47
|
-
|
48
|
-
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
49
|
-
'Mailto Link Clicked', 'mailto:name1@email.com', {transport: 'beacon'})
|
50
|
-
|
51
|
-
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
52
|
-
'Mailto Link Clicked', 'mailto:name2@email.com', {transport: 'beacon', label: 'The link for a mailto'})
|
53
|
-
})
|
54
|
-
|
55
|
-
it('listens to click events on elements within mailto links', function () {
|
56
|
-
spyOn(GOVUK.analytics, 'trackEvent')
|
57
|
-
|
58
|
-
$('.mailto-links a img').trigger('click')
|
59
|
-
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
60
|
-
'Mailto Link Clicked', 'mailto:name3@email.com', {transport: 'beacon'})
|
61
|
-
})
|
62
|
-
})
|