govuk_publishing_components 21.68.1 → 23.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/images/govuk_publishing_components/action-link-arrow--simple-light.png +0 -0
- data/app/assets/images/govuk_publishing_components/action-link-arrow--simple-light.svg +4 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics.js +16 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/analytics.js +85 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js +30 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/custom-dimensions.js +120 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js +41 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/ecommerce.js +101 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js +51 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js +56 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/google-analytics-universal-tracker.js +198 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/init.js +48 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/mailto-link-tracker.js +38 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +129 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/pii.js +74 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/print-intent.js +39 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/scroll-tracker.js +513 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics/static-analytics.js +132 -0
- data/app/assets/javascripts/govuk_publishing_components/lib/track-click.js +61 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +20 -10
- data/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss +5 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_print-link.scss +23 -20
- data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +7 -1
- data/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +1 -1
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_govspeak.scss +4 -0
- data/app/views/govuk_publishing_components/components/_action_link.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_contents_list.html.erb +8 -13
- data/app/views/govuk_publishing_components/components/_govspeak.html.erb +8 -12
- data/app/views/govuk_publishing_components/components/_input.html.erb +17 -4
- data/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +0 -1
- data/app/views/govuk_publishing_components/components/_layout_header.html.erb +6 -5
- data/app/views/govuk_publishing_components/components/_panel.html.erb +5 -2
- data/app/views/govuk_publishing_components/components/_print_link.html.erb +26 -11
- data/app/views/govuk_publishing_components/components/docs/action_link.yml +8 -0
- data/app/views/govuk_publishing_components/components/docs/contents_list.yml +0 -37
- data/app/views/govuk_publishing_components/components/docs/govspeak.yml +1 -6
- data/app/views/govuk_publishing_components/components/docs/input.yml +7 -3
- data/app/views/govuk_publishing_components/components/docs/layout_header.yml +0 -3
- data/app/views/govuk_publishing_components/components/docs/panel.yml +4 -0
- data/app/views/govuk_publishing_components/components/docs/print_link.yml +5 -0
- data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +3 -1
- data/config/initializers/assets.rb +1 -0
- data/config/locales/et.yml +4 -0
- data/config/locales/fr.yml +4 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b95df6fab59121d237e5dddeeda753bbd1282ddabdab8f3fcba6a81088f0a33
|
4
|
+
data.tar.gz: 3592d8cea5ca48b42089e2722f34f80a0a8896c39aefe7ecb57867f8859bf5dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42cdaee623f79b09dd0da4d8ca0cf1c503ffd53b2d74d8affbe68d6d86a300f81025b42d6769eec75c1f71433b8270b75d248eaddd39e7650bf17a4850a04ff3
|
7
|
+
data.tar.gz: 576e1c494014b4c6b8ac3bec21277b51662aa9e3024c8113ae4e6388abe02a9bb2f40e744abe7513e719d2e5810f3e03dca3be7bb9ef3c618631432aed966fee
|
Binary file
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<svg width="23" height="23" viewBox="0 0 23 23" fill="none" xmlns="http://www.w3.org/2000/svg">
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.9429 11.7949L10.4402 7.29222L11.7327 5.99967L17.528 11.7949L11.7327 17.5902L10.4402 16.2976L14.9429 11.7949Z" fill="#ffffff"/>
|
3
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.95631 10.881L15.4414 10.881L15.4414 12.709L3.95631 12.709L3.95631 10.881Z" fill="#ffffff"/>
|
4
|
+
</svg>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
//= require govuk_publishing_components/lib/cookie-functions
|
2
|
+
//= require ./analytics/pii
|
3
|
+
//= require ./analytics/google-analytics-universal-tracker
|
4
|
+
//= require ./analytics/analytics
|
5
|
+
//= require ./analytics/print-intent
|
6
|
+
//= require ./analytics/error-tracking
|
7
|
+
//= require ./analytics/mailto-link-tracker
|
8
|
+
//= require ./analytics/external-link-tracker
|
9
|
+
//= require ./analytics/download-link-tracker
|
10
|
+
//= require ./analytics/auto-track-event
|
11
|
+
//= require ./analytics/page-content
|
12
|
+
//= require ./analytics/custom-dimensions
|
13
|
+
//= require ./analytics/static-analytics
|
14
|
+
//= require ./analytics/ecommerce
|
15
|
+
//= require ./analytics/init
|
16
|
+
//= require ./analytics/scroll-tracker
|
@@ -0,0 +1,85 @@
|
|
1
|
+
;(function (global) {
|
2
|
+
'use strict'
|
3
|
+
|
4
|
+
var GOVUK = global.GOVUK || {}
|
5
|
+
// For usage and initialisation see:
|
6
|
+
// https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#create-an-analytics-tracker
|
7
|
+
|
8
|
+
var Analytics = function (config) {
|
9
|
+
this.pii = new GOVUK.Pii()
|
10
|
+
this.trackers = []
|
11
|
+
if (typeof config.universalId !== 'undefined') {
|
12
|
+
var universalId = config.universalId
|
13
|
+
delete config.universalId
|
14
|
+
this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config))
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
var PIISafe = function (value) {
|
19
|
+
this.value = value
|
20
|
+
}
|
21
|
+
Analytics.PIISafe = PIISafe
|
22
|
+
|
23
|
+
Analytics.prototype.sendToTrackers = function (method, args) {
|
24
|
+
for (var i = 0, l = this.trackers.length; i < l; i++) {
|
25
|
+
var tracker = this.trackers[i]
|
26
|
+
var fn = tracker[method]
|
27
|
+
|
28
|
+
if (typeof fn === 'function') {
|
29
|
+
fn.apply(tracker, args)
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
Analytics.load = function () {
|
35
|
+
GOVUK.GoogleAnalyticsUniversalTracker.load()
|
36
|
+
}
|
37
|
+
|
38
|
+
Analytics.prototype.defaultPathForTrackPageview = function (location) {
|
39
|
+
// Get the page path including querystring, but ignoring the anchor
|
40
|
+
// as per default behaviour of GA (see: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages#overview)
|
41
|
+
// we ignore the possibility of there being campaign variables in the
|
42
|
+
// anchor because we wouldn't know how to detect and parse them if they
|
43
|
+
// were present
|
44
|
+
return this.pii.stripPIIFromString(location.href.substring(location.origin.length).split('#')[0])
|
45
|
+
}
|
46
|
+
|
47
|
+
Analytics.prototype.trackPageview = function (path, title, options) {
|
48
|
+
arguments[0] = arguments[0] || this.defaultPathForTrackPageview(window.location)
|
49
|
+
if (arguments.length === 0) { arguments.length = 1 }
|
50
|
+
this.sendToTrackers('trackPageview', this.pii.stripPII(arguments))
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
https://developers.google.com/analytics/devguides/collection/analyticsjs/events
|
55
|
+
options.label – Useful for categorizing events (eg nav buttons)
|
56
|
+
options.value – Values must be non-negative. Useful to pass counts
|
57
|
+
options.nonInteraction – Prevent event from impacting bounce rate
|
58
|
+
*/
|
59
|
+
Analytics.prototype.trackEvent = function (category, action, options) {
|
60
|
+
this.sendToTrackers('trackEvent', this.pii.stripPII(arguments))
|
61
|
+
}
|
62
|
+
|
63
|
+
Analytics.prototype.trackShare = function (network, options) {
|
64
|
+
this.sendToTrackers('trackSocial', this.pii.stripPII([network, 'share', global.location.pathname, options]))
|
65
|
+
}
|
66
|
+
|
67
|
+
/*
|
68
|
+
The custom dimension index must be configured within the
|
69
|
+
Universal Analytics profile
|
70
|
+
*/
|
71
|
+
Analytics.prototype.setDimension = function (index, value) {
|
72
|
+
this.sendToTrackers('setDimension', this.pii.stripPII(arguments))
|
73
|
+
}
|
74
|
+
|
75
|
+
/*
|
76
|
+
Add a beacon to track a page in another GA account on another domain.
|
77
|
+
*/
|
78
|
+
Analytics.prototype.addLinkedTrackerDomain = function (trackerId, name, domain) {
|
79
|
+
this.sendToTrackers('addLinkedTrackerDomain', arguments)
|
80
|
+
}
|
81
|
+
|
82
|
+
GOVUK.Analytics = Analytics
|
83
|
+
|
84
|
+
global.GOVUK = GOVUK
|
85
|
+
})(window)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
;(function (global) {
|
2
|
+
'use strict'
|
3
|
+
|
4
|
+
var GOVUK = global.GOVUK || {}
|
5
|
+
GOVUK.Modules = GOVUK.Modules || {}
|
6
|
+
|
7
|
+
GOVUK.Modules.AutoTrackEvent = function () {
|
8
|
+
this.start = function (element) {
|
9
|
+
var options = { nonInteraction: 1 } // automatic events shouldn't affect bounce rate
|
10
|
+
var category = element.data('track-category')
|
11
|
+
var action = element.data('track-action')
|
12
|
+
var label = element.data('track-label')
|
13
|
+
var value = element.data('track-value')
|
14
|
+
|
15
|
+
if (typeof label === 'string') {
|
16
|
+
options.label = label
|
17
|
+
}
|
18
|
+
|
19
|
+
if (value || value === 0) {
|
20
|
+
options.value = value
|
21
|
+
}
|
22
|
+
|
23
|
+
if (GOVUK.analytics && GOVUK.analytics.trackEvent) {
|
24
|
+
GOVUK.analytics.trackEvent(category, action, options)
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
global.GOVUK = GOVUK
|
30
|
+
})(window)
|
@@ -0,0 +1,120 @@
|
|
1
|
+
/* global GOVUK, $ */
|
2
|
+
|
3
|
+
(function () {
|
4
|
+
'use strict'
|
5
|
+
window.GOVUK = window.GOVUK || {}
|
6
|
+
var CustomDimensions = function () { }
|
7
|
+
|
8
|
+
CustomDimensions.getAndExtendDefaultTrackingOptions = function (extraOptions) {
|
9
|
+
var trackingOptions = this.customDimensions()
|
10
|
+
return $.extend(trackingOptions, extraOptions)
|
11
|
+
}
|
12
|
+
|
13
|
+
CustomDimensions.customDimensions = function () {
|
14
|
+
var dimensions = $.extend(
|
15
|
+
{},
|
16
|
+
customDimensionsFromBrowser(),
|
17
|
+
customDimensionsFromMetaTags(),
|
18
|
+
customDimensionsFromDom(),
|
19
|
+
abTestCustomDimensions()
|
20
|
+
)
|
21
|
+
|
22
|
+
return $.each(dimensions, function (key, value) {
|
23
|
+
dimensions[key] = new GOVUK.Analytics.PIISafe(String(value))
|
24
|
+
})
|
25
|
+
}
|
26
|
+
|
27
|
+
function customDimensionsFromBrowser () {
|
28
|
+
var customDimensions = {
|
29
|
+
dimension15: window.httpStatusCode || 200,
|
30
|
+
dimension16: GOVUK.cookie('TLSversion') || 'unknown',
|
31
|
+
dimension95: GOVUK.analytics.gaClientId
|
32
|
+
}
|
33
|
+
|
34
|
+
if (window.devicePixelRatio) {
|
35
|
+
customDimensions.dimension11 = window.devicePixelRatio
|
36
|
+
}
|
37
|
+
|
38
|
+
return customDimensions
|
39
|
+
}
|
40
|
+
|
41
|
+
function customDimensionsFromMetaTags () {
|
42
|
+
var dimensionMappings = {
|
43
|
+
section: { dimension: 1 },
|
44
|
+
format: { dimension: 2 },
|
45
|
+
themes: { dimension: 3, defaultValue: 'other' },
|
46
|
+
'content-id': { dimension: 4, defaultValue: '00000000-0000-0000-0000-000000000000' },
|
47
|
+
'search-result-count': { dimension: 5 },
|
48
|
+
'publishing-government': { dimension: 6 },
|
49
|
+
'political-status': { dimension: 7 },
|
50
|
+
'analytics:organisations': { dimension: 9 },
|
51
|
+
'analytics:world-locations': { dimension: 10 },
|
52
|
+
withdrawn: { dimension: 12, defaultValue: 'not withdrawn' },
|
53
|
+
'schema-name': { dimension: 17 },
|
54
|
+
'rendering-application': { dimension: 20 },
|
55
|
+
'search-autocomplete-status': { dimension: 21 },
|
56
|
+
'navigation-legacy': { dimension: 30, defaultValue: 'none' },
|
57
|
+
'navigation-page-type': { dimension: 32, defaultValue: 'none' },
|
58
|
+
'taxon-slug': { dimension: 56, defaultValue: 'other' },
|
59
|
+
'taxon-id': { dimension: 57, defaultValue: 'other' },
|
60
|
+
'taxon-slugs': { dimension: 58, defaultValue: 'other' },
|
61
|
+
'taxon-ids': { dimension: 59, defaultValue: 'other' },
|
62
|
+
'content-has-history': { dimension: 39, defaultValue: 'false' },
|
63
|
+
'publishing-application': { dimension: 89 },
|
64
|
+
stepnavs: { dimension: 96 },
|
65
|
+
'relevant-result-shown': { dimension: 83 },
|
66
|
+
'spelling-suggestion': { dimension: 81 }
|
67
|
+
}
|
68
|
+
|
69
|
+
var $metas = $('meta[name^="govuk:"]')
|
70
|
+
var customDimensions = {}
|
71
|
+
var tags = {}
|
72
|
+
|
73
|
+
$metas.each(function () {
|
74
|
+
var $meta = $(this)
|
75
|
+
var key = $meta.attr('name').split('govuk:')[1]
|
76
|
+
|
77
|
+
var dimension = dimensionMappings[key]
|
78
|
+
if (dimension) {
|
79
|
+
tags[key] = $meta.attr('content')
|
80
|
+
}
|
81
|
+
})
|
82
|
+
|
83
|
+
$.each(dimensionMappings, function (key, dimension) {
|
84
|
+
var value = tags[key] || dimension.defaultValue
|
85
|
+
if (typeof value !== 'undefined') {
|
86
|
+
customDimensions['dimension' + dimension.dimension] = value
|
87
|
+
}
|
88
|
+
})
|
89
|
+
|
90
|
+
return customDimensions
|
91
|
+
}
|
92
|
+
|
93
|
+
function customDimensionsFromDom () {
|
94
|
+
return {
|
95
|
+
dimension26: GOVUK.PageContent.getNumberOfSections(),
|
96
|
+
dimension27: GOVUK.PageContent.getNumberOfLinks(),
|
97
|
+
dimension23: $('main[id="content"]').attr('lang') || 'unknown',
|
98
|
+
dimension38: $('[data-module="global-bar"]').is(':visible') && 'Global Banner viewed'
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
function abTestCustomDimensions () {
|
103
|
+
var $abMetas = $('meta[name^="govuk:ab-test"]')
|
104
|
+
var customDimensions = {}
|
105
|
+
|
106
|
+
$abMetas.each(function () {
|
107
|
+
var $meta = $(this)
|
108
|
+
var dimension = parseInt($meta.data('analytics-dimension'))
|
109
|
+
var testNameAndBucket = $meta.attr('content')
|
110
|
+
|
111
|
+
if (dimension) {
|
112
|
+
customDimensions['dimension' + dimension] = testNameAndBucket
|
113
|
+
}
|
114
|
+
})
|
115
|
+
|
116
|
+
return customDimensions
|
117
|
+
}
|
118
|
+
|
119
|
+
GOVUK.CustomDimensions = CustomDimensions
|
120
|
+
})()
|
@@ -0,0 +1,41 @@
|
|
1
|
+
;(function (global) {
|
2
|
+
'use strict'
|
3
|
+
|
4
|
+
var $ = global.jQuery
|
5
|
+
var GOVUK = global.GOVUK || {}
|
6
|
+
|
7
|
+
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
|
8
|
+
GOVUK.analyticsPlugins.downloadLinkTracker = function (options) {
|
9
|
+
options = options || {}
|
10
|
+
var downloadLinkSelector = options.selector
|
11
|
+
|
12
|
+
if (downloadLinkSelector) {
|
13
|
+
$('body').on('click', downloadLinkSelector, trackDownload)
|
14
|
+
}
|
15
|
+
|
16
|
+
function trackDownload (evt) {
|
17
|
+
var $link = getLinkFromEvent(evt)
|
18
|
+
var href = $link.attr('href')
|
19
|
+
var evtOptions = { transport: 'beacon' }
|
20
|
+
var linkText = $.trim($link.text())
|
21
|
+
|
22
|
+
if (linkText) {
|
23
|
+
evtOptions.label = linkText
|
24
|
+
}
|
25
|
+
|
26
|
+
GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions)
|
27
|
+
}
|
28
|
+
|
29
|
+
function getLinkFromEvent (evt) {
|
30
|
+
var $target = $(evt.target)
|
31
|
+
|
32
|
+
if (!$target.is('a')) {
|
33
|
+
$target = $target.parents('a')
|
34
|
+
}
|
35
|
+
|
36
|
+
return $target
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
global.GOVUK = GOVUK
|
41
|
+
})(window)
|
@@ -0,0 +1,101 @@
|
|
1
|
+
// https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce
|
2
|
+
/* global GOVUK, $, ga */
|
3
|
+
|
4
|
+
(function () {
|
5
|
+
'use strict'
|
6
|
+
window.GOVUK = window.GOVUK || {}
|
7
|
+
|
8
|
+
var DEFAULT_LIST_TITLE = 'Site search results'
|
9
|
+
var DEFAULT_TRACK_CLICK_LABEL = 'Results'
|
10
|
+
|
11
|
+
var Ecommerce = function (config) {
|
12
|
+
this.init = function (element) {
|
13
|
+
// Limiting to 100 characters to avoid noise from extra longs search queries
|
14
|
+
// and to stop the size of the payload going over 8k limit.
|
15
|
+
var searchQuery = GOVUK.analytics.stripPII(element.attr('data-search-query')).substring(0, 100).toLowerCase()
|
16
|
+
var ecommerceRows = element.find('[data-ecommerce-row]')
|
17
|
+
var startPosition = parseInt(element.data('ecommerce-start-index'), 10)
|
18
|
+
var listTitle = element.data('list-title') || DEFAULT_LIST_TITLE
|
19
|
+
var variant = element.data('ecommerce-variant')
|
20
|
+
var trackClickLabel = element.data('track-click-label') || DEFAULT_TRACK_CLICK_LABEL
|
21
|
+
|
22
|
+
ecommerceRows.each(function (index, ecommerceRow) {
|
23
|
+
var $ecommerceRow = $(ecommerceRow)
|
24
|
+
var listSubheading = $ecommerceRow.data('ecommerce-subheading') || undefined
|
25
|
+
var contentId = $ecommerceRow.attr('data-ecommerce-content-id')
|
26
|
+
var path = $ecommerceRow.attr('data-ecommerce-path')
|
27
|
+
|
28
|
+
var indexOverride = $ecommerceRow.attr('data-ecommerce-index')
|
29
|
+
index = indexOverride ? parseInt(indexOverride, 10) - 1 : index
|
30
|
+
|
31
|
+
addImpression(contentId, path, index + startPosition, searchQuery, listTitle, listSubheading, variant)
|
32
|
+
trackProductOnClick($ecommerceRow, contentId, path, index + startPosition, searchQuery, listTitle, listSubheading, variant, trackClickLabel)
|
33
|
+
})
|
34
|
+
}
|
35
|
+
|
36
|
+
function constructData (contentId, path, position, listTitle, listSubheading, searchQuery, variant) {
|
37
|
+
var data = {
|
38
|
+
position: position,
|
39
|
+
list: listTitle,
|
40
|
+
dimension71: searchQuery
|
41
|
+
}
|
42
|
+
|
43
|
+
if (listSubheading !== undefined) {
|
44
|
+
data.dimension94 = listSubheading
|
45
|
+
}
|
46
|
+
|
47
|
+
if (contentId !== undefined) {
|
48
|
+
data.id = contentId
|
49
|
+
}
|
50
|
+
|
51
|
+
if (path !== undefined) {
|
52
|
+
data.name = path
|
53
|
+
}
|
54
|
+
|
55
|
+
if (variant !== undefined) {
|
56
|
+
data.variant = variant
|
57
|
+
}
|
58
|
+
|
59
|
+
return data
|
60
|
+
}
|
61
|
+
|
62
|
+
function addImpression (contentId, path, position, searchQuery, listTitle, listSubheading, variant) {
|
63
|
+
if (contentId || path) {
|
64
|
+
var impressionData = constructData(contentId, path, position, listTitle, listSubheading, searchQuery, variant)
|
65
|
+
ga('ec:addImpression', impressionData)
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
function trackProductOnClick (row, contentId, path, position, searchQuery, listTitle, listSubheading, variant, trackClickLabel) {
|
70
|
+
row.click(function () {
|
71
|
+
if (contentId || path) {
|
72
|
+
var clickData = constructData(contentId, path, position, listTitle, listSubheading, searchQuery, variant)
|
73
|
+
ga('ec:addProduct', clickData)
|
74
|
+
}
|
75
|
+
|
76
|
+
ga('ec:setAction', 'click', { list: listTitle })
|
77
|
+
GOVUK.analytics.trackEvent('UX', 'click',
|
78
|
+
GOVUK.CustomDimensions.getAndExtendDefaultTrackingOptions({ label: trackClickLabel })
|
79
|
+
)
|
80
|
+
})
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
Ecommerce.ecLoaded = false
|
85
|
+
Ecommerce.start = function (element) {
|
86
|
+
if (!window.ga) { return }
|
87
|
+
element = element || $('[data-analytics-ecommerce]')
|
88
|
+
if (element.length > 0) {
|
89
|
+
if (!Ecommerce.ecLoaded) {
|
90
|
+
ga('require', 'ec')
|
91
|
+
Ecommerce.ecLoaded = true
|
92
|
+
}
|
93
|
+
element.each(function (index) {
|
94
|
+
var ecommerce = new Ecommerce()
|
95
|
+
ecommerce.init($(this))
|
96
|
+
})
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
GOVUK.Ecommerce = Ecommerce
|
101
|
+
})()
|
@@ -0,0 +1,51 @@
|
|
1
|
+
// Extension to track errors using google analytics as a data store.
|
2
|
+
;(function (global) {
|
3
|
+
'use strict'
|
4
|
+
|
5
|
+
var GOVUK = global.GOVUK || {}
|
6
|
+
|
7
|
+
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
|
8
|
+
|
9
|
+
GOVUK.analyticsPlugins.error = function (options) {
|
10
|
+
options = options || {}
|
11
|
+
var filenameMustMatch = options.filenameMustMatch
|
12
|
+
|
13
|
+
var trackJavaScriptError = function (e) {
|
14
|
+
var errorFilename = e.filename
|
15
|
+
var errorSource = errorFilename + ': ' + e.lineno
|
16
|
+
|
17
|
+
if (shouldTrackThisError(errorFilename)) {
|
18
|
+
GOVUK.analytics.trackEvent('JavaScript Error', e.message, {
|
19
|
+
label: errorSource,
|
20
|
+
value: 1,
|
21
|
+
nonInteraction: true
|
22
|
+
})
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
function shouldTrackThisError (errorFilename) {
|
27
|
+
// Errors in page should always be tracked
|
28
|
+
// If there's no filename filter, everything is tracked
|
29
|
+
if (!errorFilename || !filenameMustMatch) {
|
30
|
+
return true
|
31
|
+
}
|
32
|
+
|
33
|
+
// If there's a filter and the error matches it, track it
|
34
|
+
if (filenameMustMatch.test(errorFilename)) {
|
35
|
+
return true
|
36
|
+
}
|
37
|
+
|
38
|
+
return false
|
39
|
+
}
|
40
|
+
|
41
|
+
if (global.addEventListener) {
|
42
|
+
global.addEventListener('error', trackJavaScriptError, false)
|
43
|
+
} else if (global.attachEvent) {
|
44
|
+
global.attachEvent('onerror', trackJavaScriptError)
|
45
|
+
} else {
|
46
|
+
global.onerror = trackJavaScriptError
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
global.GOVUK = GOVUK
|
51
|
+
})(window)
|