govuk_frontend_toolkit 4.6.1 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3779c00293b0da0da9ee29c55858b374ad0ef687
4
- data.tar.gz: 7056419a578825e7a121e77aa3e5d452e17c86f9
3
+ metadata.gz: eaa5f7117e30f5312a36798eb20156bfe780d2a9
4
+ data.tar.gz: 1325ad166e0234a847bde510e26f8f0eb69fc774
5
5
  SHA512:
6
- metadata.gz: 725c9056c9c9df4776ba0739ac759a3f8c2b718b95692e5feea94e81f7dbd54db9c6af05f0820ea29d0a8e30a984f5e33cb9fecd5be4890c911242244c901ab1
7
- data.tar.gz: c304286d59fdeacf68d1c8adb1c8903ea4ef816263cd35e24af9beaff21bd175007d2d3c74e393d9596b1d534c2ef46b949e70a9a3bc895b9be9e1efece88855
6
+ metadata.gz: d46e13e3da38fe2c8a70d0ff7bf14a0c3e8b8933a8652a1165a0deb0b3fe8d20a0279f8f93afc31d6beec86e0fc06a998aff298d8109e52b0e96f2cb2c3e95cd
7
+ data.tar.gz: 1aaa3cd5fafc3450c5ac8f6425822e8faf7798168458fb0b6019ea0f034841afe9309f023ac02671ec89de7a06342509add753ec36110587d62ac237b93d0bad
@@ -1,3 +1,7 @@
1
+ # 4.7.0
2
+
3
+ - Add 'mailto' tracking to GOV.UK Analytics (PR #244)
4
+
1
5
  # 4.6.1
2
6
 
3
7
  - Use the Sass variable $light-blue for link active and hover colours (PR #242)
@@ -144,6 +144,7 @@ In production:
144
144
  * [Error tracking](/docs/analytics.md#error-tracking-error-trackingjs)
145
145
  * [External link tracking](/docs/analytics.md#external-link-tracking-external-link-trackerjs)
146
146
  * [Download link tracking](/docs/analytics.md#download-link-tracking-download-link-trackerjs)
147
+ * [Mailto link tracking](/docs/analytics.md#mailto-link-tracking-mailto-link-trackerjs)
147
148
 
148
149
  ## Licence
149
150
 
@@ -1 +1 @@
1
- 4.6.1
1
+ 4.7.0
@@ -202,3 +202,12 @@ GOVUK.analyticsPlugins.downloadTracker({selector: 'a[rel="download"]'});
202
202
  Category | Action | Label
203
203
  ---------|--------|-------
204
204
  Download Link Clicked | `/some/upload/attachment/file.pdf` | Link text
205
+
206
+ ### Mailto link tracking (`mailto-link-tracker.js`)
207
+
208
+ The tracker will send events for clicks on links beginning with `mailto`. By default the
209
+ plugin uses Google Analytics’ `transport: beacon` method so that events are tracked even if the page unloads.
210
+
211
+ Category | Action | Label
212
+ ---------|--------|-------
213
+ Mailto Link Clicked | mailto:name@email.com | Link text
@@ -0,0 +1,33 @@
1
+ (function() {
2
+ "use strict";
3
+ GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
4
+ GOVUK.analyticsPlugins.mailtoLinkTracker = function () {
5
+
6
+ var mailtoLinkSelector = 'a[href^="mailto:"]';
7
+
8
+ $('body').on('click', mailtoLinkSelector, trackClickEvent);
9
+
10
+ function trackClickEvent(evt) {
11
+ var $link = getLinkFromEvent(evt),
12
+ options = {transport: 'beacon'},
13
+ href = $link.attr('href'),
14
+ linkText = $.trim($link.text());
15
+
16
+ if (linkText) {
17
+ options.label = linkText;
18
+ }
19
+
20
+ GOVUK.analytics.trackEvent('Mailto Link Clicked', href, options);
21
+ }
22
+
23
+ function getLinkFromEvent(evt) {
24
+ var $target = $(evt.target);
25
+
26
+ if (!$target.is('a')) {
27
+ $target = $target.parents('a');
28
+ }
29
+
30
+ return $target;
31
+ }
32
+ }
33
+ }());
@@ -13,7 +13,8 @@ var manifest = {
13
13
  '../../javascripts/govuk/analytics/analytics.js',
14
14
  '../../javascripts/govuk/analytics/error-tracking.js',
15
15
  '../../javascripts/govuk/analytics/external-link-tracker.js',
16
- '../../javascripts/govuk/analytics/download-link-tracker.js'
16
+ '../../javascripts/govuk/analytics/download-link-tracker.js',
17
+ '../../javascripts/govuk/analytics/mailto-link-tracker.js'
17
18
  ],
18
19
  test : [
19
20
  '../unit/modules.spec.js',
@@ -26,6 +27,7 @@ var manifest = {
26
27
  '../unit/analytics/analytics.spec.js',
27
28
  '../unit/analytics/error-tracking.spec.js',
28
29
  '../unit/analytics/external-link-tracker.spec.js',
29
- '../unit/analytics/download-link-tracker.spec.js'
30
+ '../unit/analytics/download-link-tracker.spec.js',
31
+ '../unit/analytics/mailto-link-tracker.spec.js'
30
32
  ]
31
33
  };
@@ -0,0 +1,54 @@
1
+ describe("GOVUK.analyticsPlugins.mailtoLinkTracker", function() {
2
+ var $links;
3
+
4
+ beforeEach(function() {
5
+ $links = $('\
6
+ <div class="mailto-links">\
7
+ <a href="mailto:name1@email.com"></a>\
8
+ <a href="mailto:name2@email.com">The link for a mailto</a>\
9
+ <a href="mailto:name3@email.com"><img src="/img" /></a>\
10
+ </div>');
11
+
12
+ $('html').on('click', function(evt) { evt.preventDefault(); });
13
+ $('body').append($links);
14
+ GOVUK.analytics = {trackEvent:function(){}};
15
+
16
+ GOVUK.analyticsPlugins.mailtoLinkTracker();
17
+ });
18
+
19
+ afterEach(function() {
20
+ $('html').off();
21
+ $('body').off();
22
+ $links.remove();
23
+ delete GOVUK.analytics;
24
+ });
25
+
26
+ it('listens to click events on mailto links', function() {
27
+ spyOn(GOVUK.analytics, 'trackEvent');
28
+
29
+ $('.mailto-links a').each(function() {
30
+ $(this).trigger('click');
31
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalled();
32
+ GOVUK.analytics.trackEvent.calls.reset();
33
+ });
34
+ });
35
+
36
+ it('tracks mailto addresses and link text', function() {
37
+ spyOn(GOVUK.analytics, 'trackEvent');
38
+ $('.mailto-links a').trigger('click');
39
+
40
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
41
+ 'Mailto Link Clicked', 'mailto:name1@email.com', {transport: 'beacon'});
42
+
43
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
44
+ 'Mailto Link Clicked', 'mailto:name2@email.com', {transport: 'beacon', label: 'The link for a mailto'});
45
+ });
46
+
47
+ it('listens to click events on elements within mailto links', function() {
48
+ spyOn(GOVUK.analytics, 'trackEvent');
49
+
50
+ $('.mailto-links a img').trigger('click');
51
+ expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
52
+ 'Mailto Link Clicked', 'mailto:name3@email.com', {transport: 'beacon'});
53
+ });
54
+ });
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: 4.6.1
4
+ version: 4.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bradley Wright
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -227,6 +227,7 @@ files:
227
227
  - app/assets/javascripts/govuk/analytics/error-tracking.js
228
228
  - app/assets/javascripts/govuk/analytics/external-link-tracker.js
229
229
  - app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js
230
+ - app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
230
231
  - app/assets/javascripts/govuk/analytics/print-intent.js
231
232
  - app/assets/javascripts/govuk/modules.js
232
233
  - app/assets/javascripts/govuk/modules/auto-track-event.js
@@ -251,6 +252,7 @@ files:
251
252
  - app/assets/spec/unit/analytics/error-tracking.spec.js
252
253
  - app/assets/spec/unit/analytics/external-link-tracker.spec.js
253
254
  - app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js
255
+ - app/assets/spec/unit/analytics/mailto-link-tracker.spec.js
254
256
  - app/assets/spec/unit/modules.spec.js
255
257
  - app/assets/spec/unit/modules/auto-track-event.spec.js
256
258
  - app/assets/spec/unit/multivariate-test.spec.js