govuk_publishing_components 40.1.0 → 41.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +1 -79
- data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +1 -34
- data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +0 -17
- data/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js +0 -6
- data/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js +0 -7
- data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +8 -74
- data/app/assets/javascripts/govuk_publishing_components/dependencies.js +0 -4
- data/app/assets/javascripts/govuk_publishing_components/domain-config.js +0 -8
- data/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js +0 -4
- data/app/assets/javascripts/govuk_publishing_components/lib/cookie-settings.js +0 -14
- data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +0 -20
- data/app/assets/javascripts/govuk_publishing_components/lib/toggle.js +0 -33
- data/app/assets/javascripts/govuk_publishing_components/load-analytics.js +0 -25
- data/app/views/govuk_publishing_components/components/_accordion.html.erb +1 -8
- data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_cards.html.erb +3 -11
- data/app/views/govuk_publishing_components/components/_contents_list.html.erb +2 -15
- data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +3 -19
- data/app/views/govuk_publishing_components/components/_details.html.erb +9 -11
- data/app/views/govuk_publishing_components/components/_image_card.html.erb +1 -5
- data/app/views/govuk_publishing_components/components/_intervention.html.erb +4 -4
- data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +7 -21
- data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +1 -26
- data/app/views/govuk_publishing_components/components/_metadata.html.erb +2 -5
- data/app/views/govuk_publishing_components/components/_organisation_logo.html.erb +2 -7
- data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +0 -10
- data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +1 -3
- data/app/views/govuk_publishing_components/components/_search.html.erb +0 -1
- data/app/views/govuk_publishing_components/components/_select.html.erb +1 -2
- data/app/views/govuk_publishing_components/components/_share_links.html.erb +1 -10
- data/app/views/govuk_publishing_components/components/_single_page_notification_button.html.erb +0 -1
- data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +1 -24
- data/app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb +1 -14
- data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +1 -4
- data/app/views/govuk_publishing_components/components/_translation_nav.html.erb +0 -1
- data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +1 -7
- data/app/views/govuk_publishing_components/components/docs/accordion.yml +1 -60
- data/app/views/govuk_publishing_components/components/docs/big_number.yml +2 -6
- data/app/views/govuk_publishing_components/components/docs/breadcrumbs.yml +0 -1
- data/app/views/govuk_publishing_components/components/docs/button.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/cards.yml +3 -13
- data/app/views/govuk_publishing_components/components/docs/checkboxes.yml +0 -33
- data/app/views/govuk_publishing_components/components/docs/cookie_banner.yml +2 -2
- data/app/views/govuk_publishing_components/components/docs/details.yml +0 -15
- data/app/views/govuk_publishing_components/components/docs/document_list.yml +11 -18
- data/app/views/govuk_publishing_components/components/docs/error_alert.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/govspeak.yml +0 -11
- data/app/views/govuk_publishing_components/components/docs/image_card.yml +0 -31
- data/app/views/govuk_publishing_components/components/docs/intervention.yml +0 -26
- data/app/views/govuk_publishing_components/components/docs/layout_for_public.yml +2 -2
- data/app/views/govuk_publishing_components/components/docs/meta_tags.yml +0 -2
- data/app/views/govuk_publishing_components/components/docs/option_select.yml +4 -16
- data/app/views/govuk_publishing_components/components/docs/organisation_logo.yml +0 -15
- data/app/views/govuk_publishing_components/components/docs/print_link.yml +2 -9
- data/app/views/govuk_publishing_components/components/docs/select.yml +0 -36
- data/app/views/govuk_publishing_components/components/docs/share_links.yml +2 -4
- data/app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml +2 -25
- data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_header.yml +0 -23
- data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_related.yml +0 -10
- data/app/views/govuk_publishing_components/components/docs/subscription_links.yml +3 -15
- data/app/views/govuk_publishing_components/components/docs/table.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/tabs.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/translation_nav.yml +3 -27
- data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +1 -5
- data/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb +0 -2
- data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +0 -10
- data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/layout_header/_search.html.erb +0 -5
- data/app/views/govuk_publishing_components/components/related_navigation/_section.html.erb +0 -7
- data/lib/govuk_publishing_components/presenters/breadcrumbs_helper.rb +1 -19
- data/lib/govuk_publishing_components/presenters/image_card_helper.rb +1 -15
- data/lib/govuk_publishing_components/presenters/public_layout_helper.rb +2 -24
- data/lib/govuk_publishing_components/presenters/select_helper.rb +0 -4
- data/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb +0 -5
- data/lib/govuk_publishing_components/presenters/translation_nav_helper.rb +0 -7
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +1 -23
- data/app/assets/javascripts/govuk_publishing_components/analytics/analytics.js +0 -92
- data/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js +0 -221
- data/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js +0 -30
- data/app/assets/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.js +0 -55
- data/app/assets/javascripts/govuk_publishing_components/analytics/custom-dimensions.js +0 -133
- data/app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js +0 -46
- data/app/assets/javascripts/govuk_publishing_components/analytics/ecommerce.js +0 -101
- data/app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js +0 -51
- data/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js +0 -88
- data/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js +0 -68
- data/app/assets/javascripts/govuk_publishing_components/analytics/google-analytics-universal-tracker.js +0 -220
- data/app/assets/javascripts/govuk_publishing_components/analytics/init.js +0 -60
- data/app/assets/javascripts/govuk_publishing_components/analytics/linked-domains.js +0 -135
- data/app/assets/javascripts/govuk_publishing_components/analytics/mailto-link-tracker.js +0 -43
- data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +0 -160
- data/app/assets/javascripts/govuk_publishing_components/analytics/pii.js +0 -115
- data/app/assets/javascripts/govuk_publishing_components/analytics/print-intent.js +0 -39
- data/app/assets/javascripts/govuk_publishing_components/analytics/static-analytics.js +0 -132
- data/app/assets/javascripts/govuk_publishing_components/analytics/track-click.js +0 -75
- data/app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js +0 -56
- data/app/assets/javascripts/govuk_publishing_components/analytics.js +0 -23
- data/app/assets/javascripts/govuk_publishing_components/components/details.js +0 -48
@@ -1,160 +0,0 @@
|
|
1
|
-
/* global GOVUK */
|
2
|
-
|
3
|
-
(function () {
|
4
|
-
'use strict'
|
5
|
-
window.GOVUK = window.GOVUK || {}
|
6
|
-
var PageContent = function () { }
|
7
|
-
|
8
|
-
PageContent.getNumberOfSections = function () {
|
9
|
-
switch (true) {
|
10
|
-
case isNavigationGridPage():
|
11
|
-
return 1 + document.querySelectorAll('.parent-topic-contents').length
|
12
|
-
case isNavigationAccordionPage():
|
13
|
-
return document.querySelectorAll('[data-track-count="accordionSection"]').length
|
14
|
-
case isDocumentCollectionPage():
|
15
|
-
return document.querySelectorAll('.document-collection .group-title').length
|
16
|
-
case isNewBrowsePageLevelTwo():
|
17
|
-
// if there are no accordion sections on the browse level 2 page
|
18
|
-
// then it is a default page with one or two lists
|
19
|
-
return document.querySelectorAll('[data-track-count="accordionSection"]').length || document.querySelectorAll('main .govuk-list').length
|
20
|
-
case isNewBrowsePage():
|
21
|
-
return document.querySelectorAll('[data-track-count="cardList"]').length
|
22
|
-
case isMainstreamBrowsePage():
|
23
|
-
return countVisible(document.querySelectorAll('#subsection ul')) || document.querySelectorAll('#section ul').length || document.querySelectorAll('#root ul').length
|
24
|
-
case isTopicPage():
|
25
|
-
return document.querySelectorAll('.topics-page nav.index-list').length
|
26
|
-
case isPolicyAreaPage():
|
27
|
-
return document.querySelectorAll('.topic section h1.label').length
|
28
|
-
case isFinderPage():
|
29
|
-
case isWhitehallFinderPage():
|
30
|
-
case isNavigationLeafPage():
|
31
|
-
// The default in finders should be one, so it's comparable with A-Z
|
32
|
-
// lists in other navigation pages. Request made by performance
|
33
|
-
// analysts.
|
34
|
-
return 1
|
35
|
-
default:
|
36
|
-
// It's a content page, not a "finding" page
|
37
|
-
var sidebarSections = document.querySelectorAll('[data-track-count="sidebarRelatedItemSection"]').length
|
38
|
-
var sidebarTaxons = document.querySelectorAll('[data-track-count="sidebarTaxonSection"]').length
|
39
|
-
|
40
|
-
return sidebarSections || sidebarTaxons
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
PageContent.getNumberOfLinks = function () {
|
45
|
-
switch (true) {
|
46
|
-
case isNavigationGridPage():
|
47
|
-
return document.querySelectorAll('a[data-track-category="navGridLinkClicked"]').length +
|
48
|
-
document.querySelectorAll('a[data-track-category="navGridLeafLinkClicked"]').length
|
49
|
-
case isNavigationAccordionPage():
|
50
|
-
return document.querySelectorAll('a[data-track-category="navAccordionLinkClicked"]').length
|
51
|
-
case isDocumentCollectionPage():
|
52
|
-
return document.querySelectorAll('.document-collection .group-document-list li a').length
|
53
|
-
case isNewBrowsePageLevelTwo():
|
54
|
-
return document.querySelectorAll('[data-track-count="contentLink"]').length
|
55
|
-
case isNewBrowsePage():
|
56
|
-
return document.querySelectorAll('[data-track-count="cardLink"]').length
|
57
|
-
case isMainstreamBrowsePage():
|
58
|
-
return countVisible(document.querySelectorAll('#subsection ul a')) || document.querySelectorAll('#section ul a').length || document.querySelectorAll('#root ul a').length
|
59
|
-
case isTopicPage():
|
60
|
-
return document.querySelectorAll('.topics-page .index-list ul a').length ||
|
61
|
-
document.querySelectorAll('.topics-page .topics ul a').length
|
62
|
-
case isPolicyAreaPage():
|
63
|
-
return document.querySelectorAll('section.document-block a').length +
|
64
|
-
document.querySelectorAll('section .collection-list h2 a').length
|
65
|
-
case isFinderPage():
|
66
|
-
return document.querySelectorAll('.finder-frontend-content li.document a').length
|
67
|
-
case isWhitehallFinderPage():
|
68
|
-
return document.querySelectorAll('.document-list .document-row h3 a').length
|
69
|
-
case isNavigationLeafPage():
|
70
|
-
return document.querySelectorAll('a[data-track-category="navLeafLinkClicked"]').length
|
71
|
-
default:
|
72
|
-
// It's a content page, not a "finding" page, count related links
|
73
|
-
return document.querySelectorAll('a[data-track-category="relatedLinkClicked"]').length
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
var metaApplicationSelector = 'meta[name="govuk:rendering-application"]'
|
78
|
-
var metaFormatSelector = 'meta[name="govuk:format"]'
|
79
|
-
var metaNavigationTypeSelector = 'meta[name="govuk:navigation-page-type"]'
|
80
|
-
|
81
|
-
function getMetaAttribute (selector) {
|
82
|
-
var element = document.querySelector(selector)
|
83
|
-
if (element) {
|
84
|
-
return element.getAttribute('content').toLowerCase()
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
function isNavigationGridPage () {
|
89
|
-
return getMetaAttribute(metaApplicationSelector) === 'collections' &&
|
90
|
-
getMetaAttribute(metaFormatSelector) === 'taxon' &&
|
91
|
-
getMetaAttribute(metaNavigationTypeSelector) === 'grid'
|
92
|
-
}
|
93
|
-
|
94
|
-
function isNavigationAccordionPage () {
|
95
|
-
return getMetaAttribute(metaApplicationSelector) === 'collections' &&
|
96
|
-
getMetaAttribute(metaFormatSelector) === 'taxon' &&
|
97
|
-
getMetaAttribute(metaNavigationTypeSelector) === 'accordion'
|
98
|
-
}
|
99
|
-
|
100
|
-
function isNavigationLeafPage () {
|
101
|
-
return getMetaAttribute(metaApplicationSelector) === 'collections' &&
|
102
|
-
getMetaAttribute(metaFormatSelector) === 'taxon' &&
|
103
|
-
getMetaAttribute(metaNavigationTypeSelector) === 'leaf'
|
104
|
-
}
|
105
|
-
|
106
|
-
function isNewBrowsePageLevelTwo () {
|
107
|
-
return getMetaAttribute(metaApplicationSelector) === 'collections' &&
|
108
|
-
getMetaAttribute(metaNavigationTypeSelector) === 'browse level 2'
|
109
|
-
}
|
110
|
-
|
111
|
-
function isNewBrowsePage () {
|
112
|
-
return getMetaAttribute(metaApplicationSelector) === 'collections' &&
|
113
|
-
(getMetaAttribute(metaNavigationTypeSelector) === 'browse level 0' ||
|
114
|
-
getMetaAttribute(metaNavigationTypeSelector) === 'browse level 1') &&
|
115
|
-
getMetaAttribute(metaFormatSelector) === 'mainstream_browse_page'
|
116
|
-
}
|
117
|
-
|
118
|
-
function isMainstreamBrowsePage () {
|
119
|
-
return getMetaAttribute(metaApplicationSelector) === 'collections' &&
|
120
|
-
getMetaAttribute(metaFormatSelector) === 'mainstream_browse_page'
|
121
|
-
}
|
122
|
-
|
123
|
-
function isTopicPage () {
|
124
|
-
return getMetaAttribute(metaApplicationSelector) === 'collections' &&
|
125
|
-
getMetaAttribute(metaFormatSelector) === 'topic'
|
126
|
-
}
|
127
|
-
|
128
|
-
function isPolicyAreaPage () {
|
129
|
-
return getMetaAttribute(metaApplicationSelector) === 'whitehall' &&
|
130
|
-
getMetaAttribute(metaFormatSelector) === 'placeholder_policy_area'
|
131
|
-
}
|
132
|
-
|
133
|
-
function isDocumentCollectionPage () {
|
134
|
-
return getMetaAttribute(metaApplicationSelector) === 'government-frontend' &&
|
135
|
-
getMetaAttribute(metaFormatSelector) === 'document_collection'
|
136
|
-
}
|
137
|
-
|
138
|
-
function isFinderPage () {
|
139
|
-
return getMetaAttribute(metaApplicationSelector) === 'finder-frontend' &&
|
140
|
-
getMetaAttribute(metaFormatSelector) === 'finder'
|
141
|
-
}
|
142
|
-
|
143
|
-
function isWhitehallFinderPage () {
|
144
|
-
return getMetaAttribute(metaApplicationSelector) === 'whitehall' &&
|
145
|
-
getMetaAttribute(metaFormatSelector) === 'finder'
|
146
|
-
}
|
147
|
-
|
148
|
-
function countVisible (elements) {
|
149
|
-
var count = 0
|
150
|
-
for (var i = 0; i < elements.length; i++) {
|
151
|
-
var style = window.getComputedStyle(elements[i])
|
152
|
-
if (!(style.display === 'none' || style.visibility === 'hidden')) {
|
153
|
-
count++
|
154
|
-
}
|
155
|
-
}
|
156
|
-
return count
|
157
|
-
}
|
158
|
-
|
159
|
-
GOVUK.PageContent = PageContent
|
160
|
-
})()
|
@@ -1,115 +0,0 @@
|
|
1
|
-
;(function (global) {
|
2
|
-
'use strict'
|
3
|
-
|
4
|
-
var GOVUK = global.GOVUK || {}
|
5
|
-
var EMAIL_PATTERN = /[^\s=/?&]+(?:@|%40)[^\s=/?&]+/g
|
6
|
-
var POSTCODE_PATTERN = /\b[A-PR-UWYZ][A-HJ-Z]?[0-9][0-9A-HJKMNPR-Y]?(?:[\s+]|%20)*[0-9](?!refund)[ABD-HJLNPQ-Z]{2,3}\b/gi
|
7
|
-
var DATE_PATTERN = /\d{4}(-?)\d{2}(-?)\d{2}/g
|
8
|
-
var ESCAPE_REGEX_PATTERN = /[|\\{}()[\]^$+*?.]/g
|
9
|
-
|
10
|
-
// specific URL parameters to be redacted from accounts URLs
|
11
|
-
var RESET_PASSWORD_TOKEN_PATTERN = /reset_password_token=[a-zA-Z0-9-]+/g
|
12
|
-
var UNLOCK_TOKEN_PATTERN = /unlock_token=[a-zA-Z0-9-]+/g
|
13
|
-
var STATE_PATTERN = /state=.[^&]+/g
|
14
|
-
|
15
|
-
function shouldStripDates () {
|
16
|
-
var metas = document.querySelectorAll('meta[name="govuk:static-analytics:strip-dates"]')
|
17
|
-
return metas.length > 0
|
18
|
-
}
|
19
|
-
|
20
|
-
function shouldStripPostcodes () {
|
21
|
-
var metas = document.querySelectorAll('meta[name="govuk:static-analytics:strip-postcodes"]')
|
22
|
-
return metas.length > 0
|
23
|
-
}
|
24
|
-
|
25
|
-
function queryStringParametersToStrip () {
|
26
|
-
var meta = document.querySelector('meta[name="govuk:static-analytics:strip-query-string-parameters"]')
|
27
|
-
var value = false
|
28
|
-
if (meta) {
|
29
|
-
value = meta.getAttribute('content')
|
30
|
-
}
|
31
|
-
var parameters = []
|
32
|
-
|
33
|
-
if (value) {
|
34
|
-
var split = value.split(',')
|
35
|
-
for (var i = 0; i < split.length; i++) {
|
36
|
-
parameters.push(split[i].trim())
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
return parameters
|
41
|
-
}
|
42
|
-
|
43
|
-
var pii = function () {
|
44
|
-
this.stripDatePII = shouldStripDates()
|
45
|
-
this.stripPostcodePII = shouldStripPostcodes()
|
46
|
-
this.queryStringParametersToStrip = queryStringParametersToStrip()
|
47
|
-
}
|
48
|
-
|
49
|
-
pii.prototype.stripPII = function (value) {
|
50
|
-
if (typeof value === 'string') {
|
51
|
-
return this.stripPIIFromString(value)
|
52
|
-
} else if (Object.prototype.toString.call(value) === '[object Array]' || Object.prototype.toString.call(value) === '[object Arguments]') {
|
53
|
-
return this.stripPIIFromArray(value)
|
54
|
-
} else if (typeof value === 'object') {
|
55
|
-
return this.stripPIIFromObject(value)
|
56
|
-
} else {
|
57
|
-
return value
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
pii.prototype.stripPIIFromString = function (string) {
|
62
|
-
var stripped = string.replace(EMAIL_PATTERN, '[email]')
|
63
|
-
stripped = stripped.replace(RESET_PASSWORD_TOKEN_PATTERN, 'reset_password_token=[reset_password_token]')
|
64
|
-
stripped = stripped.replace(UNLOCK_TOKEN_PATTERN, 'unlock_token=[unlock_token]')
|
65
|
-
stripped = stripped.replace(STATE_PATTERN, 'state=[state]')
|
66
|
-
stripped = this.stripQueryStringParameters(stripped)
|
67
|
-
|
68
|
-
if (this.stripDatePII === true) {
|
69
|
-
stripped = stripped.replace(DATE_PATTERN, '[date]')
|
70
|
-
}
|
71
|
-
if (this.stripPostcodePII === true) {
|
72
|
-
stripped = stripped.replace(POSTCODE_PATTERN, '[postcode]')
|
73
|
-
}
|
74
|
-
return stripped
|
75
|
-
}
|
76
|
-
|
77
|
-
pii.prototype.stripPIIFromObject = function (object) {
|
78
|
-
if (object) {
|
79
|
-
if (object instanceof GOVUK.Analytics.PIISafe) {
|
80
|
-
return object.value
|
81
|
-
} else {
|
82
|
-
for (var property in object) {
|
83
|
-
var value = object[property]
|
84
|
-
|
85
|
-
object[property] = this.stripPII(value)
|
86
|
-
}
|
87
|
-
return object
|
88
|
-
}
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
pii.prototype.stripPIIFromArray = function (array) {
|
93
|
-
for (var i = 0, l = array.length; i < l; i++) {
|
94
|
-
var elem = array[i]
|
95
|
-
|
96
|
-
array[i] = this.stripPII(elem)
|
97
|
-
}
|
98
|
-
return array
|
99
|
-
}
|
100
|
-
|
101
|
-
pii.prototype.stripQueryStringParameters = function (string) {
|
102
|
-
for (var i = 0; i < this.queryStringParametersToStrip.length; i++) {
|
103
|
-
var parameter = this.queryStringParametersToStrip[i]
|
104
|
-
var escaped = parameter.replace(ESCAPE_REGEX_PATTERN, '\\$&')
|
105
|
-
var regexp = new RegExp('((?:\\?|&)' + escaped + '=)(?:[^&#\\s]*)', 'g')
|
106
|
-
string = string.replace(regexp, '$1[' + parameter + ']')
|
107
|
-
}
|
108
|
-
|
109
|
-
return string
|
110
|
-
}
|
111
|
-
|
112
|
-
GOVUK.Pii = pii
|
113
|
-
|
114
|
-
global.GOVUK = GOVUK
|
115
|
-
})(window)
|
@@ -1,39 +0,0 @@
|
|
1
|
-
// Extension to monitor attempts to print pages.
|
2
|
-
;(function (global) {
|
3
|
-
'use strict'
|
4
|
-
|
5
|
-
var GOVUK = global.GOVUK || {}
|
6
|
-
|
7
|
-
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
|
8
|
-
|
9
|
-
GOVUK.analyticsPlugins.printIntent = function () {
|
10
|
-
var printAttempt = function () {
|
11
|
-
GOVUK.analytics.trackEvent('Print Intent', document.location.pathname)
|
12
|
-
GOVUK.analytics.trackPageview('/print' + document.location.pathname)
|
13
|
-
}
|
14
|
-
|
15
|
-
// Most browsers
|
16
|
-
if (global.matchMedia) {
|
17
|
-
var mediaQueryList = global.matchMedia('print')
|
18
|
-
var mqlListenerCount = 0
|
19
|
-
mediaQueryList.addListener(function (mql) {
|
20
|
-
if (!mql.matches && mqlListenerCount === 0) {
|
21
|
-
printAttempt()
|
22
|
-
mqlListenerCount++
|
23
|
-
// If we try and print again within 3 seconds, don't log it
|
24
|
-
setTimeout(function () {
|
25
|
-
mqlListenerCount = 0
|
26
|
-
// printing will be tracked again now
|
27
|
-
}, 3000)
|
28
|
-
}
|
29
|
-
})
|
30
|
-
}
|
31
|
-
|
32
|
-
// IE < 10
|
33
|
-
if (global.onafterprint) {
|
34
|
-
global.onafterprint = printAttempt
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
global.GOVUK = GOVUK
|
39
|
-
})(window)
|
@@ -1,132 +0,0 @@
|
|
1
|
-
/* global GOVUK, ga */
|
2
|
-
|
3
|
-
(function () {
|
4
|
-
'use strict'
|
5
|
-
window.GOVUK = window.GOVUK || {}
|
6
|
-
var StaticAnalytics = function (config) {
|
7
|
-
// Create universal tracker
|
8
|
-
// https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md
|
9
|
-
// https://github.com/alphagov/govuk_frontend_toolkit/blob/master/javascripts/govuk/analytics/analytics.js
|
10
|
-
var consentCookie = window.GOVUK.getConsentCookie()
|
11
|
-
|
12
|
-
if (!consentCookie || consentCookie.usage) {
|
13
|
-
this.analytics = new GOVUK.Analytics(config)
|
14
|
-
}
|
15
|
-
|
16
|
-
var trackingOptions = getOptionsFromCookie()
|
17
|
-
|
18
|
-
// We're setting the client ID inside a callback function because
|
19
|
-
// we don't have access to the client ID until GA returns a tracker object.
|
20
|
-
ga(function (tracker) {
|
21
|
-
this.gaClientId = tracker.get('clientId')
|
22
|
-
|
23
|
-
GOVUK.triggerEvent(window, 'gaClientSet')
|
24
|
-
|
25
|
-
// Start up ecommerce tracking
|
26
|
-
GOVUK.Ecommerce.start()
|
27
|
-
|
28
|
-
// Track initial pageview
|
29
|
-
this.trackPageview(null, null, trackingOptions)
|
30
|
-
|
31
|
-
// Begin error and print tracking
|
32
|
-
GOVUK.analyticsPlugins.error({ filenameMustMatch: /gov\.uk/ })
|
33
|
-
GOVUK.analyticsPlugins.printIntent()
|
34
|
-
GOVUK.analyticsPlugins.mailtoLinkTracker()
|
35
|
-
GOVUK.analyticsPlugins.externalLinkTracker({
|
36
|
-
externalLinkUploadCustomDimension: 36
|
37
|
-
})
|
38
|
-
GOVUK.analyticsPlugins.downloadLinkTracker({
|
39
|
-
selector: 'a[href*="/government/uploads"], a[href*="assets.publishing.service.gov.uk"]'
|
40
|
-
})
|
41
|
-
}.bind(this))
|
42
|
-
}
|
43
|
-
|
44
|
-
StaticAnalytics.load = function () {
|
45
|
-
GOVUK.Analytics.load()
|
46
|
-
}
|
47
|
-
|
48
|
-
StaticAnalytics.prototype.trackPageview = function (path, title, options) {
|
49
|
-
// Add the cookie banner status as a custom dimension
|
50
|
-
var cookieBannerShown = !this.getCookie('seen_cookie_message')
|
51
|
-
var cookieBannerDimension = { dimension100: cookieBannerShown ? cookieBannerShown.toString() : 'false' }
|
52
|
-
options = GOVUK.extendObject(options, cookieBannerDimension)
|
53
|
-
|
54
|
-
var trackingOptions = GOVUK.CustomDimensions.getAndExtendDefaultTrackingOptions(options)
|
55
|
-
this.analytics.trackPageview(path, title, trackingOptions)
|
56
|
-
}
|
57
|
-
|
58
|
-
StaticAnalytics.prototype.trackEvent = function (category, action, options) {
|
59
|
-
var trackingOptions = GOVUK.CustomDimensions.getAndExtendDefaultTrackingOptions(options)
|
60
|
-
this.analytics.trackEvent(category, action, trackingOptions)
|
61
|
-
}
|
62
|
-
|
63
|
-
StaticAnalytics.prototype.setDimension = function (index, value, name, scope) {
|
64
|
-
if (typeof value === 'undefined') {
|
65
|
-
return
|
66
|
-
}
|
67
|
-
this.analytics.setDimension(index, value, name, scope)
|
68
|
-
}
|
69
|
-
|
70
|
-
StaticAnalytics.prototype.trackShare = function (network) {
|
71
|
-
var trackingOptions = GOVUK.CustomDimensions.getAndExtendDefaultTrackingOptions()
|
72
|
-
this.analytics.trackShare(network, trackingOptions)
|
73
|
-
}
|
74
|
-
|
75
|
-
StaticAnalytics.prototype.addLinkedTrackerDomain = function (trackerId, name, domain, sendPageView) {
|
76
|
-
this.analytics.addLinkedTrackerDomain(trackerId, name, domain, sendPageView)
|
77
|
-
}
|
78
|
-
|
79
|
-
StaticAnalytics.prototype.setOptionsForNextPageview = function (options) {
|
80
|
-
if (typeof options !== 'object') {
|
81
|
-
return
|
82
|
-
}
|
83
|
-
|
84
|
-
var cookieOptions = getOptionsFromCookie()
|
85
|
-
|
86
|
-
cookieOptions = GOVUK.extendObject(cookieOptions, options)
|
87
|
-
|
88
|
-
this.setCookie('analytics_next_page_call', cookieOptions)
|
89
|
-
}
|
90
|
-
|
91
|
-
StaticAnalytics.prototype.setCookie = function (cookieName, object) {
|
92
|
-
if (!GOVUK.cookie) {
|
93
|
-
return
|
94
|
-
}
|
95
|
-
|
96
|
-
if (!object) {
|
97
|
-
GOVUK.cookie(cookieName, null)
|
98
|
-
} else {
|
99
|
-
// Singly-stringified JSON sometimes gets escaped when put into a cookie, but inconsistently. The command-line
|
100
|
-
// tests will escape, but browser tests will not. Double-stringify in order to get consistently-escaped strings.
|
101
|
-
GOVUK.cookie(cookieName, JSON.stringify(JSON.stringify(object)))
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
StaticAnalytics.prototype.getCookie = function (cookieName) {
|
106
|
-
if (!GOVUK.cookie) {
|
107
|
-
return
|
108
|
-
}
|
109
|
-
|
110
|
-
try {
|
111
|
-
return JSON.parse(JSON.parse(GOVUK.cookie(cookieName)))
|
112
|
-
} catch (error) {
|
113
|
-
return null
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
StaticAnalytics.prototype.stripPII = function (value) {
|
118
|
-
return this.analytics.pii.stripPII(value)
|
119
|
-
}
|
120
|
-
|
121
|
-
function getOptionsFromCookie () {
|
122
|
-
try {
|
123
|
-
var cookie = StaticAnalytics.prototype.getCookie('analytics_next_page_call')
|
124
|
-
StaticAnalytics.prototype.setCookie('analytics_next_page_call', null)
|
125
|
-
return cookie || {}
|
126
|
-
} catch (e) {
|
127
|
-
return {}
|
128
|
-
}
|
129
|
-
}
|
130
|
-
|
131
|
-
GOVUK.StaticAnalytics = StaticAnalytics
|
132
|
-
})()
|
@@ -1,75 +0,0 @@
|
|
1
|
-
//= require ../vendor/polyfills/closest.js
|
2
|
-
|
3
|
-
window.GOVUK = window.GOVUK || {}
|
4
|
-
window.GOVUK.Modules = window.GOVUK.Modules || {};
|
5
|
-
|
6
|
-
(function (Modules) {
|
7
|
-
function GemTrackClick ($module) {
|
8
|
-
this.$module = $module
|
9
|
-
}
|
10
|
-
|
11
|
-
GemTrackClick.prototype.init = function () {
|
12
|
-
this.$module.handleClick = this.handleClick.bind(this)
|
13
|
-
var trackLinksOnly = this.$module.hasAttribute('data-track-links-only')
|
14
|
-
var limitToElementClass = this.$module.getAttribute('data-limit-to-element-class')
|
15
|
-
|
16
|
-
var that = this
|
17
|
-
// add a listener to the whole element
|
18
|
-
this.$module.addEventListener('click', function (e) {
|
19
|
-
var target = e.target
|
20
|
-
if (!trackLinksOnly) {
|
21
|
-
that.$module.handleClick(target)
|
22
|
-
} else if (trackLinksOnly && target.closest('a')) {
|
23
|
-
if (!limitToElementClass) {
|
24
|
-
that.$module.handleClick(target)
|
25
|
-
} else if (limitToElementClass && target.closest('.' + limitToElementClass)) {
|
26
|
-
that.$module.handleClick(target)
|
27
|
-
}
|
28
|
-
}
|
29
|
-
})
|
30
|
-
}
|
31
|
-
|
32
|
-
GemTrackClick.prototype.handleClick = function (target) {
|
33
|
-
var options = { transport: 'beacon' }
|
34
|
-
var linkUrl
|
35
|
-
|
36
|
-
// if clicked element hasn't got the right attributes, look for a parent that matches
|
37
|
-
if (!target.hasAttribute('data-track-category') && !target.hasAttribute('data-track-action')) {
|
38
|
-
linkUrl = target.getAttribute('href')
|
39
|
-
target = target.closest('[data-track-category][data-track-action]')
|
40
|
-
}
|
41
|
-
|
42
|
-
if (target) {
|
43
|
-
var category = target.getAttribute('data-track-category')
|
44
|
-
var action = target.getAttribute('data-track-action')
|
45
|
-
var label = target.getAttribute('data-track-label') || linkUrl
|
46
|
-
var value = target.getAttribute('data-track-value')
|
47
|
-
var dimension = target.getAttribute('data-track-dimension')
|
48
|
-
var dimensionIndex = target.getAttribute('data-track-dimension-index')
|
49
|
-
var extraOptions = target.getAttribute('data-track-options')
|
50
|
-
|
51
|
-
if (label) {
|
52
|
-
options.label = label
|
53
|
-
}
|
54
|
-
|
55
|
-
if (value) {
|
56
|
-
options.value = value
|
57
|
-
}
|
58
|
-
|
59
|
-
if (dimension && dimensionIndex) {
|
60
|
-
options['dimension' + dimensionIndex] = dimension
|
61
|
-
}
|
62
|
-
|
63
|
-
if (extraOptions) {
|
64
|
-
extraOptions = JSON.parse(extraOptions)
|
65
|
-
for (var k in extraOptions) options[k] = extraOptions[k]
|
66
|
-
}
|
67
|
-
|
68
|
-
if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
|
69
|
-
window.GOVUK.analytics.trackEvent(category, action, options)
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
Modules.GemTrackClick = GemTrackClick
|
75
|
-
})(window.GOVUK.Modules)
|
@@ -1,56 +0,0 @@
|
|
1
|
-
window.GOVUK = window.GOVUK || {}
|
2
|
-
window.GOVUK.Modules = window.GOVUK.Modules || {};
|
3
|
-
|
4
|
-
(function (Modules) {
|
5
|
-
function TrackSelectChange ($module) {
|
6
|
-
this.$module = $module
|
7
|
-
}
|
8
|
-
|
9
|
-
TrackSelectChange.prototype.init = function ($module) {
|
10
|
-
this.$module.trackChange = this.trackChange.bind(this)
|
11
|
-
this.$module.fireTrackingChange = this.fireTrackingChange.bind(this)
|
12
|
-
this.$module.addEventListener('change', this.trackChange)
|
13
|
-
}
|
14
|
-
|
15
|
-
TrackSelectChange.prototype.trackChange = function () {
|
16
|
-
var selectedOption = this.options[this.selectedIndex]
|
17
|
-
|
18
|
-
if (selectedOption.hasAttribute('data-track-category') && selectedOption.hasAttribute('data-track-action')) {
|
19
|
-
this.fireTrackingChange(selectedOption)
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
TrackSelectChange.prototype.fireTrackingChange = function (selectedOption) {
|
24
|
-
var options = { transport: 'beacon' }
|
25
|
-
var category = selectedOption.getAttribute('data-track-category')
|
26
|
-
var action = selectedOption.getAttribute('data-track-action')
|
27
|
-
var label = selectedOption.getAttribute('data-track-label')
|
28
|
-
var value = selectedOption.getAttribute('data-track-value')
|
29
|
-
var dimension = selectedOption.getAttribute('data-track-dimension')
|
30
|
-
var dimensionIndex = selectedOption.getAttribute('data-track-dimension-index')
|
31
|
-
var extraOptions = selectedOption.getAttribute('data-track-options')
|
32
|
-
|
33
|
-
if (label) {
|
34
|
-
options.label = label
|
35
|
-
}
|
36
|
-
|
37
|
-
if (value) {
|
38
|
-
options.value = value
|
39
|
-
}
|
40
|
-
|
41
|
-
if (dimension && dimensionIndex) {
|
42
|
-
options['dimension' + dimensionIndex] = dimension
|
43
|
-
}
|
44
|
-
|
45
|
-
if (extraOptions) {
|
46
|
-
extraOptions = JSON.parse(extraOptions)
|
47
|
-
for (var k in extraOptions) options[k] = extraOptions[k]
|
48
|
-
}
|
49
|
-
|
50
|
-
if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
|
51
|
-
window.GOVUK.analytics.trackEvent(category, action, options)
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
Modules.TrackSelectChange = TrackSelectChange
|
56
|
-
})(window.GOVUK.Modules)
|
@@ -1,23 +0,0 @@
|
|
1
|
-
// these scripts are specifically ordered
|
2
|
-
|
3
|
-
//= require govuk_publishing_components/lib/cookie-functions
|
4
|
-
//= require govuk_publishing_components/lib/extend-object
|
5
|
-
//= require ./analytics/pii
|
6
|
-
//= require ./analytics/google-analytics-universal-tracker
|
7
|
-
//= require ./analytics/analytics
|
8
|
-
//= require ./analytics/print-intent
|
9
|
-
//= require ./analytics/error-tracking
|
10
|
-
//= require ./analytics/mailto-link-tracker
|
11
|
-
//= require ./analytics/external-link-tracker
|
12
|
-
//= require ./analytics/download-link-tracker
|
13
|
-
//= require ./analytics/auto-track-event
|
14
|
-
//= require ./analytics/page-content
|
15
|
-
//= require ./analytics/custom-dimensions
|
16
|
-
//= require ./analytics/static-analytics
|
17
|
-
//= require ./analytics/ecommerce
|
18
|
-
//= require ./analytics/init
|
19
|
-
//= require ./analytics/auto-scroll-tracker
|
20
|
-
//= require ./analytics/explicit-cross-domain-links
|
21
|
-
//= require ./analytics/track-click
|
22
|
-
//= require ./analytics/track-select-change
|
23
|
-
//= require ./analytics/cross-domain-tracking
|
@@ -1,48 +0,0 @@
|
|
1
|
-
window.GOVUK = window.GOVUK || {}
|
2
|
-
window.GOVUK.Modules = window.GOVUK.Modules || {};
|
3
|
-
|
4
|
-
(function (Modules) {
|
5
|
-
function GemDetails ($module) {
|
6
|
-
this.$module = $module
|
7
|
-
this.$summary = this.$module.querySelector('.govuk-details__summary')
|
8
|
-
|
9
|
-
this.customTrackLabel = this.$summary.getAttribute('data-track-label')
|
10
|
-
this.detailsClick = this.$module.querySelector('[data-details-track-click]')
|
11
|
-
}
|
12
|
-
|
13
|
-
GemDetails.prototype.init = function () {
|
14
|
-
if (this.customTrackLabel) { // If a custom label has been provided, we can simply call the tracking module
|
15
|
-
var trackDetails = new window.GOVUK.Modules.GemTrackClick(this.$summary)
|
16
|
-
trackDetails.init()
|
17
|
-
} else if (this.detailsClick) { // If no custom label is set, we use the open/close status as the label
|
18
|
-
this.detailsClick.addEventListener('click', function (event) {
|
19
|
-
this.trackDefault(this.$summary)
|
20
|
-
}.bind(this))
|
21
|
-
}
|
22
|
-
}
|
23
|
-
|
24
|
-
GemDetails.prototype.trackDefault = function (element) {
|
25
|
-
if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
|
26
|
-
var componentStatus = (this.$module.getAttribute('open') == null) ? 'open' : 'closed'
|
27
|
-
var trackCategory = element.getAttribute('data-track-category')
|
28
|
-
var trackAction = element.getAttribute('data-track-action')
|
29
|
-
var trackOptions = element.getAttribute('data-track-options')
|
30
|
-
|
31
|
-
if (trackOptions) {
|
32
|
-
trackOptions = JSON.parse(trackOptions)
|
33
|
-
}
|
34
|
-
|
35
|
-
if (typeof trackOptions !== 'object' || trackOptions === null) {
|
36
|
-
trackOptions = {}
|
37
|
-
}
|
38
|
-
|
39
|
-
trackOptions.label = componentStatus
|
40
|
-
|
41
|
-
if (trackAction && trackCategory) {
|
42
|
-
window.GOVUK.analytics.trackEvent(trackCategory, trackAction, trackOptions)
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
Modules.GemDetails = GemDetails
|
48
|
-
})(window.GOVUK.Modules)
|