govuk_frontend_toolkit 4.13.0 → 4.14.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: fdab1cc5481c808d894dabec2ec8377f3f07e21b
4
- data.tar.gz: ad538d6e392ef3ae4408d8df873580f938234488
3
+ metadata.gz: fcc2e1608a32115e7405c8579739e7673c4e12d6
4
+ data.tar.gz: d2a23439130453227958efe416ecda2ebf335e6c
5
5
  SHA512:
6
- metadata.gz: f1fd18797d04ab572d43c1cde7fdae57ff2bc3cf4ed5aa0834ee881bfe15744d1d92222d2e08718ae3325dd9c8d987ca280b8edab770bf0debb6034b912bbf8f
7
- data.tar.gz: d3bc7e3a5dbf7a5e92a42ac7b80a9c5d571c80dd3f71e215f7b429e3af509fc90982a4712aa7b206243fbcc944af7e4b928213c81cb38f002630f3920035dfab
6
+ metadata.gz: 4336246cb9440cd42fc7aa9d369112c6bc4f50319e43b3f5f62149e6e2ccafbf29c936b9fa32c7f28456c5549ae7d24340495fe5ed79d63937699cfa6316b027
7
+ data.tar.gz: 935e052dc4755027b64609e3837bd01802400f7b02ba5fcc57e00bd89f82a08d94d011471df5bc7e297baf9376f5529e6c30e792811aa897886da623c56f5370
@@ -1,3 +1,9 @@
1
+ # 4.14.0
2
+
3
+ - Allow use of multiple GA customDimensionIndex. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/javascript.md#using-google-custom-dimensions-with-your-own-statistical-model) of the documentation for more information.
4
+ - Configurable duration (in days) for AB Test cookie. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/javascript.md#multivariate-test-framework) of the documentation for more information.
5
+ - Allow base scripts to run within a module loader. See [this PR](https://github.com/alphagov/govuk_frontend_toolkit/pull/290) for more information.
6
+
1
7
  # 4.13.0
2
8
 
3
9
  - Make headings block-level by default (PR #200). If you are styling elements you want to be inline with heading includes, you’ll need to explicitly make them inline in your CSS.
data/app/assets/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # GOV.UK frontend toolkit
2
2
 
3
+ ---
4
+
5
+ #### You can help us improve the GOV.UK frontend toolkit by completing our [5 minute survey](https://www.surveymonkey.co.uk/r/2MZRS9H).
6
+
7
+ ---
8
+
3
9
  A collection of Sass and JavaScript files for using as part of your
4
10
  application's frontend.
5
11
 
@@ -1 +1 @@
1
- 4.13.0
1
+ 4.14.0
@@ -178,6 +178,20 @@ var test = new GOVUK.MultivariateTest({
178
178
  });
179
179
  ```
180
180
 
181
+ If you want to set the cookie expiration then you can optionally set cookieDuration as follows:
182
+
183
+ ```javascript
184
+ var test = new GOVUK.MultivariateTest({
185
+ name: 'car_tax_button_text',
186
+ cookieDuration: 14,
187
+ cohorts: {
188
+ pay_your_car_tax: {weight: 25, callback: function() { ... }}, // 25%
189
+ give_us_money: {weight: 75, callback: function() { ... }} // 75%
190
+ }
191
+ });
192
+ ```
193
+ Here, it is set to expire in 14 days time. if this option is not set the default cookie expiration (30 days) take effect.
194
+
181
195
  If you have a complex test, it may be worth extending MultivariateTest with
182
196
  your own. Callbacks can be strings which will call a method of that name
183
197
  on the current object.
@@ -250,6 +264,24 @@ var test = new GOVUK.MultivariateTest({
250
264
 
251
265
  `customDimensionIndex` is the index of the custom variable in Google Analytics. GA only gives 50 integer slots to each account, and it is important that a unique integer is assigned to each test. Current contact for assigning a custom var slot for GOV.UK is: Tim Leighton-Boyce <tim.leighton-boyce@digital.cabinet-office.gov.uk>
252
266
 
267
+ For certain types of tests where the custom dimensions in Google Analytics can only have one of three scopes (hit, session, or user). Measuring performance of A/B tests, and want to compare test results for session-scoped custom dimensions (eg: index 222) against hit-scoped ones (eg: index 223) may become important.
268
+
269
+ Instead of supplying an integer (like the above example), `customDimensionIndex` can also accept an array of dimension indexes ([222, 223]), see below for more.
270
+
271
+ Make sure to check GA debugger that these values are being sent before deploying.
272
+
273
+ ```js
274
+ var test = new GOVUK.MultivariateTest({
275
+ name: 'car_tax_button_text',
276
+ customDimensionIndex: [222, 223],
277
+ cohorts: {
278
+ pay_your_car_tax: {weight: 25},
279
+ give_us_money: {weight: 50}
280
+ }
281
+ });
282
+ ```
283
+
284
+
253
285
  ## Primary Links
254
286
 
255
287
  `GOVUK.PrimaryList` hides elements in a list which don't have a supplied
@@ -1,6 +1,7 @@
1
- (function() {
1
+ (function(global) {
2
2
  "use strict";
3
- window.GOVUK = window.GOVUK || {};
3
+
4
+ var GOVUK = global.GOVUK || {};
4
5
 
5
6
  // For usage and initialisation see:
6
7
  // https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#create-an-analytics-tracker
@@ -61,4 +62,6 @@
61
62
  };
62
63
 
63
64
  GOVUK.Analytics = Analytics;
64
- })();
65
+
66
+ global.GOVUK = GOVUK;
67
+ })(window);
@@ -1,5 +1,9 @@
1
- (function() {
1
+ (function(global) {
2
2
  "use strict";
3
+
4
+ var $ = global.jQuery;
5
+ var GOVUK = global.GOVUK || {};
6
+
3
7
  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
4
8
  GOVUK.analyticsPlugins.downloadLinkTracker = function (options) {
5
9
  var options = options || {},
@@ -32,4 +36,6 @@
32
36
  return $target;
33
37
  }
34
38
  }
35
- }());
39
+
40
+ global.GOVUK = GOVUK;
41
+ })(window);
@@ -1,6 +1,9 @@
1
1
  // Extension to track errors using google analytics as a data store.
2
- (function() {
2
+ (function(global) {
3
3
  "use strict";
4
+
5
+ var GOVUK = global.GOVUK || {};
6
+
4
7
  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
5
8
 
6
9
  GOVUK.analyticsPlugins.error = function (options) {
@@ -35,12 +38,14 @@
35
38
  return false;
36
39
  }
37
40
 
38
- if (window.addEventListener) {
39
- window.addEventListener('error', trackJavaScriptError, false);
40
- } else if (window.attachEvent) {
41
- window.attachEvent('onerror', trackJavaScriptError);
41
+ if (global.addEventListener) {
42
+ global.addEventListener('error', trackJavaScriptError, false);
43
+ } else if (global.attachEvent) {
44
+ global.attachEvent('onerror', trackJavaScriptError);
42
45
  } else {
43
- window.onerror = trackJavaScriptError;
46
+ global.onerror = trackJavaScriptError;
44
47
  }
45
48
  }
46
- }());
49
+
50
+ global.GOVUK = GOVUK;
51
+ })(window);
@@ -1,5 +1,9 @@
1
- (function() {
1
+ (function(global) {
2
2
  "use strict";
3
+
4
+ var $ = global.jQuery;
5
+ var GOVUK = global.GOVUK || {};
6
+
3
7
  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
4
8
  GOVUK.analyticsPlugins.externalLinkTracker = function () {
5
9
 
@@ -33,6 +37,8 @@
33
37
  }
34
38
 
35
39
  GOVUK.analyticsPlugins.externalLinkTracker.getHostname = function() {
36
- return window.location.hostname;
40
+ return global.location.hostname;
37
41
  }
38
- }());
42
+
43
+ global.GOVUK = GOVUK;
44
+ })(window);
@@ -1,6 +1,7 @@
1
- (function() {
1
+ (function(global) {
2
2
  "use strict";
3
- window.GOVUK = window.GOVUK || {};
3
+
4
+ var GOVUK = global.GOVUK || {};
4
5
 
5
6
  var GoogleAnalyticsUniversalTracker = function(id, cookieDomain) {
6
7
  configureProfile(id, cookieDomain);
@@ -20,7 +21,7 @@
20
21
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
21
22
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
22
23
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
23
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
24
+ })(global,document,'script','//www.google-analytics.com/analytics.js','ga');
24
25
  };
25
26
 
26
27
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
@@ -140,10 +141,12 @@
140
141
  };
141
142
 
142
143
  function sendToGa() {
143
- if (typeof window.ga === "function") {
144
- ga.apply(window, arguments);
144
+ if (typeof global.ga === "function") {
145
+ ga.apply(global, arguments);
145
146
  }
146
147
  }
147
148
 
148
149
  GOVUK.GoogleAnalyticsUniversalTracker = GoogleAnalyticsUniversalTracker;
149
- })();
150
+
151
+ global.GOVUK = GOVUK;
152
+ })(window);
@@ -1,5 +1,9 @@
1
- (function() {
1
+ (function(global) {
2
2
  "use strict";
3
+
4
+ var $ = global.jQuery;
5
+ var GOVUK = global.GOVUK || {};
6
+
3
7
  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
4
8
  GOVUK.analyticsPlugins.mailtoLinkTracker = function () {
5
9
 
@@ -30,4 +34,6 @@
30
34
  return $target;
31
35
  }
32
36
  }
33
- }());
37
+
38
+ global.GOVUK = GOVUK;
39
+ })(window);
@@ -1,7 +1,9 @@
1
1
  // Extension to monitor attempts to print pages.
2
- (function () {
2
+ (function (global) {
3
3
  "use strict";
4
4
 
5
+ var GOVUK = global.GOVUK || {};
6
+
5
7
  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
6
8
 
7
9
  GOVUK.analyticsPlugins.printIntent = function () {
@@ -11,15 +13,15 @@
11
13
  });
12
14
 
13
15
  // Most browsers
14
- if (window.matchMedia) {
15
- var mediaQueryList = window.matchMedia('print'),
16
+ if (global.matchMedia) {
17
+ var mediaQueryList = global.matchMedia('print'),
16
18
  mqlListenerCount = 0;
17
19
  mediaQueryList.addListener(function (mql) {
18
20
  if (!mql.matches && mqlListenerCount === 0) {
19
21
  printAttempt();
20
22
  mqlListenerCount++;
21
23
  // If we try and print again within 3 seconds, don't log it
22
- window.setTimeout(function () {
24
+ setTimeout(function () {
23
25
  mqlListenerCount = 0;
24
26
  // printing will be tracked again now
25
27
  }, 3000);
@@ -28,10 +30,11 @@
28
30
  }
29
31
 
30
32
  // IE < 10
31
- if (window.onafterprint) {
32
- window.onafterprint = printAttempt;
33
+ if (global.onafterprint) {
34
+ global.onafterprint = printAttempt;
33
35
  }
34
36
 
35
37
  };
36
38
 
37
- }());
39
+ global.GOVUK = GOVUK;
40
+ })(window);
@@ -1,7 +1,10 @@
1
- (function(Modules) {
1
+ (function(global) {
2
2
  "use strict";
3
3
 
4
- Modules.AutoTrackEvent = function() {
4
+ var GOVUK = global.GOVUK || {};
5
+ GOVUK.Modules = GOVUK.Modules || {};
6
+
7
+ GOVUK.Modules.AutoTrackEvent = function() {
5
8
  this.start = function(element) {
6
9
  var options = {nonInteraction: 1}, // automatic events shouldn't affect bounce rate
7
10
  category = element.data('track-category'),
@@ -23,4 +26,5 @@
23
26
  }
24
27
  };
25
28
 
26
- })(window.GOVUK.Modules);
29
+ global.GOVUK = GOVUK;
30
+ })(window);
@@ -1,6 +1,8 @@
1
- (function($, root) {
1
+ (function(global) {
2
2
  "use strict";
3
- root.GOVUK = root.GOVUK || {};
3
+
4
+ var $ = global.jQuery;
5
+ var GOVUK = global.GOVUK || {};
4
6
  GOVUK.Modules = GOVUK.Modules || {};
5
7
 
6
8
  GOVUK.modules = {
@@ -53,4 +55,6 @@
53
55
  }
54
56
  }
55
57
  }
56
- })(jQuery, window);
58
+
59
+ global.GOVUK = GOVUK;
60
+ })(window);
@@ -1,7 +1,8 @@
1
- (function() {
1
+ (function(global) {
2
2
  "use strict";
3
- window.GOVUK = window.GOVUK || {};
4
- var $ = window.$;
3
+
4
+ var $ = global.jQuery;
5
+ var GOVUK = global.GOVUK || {};
5
6
 
6
7
  // A multivariate test framework
7
8
  //
@@ -17,6 +18,7 @@
17
18
  this._loadOption(options, 'runImmediately', true);
18
19
  this._loadOption(options, 'defaultWeight', 1);
19
20
  this._loadOption(options, 'contentExperimentId', null);
21
+ this._loadOption(options, 'cookieDuration', 30);
20
22
 
21
23
  if (this.runImmediately) {
22
24
  this.run();
@@ -68,20 +70,29 @@
68
70
  var cohort = GOVUK.cookie(this.cookieName());
69
71
  if (!cohort || !this.cohorts[cohort]) {
70
72
  cohort = this.chooseRandomCohort();
71
- GOVUK.cookie(this.cookieName(), cohort, {days: 30});
73
+ GOVUK.cookie(this.cookieName(), cohort, {days: this.cookieDuration});
72
74
  }
73
75
  return cohort;
74
76
  };
75
77
 
76
78
  MultivariateTest.prototype.setCustomVar = function(cohort) {
77
- if (this.customDimensionIndex) {
78
- GOVUK.analytics.setDimension(
79
- this.customDimensionIndex,
80
- this.cookieName() + "__" + cohort
81
- );
79
+ if (this.customDimensionIndex &&
80
+ this.customDimensionIndex.constructor === Array) {
81
+ for (var index = 0; index < this.customDimensionIndex.length; index++) {
82
+ this.setDimension(cohort, this.customDimensionIndex[index])
83
+ }
84
+ } else if (this.customDimensionIndex) {
85
+ this.setDimension(cohort, this.customDimensionIndex)
82
86
  }
83
87
  };
84
88
 
89
+ MultivariateTest.prototype.setDimension = function(cohort, dimension) {
90
+ GOVUK.analytics.setDimension(
91
+ dimension,
92
+ this.cookieName() + "__" + cohort
93
+ );
94
+ };
95
+
85
96
  MultivariateTest.prototype.setUpContentExperiment = function(cohort) {
86
97
  var contentExperimentId = this.contentExperimentId;
87
98
  var cohortVariantId = this.cohorts[cohort]['variantId'];
@@ -130,5 +141,7 @@
130
141
  return "multivariatetest_cohort_" + this.name;
131
142
  };
132
143
 
133
- window.GOVUK.MultivariateTest = MultivariateTest;
134
- }());
144
+ GOVUK.MultivariateTest = MultivariateTest;
145
+
146
+ global.GOVUK = GOVUK;
147
+ })(window);
@@ -1,6 +1,8 @@
1
- (function() {
1
+ (function(global) {
2
2
  "use strict";
3
- window.GOVUK = window.GOVUK || {};
3
+
4
+ var $ = global.jQuery;
5
+ var GOVUK = global.GOVUK || {};
4
6
 
5
7
  // Only show the first {n} items in a list, documentation is in the README.md
6
8
  var PrimaryList = function(el, selector){
@@ -39,6 +41,7 @@
39
41
  $(window).trigger('govuk.pageSizeChanged');
40
42
  }
41
43
  };
44
+
42
45
  GOVUK.PrimaryList = PrimaryList;
43
46
 
44
47
  GOVUK.primaryLinks = {
@@ -48,4 +51,6 @@
48
51
  });
49
52
  }
50
53
  };
51
- }());
54
+
55
+ global.GOVUK = GOVUK;
56
+ })(window);
@@ -1,9 +1,8 @@
1
- (function () {
1
+ (function (global) {
2
2
  "use strict";
3
- var root = this,
4
- $ = root.jQuery;
5
3
 
6
- if (typeof GOVUK === 'undefined') { root.GOVUK = {}; }
4
+ var $ = global.jQuery;
5
+ var GOVUK = global.GOVUK || {};
7
6
 
8
7
  var SelectionButtons = function (elmsOrSelector, opts) {
9
8
  var $elms;
@@ -107,5 +106,6 @@
107
106
  }
108
107
  };
109
108
 
110
- root.GOVUK.SelectionButtons = SelectionButtons;
111
- }).call(this);
109
+ GOVUK.SelectionButtons = SelectionButtons;
110
+ global.GOVUK = GOVUK;
111
+ })(window);
@@ -1,8 +1,8 @@
1
- (function () {
1
+ (function (global) {
2
2
  "use strict";
3
- var root = this,
4
- $ = root.jQuery;
5
- if(typeof root.GOVUK === 'undefined') { root.GOVUK = {}; }
3
+
4
+ var $ = global.jQuery;
5
+ var GOVUK = global.GOVUK || {};
6
6
 
7
7
  // Stick elements to top of screen when you scroll past, documentation is in the README.md
8
8
  var sticky = {
@@ -16,22 +16,22 @@
16
16
  sticky.$els = $els;
17
17
 
18
18
  if(sticky._scrollTimeout === false) {
19
- $(root).scroll(sticky.onScroll);
20
- sticky._scrollTimeout = root.setInterval(sticky.checkScroll, 50);
19
+ $(global).scroll(sticky.onScroll);
20
+ sticky._scrollTimeout = global.setInterval(sticky.checkScroll, 50);
21
21
  }
22
- $(root).resize(sticky.onResize);
22
+ $(global).resize(sticky.onResize);
23
23
  }
24
- if(root.GOVUK.stopScrollingAtFooter){
24
+ if(GOVUK.stopScrollingAtFooter){
25
25
  $els.each(function(i,el){
26
26
  var $img = $(el).find('img');
27
27
  if($img.length > 0){
28
28
  var image = new Image();
29
29
  image.onload = function(){
30
- root.GOVUK.stopScrollingAtFooter.addEl($(el), $(el).outerHeight());
30
+ GOVUK.stopScrollingAtFooter.addEl($(el), $(el).outerHeight());
31
31
  };
32
32
  image.src = $img.attr('src');
33
33
  } else {
34
- root.GOVUK.stopScrollingAtFooter.addEl($(el), $(el).outerHeight());
34
+ GOVUK.stopScrollingAtFooter.addEl($(el), $(el).outerHeight());
35
35
  }
36
36
  });
37
37
  }
@@ -43,14 +43,14 @@
43
43
  if(sticky._hasScrolled === true){
44
44
  sticky._hasScrolled = false;
45
45
 
46
- var windowVerticalPosition = $(root).scrollTop();
46
+ var windowVerticalPosition = $(global).scrollTop();
47
47
  sticky.$els.each(function(i, el){
48
48
  var $el = $(el),
49
49
  scrolledFrom = $el.data('scrolled-from');
50
50
 
51
51
  if (scrolledFrom && windowVerticalPosition < scrolledFrom){
52
52
  sticky.release($el);
53
- } else if($(root).width() > 768 && windowVerticalPosition >= $el.offset().top) {
53
+ } else if($(global).width() > 768 && windowVerticalPosition >= $el.offset().top) {
54
54
  sticky.stick($el);
55
55
  }
56
56
  });
@@ -72,5 +72,6 @@
72
72
  }
73
73
  }
74
74
  };
75
- root.GOVUK.stickAtTopWhenScrolling = sticky;
76
- }).call(this);
75
+ GOVUK.stickAtTopWhenScrolling = sticky;
76
+ global.GOVUK = GOVUK;
77
+ })(window);
@@ -11,11 +11,11 @@
11
11
  // itself.
12
12
 
13
13
 
14
- (function () {
14
+ (function (global) {
15
15
  "use strict";
16
- var root = this,
17
- $ = root.jQuery;
18
- if(typeof root.GOVUK === 'undefined') { root.GOVUK = {}; }
16
+
17
+ var $ = global.jQuery;
18
+ var GOVUK = global.GOVUK || {};
19
19
 
20
20
  var stopScrollingAtFooter = {
21
21
  _pollingId: null,
@@ -32,7 +32,7 @@
32
32
  fixedOffset = isNaN(fixedOffset) ? 0 : fixedOffset;
33
33
 
34
34
  stopScrollingAtFooter.updateFooterTop();
35
- $(root).on('govuk.pageSizeChanged', stopScrollingAtFooter.updateFooterTop);
35
+ $(global).on('govuk.pageSizeChanged', stopScrollingAtFooter.updateFooterTop);
36
36
 
37
37
  var $siblingEl = $('<div></div>');
38
38
  $siblingEl.insertBefore($fixedEl);
@@ -63,7 +63,7 @@
63
63
  }
64
64
  },
65
65
  onScroll: function(){
66
- if (stopScrollingAtFooter._isPolling === false) {
66
+ if (stopScrollingAtFooter._isPolling === false) {
67
67
  stopScrollingAtFooter.startPolling();
68
68
  }
69
69
  },
@@ -132,7 +132,9 @@
132
132
  }
133
133
  };
134
134
 
135
- root.GOVUK.stopScrollingAtFooter = stopScrollingAtFooter;
135
+ GOVUK.stopScrollingAtFooter = stopScrollingAtFooter;
136
+
137
+ $(global).load(function(){ $(global).trigger('govuk.pageSizeChanged'); });
136
138
 
137
- $(root).load(function(){ $(root).trigger('govuk.pageSizeChanged'); });
138
- }).call(this);
139
+ global.GOVUK = GOVUK;
140
+ })(window);
@@ -1,63 +1,70 @@
1
1
  // Stageprompt 2.0.1
2
- //
2
+ //
3
3
  // See: https://github.com/alphagov/stageprompt
4
- //
5
- // Stageprompt allows user journeys to be described and instrumented
4
+ //
5
+ // Stageprompt allows user journeys to be described and instrumented
6
6
  // using data attributes.
7
- //
7
+ //
8
8
  // Setup (run this on document ready):
9
- //
9
+ //
10
10
  // GOVUK.performance.stageprompt.setupForGoogleAnalytics();
11
- //
11
+ //
12
12
  // Usage:
13
- //
13
+ //
14
14
  // Sending events on page load:
15
- //
15
+ //
16
16
  // <div id="wrapper" class="service" data-journey="pay-register-birth-abroad:start">
17
17
  // [...]
18
18
  // </div>
19
- //
19
+ //
20
20
  // Sending events on click:
21
- //
21
+ //
22
22
  // <a class="help-button" href="#" data-journey-click="stage:help:info">See more info...</a>
23
23
 
24
- var GOVUK = GOVUK || {};
24
+ (function(global) {
25
+ "use strict";
25
26
 
26
- GOVUK.performance = GOVUK.performance || {};
27
+ var $ = global.jQuery;
28
+ var GOVUK = global.GOVUK || {};
27
29
 
28
- GOVUK.performance.stageprompt = (function () {
30
+ GOVUK.performance = GOVUK.performance || {};
29
31
 
30
- var setup, setupForGoogleAnalytics, splitAction;
32
+ GOVUK.performance.stageprompt = (function () {
31
33
 
32
- splitAction = function (action) {
33
- var parts = action.split(':');
34
- if (parts.length <= 3) return parts;
35
- return [parts.shift(), parts.shift(), parts.join(':')];
36
- };
34
+ var setup, setupForGoogleAnalytics, splitAction;
37
35
 
38
- setup = function (analyticsCallback) {
39
- var journeyStage = $('[data-journey]').attr('data-journey'),
40
- journeyHelpers = $('[data-journey-click]');
41
-
42
- if (journeyStage) {
43
- analyticsCallback.apply(null, splitAction(journeyStage));
44
- }
45
-
46
- journeyHelpers.on('click', function (event) {
47
- analyticsCallback.apply(null, splitAction($(this).data('journey-click')));
48
- });
49
- };
50
-
51
- setupForGoogleAnalytics = function () {
52
- setup(GOVUK.performance.sendGoogleAnalyticsEvent);
53
- };
36
+ splitAction = function (action) {
37
+ var parts = action.split(':');
38
+ if (parts.length <= 3) return parts;
39
+ return [parts.shift(), parts.shift(), parts.join(':')];
40
+ };
41
+
42
+ setup = function (analyticsCallback) {
43
+ var journeyStage = $('[data-journey]').attr('data-journey'),
44
+ journeyHelpers = $('[data-journey-click]');
45
+
46
+ if (journeyStage) {
47
+ analyticsCallback.apply(null, splitAction(journeyStage));
48
+ }
49
+
50
+ journeyHelpers.on('click', function (event) {
51
+ analyticsCallback.apply(null, splitAction($(this).data('journey-click')));
52
+ });
53
+ };
54
+
55
+ setupForGoogleAnalytics = function () {
56
+ setup(GOVUK.performance.sendGoogleAnalyticsEvent);
57
+ };
58
+
59
+ return {
60
+ setup: setup,
61
+ setupForGoogleAnalytics: setupForGoogleAnalytics
62
+ };
63
+ }());
54
64
 
55
- return {
56
- setup: setup,
57
- setupForGoogleAnalytics: setupForGoogleAnalytics
65
+ GOVUK.performance.sendGoogleAnalyticsEvent = function (category, event, label) {
66
+ _gaq.push(['_trackEvent', category, event, label, undefined, true]);
58
67
  };
59
- }());
60
68
 
61
- GOVUK.performance.sendGoogleAnalyticsEvent = function (category, event, label) {
62
- _gaq.push(['_trackEvent', category, event, label, undefined, true]);
63
- };
69
+ global.GOVUK = GOVUK;
70
+ })(window);
@@ -22,6 +22,6 @@ if [ "$MASTER_SHA" == "$HEAD_SHA" ]; then
22
22
  git push origin $VERSION_TAG
23
23
 
24
24
  # Alias branch for the most recently released tag, for easier diffing
25
- git push origin master:latest-release
25
+ git push -f origin master:latest-release
26
26
  fi
27
27
  fi
@@ -1,4 +1,4 @@
1
- (function (root) {
1
+ (function (global) {
2
2
  "use strict"
3
3
  var loadedScripts = 0,
4
4
  totalScripts,
@@ -44,4 +44,4 @@
44
44
  totalScripts = merge([manifest.support, manifest.test]);
45
45
  loadScript(totalScripts[idx], idx + 1);
46
46
  };
47
- }).call(this);
47
+ })(window);
@@ -63,6 +63,26 @@ describe("MultivariateTest", function() {
63
63
  );
64
64
  });
65
65
 
66
+ it("should be able to set multiple custom vars with the name and cohort if one is defined as an array", function() {
67
+ GOVUK.cookie.and.returnValue('foo');
68
+ var test = new GOVUK.MultivariateTest({
69
+ name: 'stuff',
70
+ cohorts: {
71
+ foo: {},
72
+ bar: {}
73
+ },
74
+ customDimensionIndex: [2,3]
75
+ });
76
+ expect(GOVUK.analytics.setDimension).toHaveBeenCalledWith(
77
+ 2,
78
+ 'multivariatetest_cohort_stuff__foo'
79
+ );
80
+ expect(GOVUK.analytics.setDimension).toHaveBeenCalledWith(
81
+ 3,
82
+ 'multivariatetest_cohort_stuff__foo'
83
+ );
84
+ });
85
+
66
86
  it("should trigger an event to track that the test has been run", function() {
67
87
  GOVUK.cookie.and.returnValue('foo');
68
88
  var test = new GOVUK.MultivariateTest({
@@ -124,6 +144,29 @@ describe("MultivariateTest", function() {
124
144
  expect(test.fooCallback).toHaveBeenCalled();
125
145
  });
126
146
 
147
+ it("should assign 30 if cookieDuration isn't defined", function() {
148
+ GOVUK.cookie.and.returnValue('foo');
149
+ var test = new GOVUK.MultivariateTest({
150
+ name: 'cookie_duration_test',
151
+ cohorts: {
152
+ foo: {callback: function(){}}
153
+ }
154
+ });
155
+ expect(test.cookieDuration).toEqual(30);
156
+ });
157
+
158
+ it("should assign the user's cookie duration, when cookieDuration is defined", function() {
159
+ GOVUK.cookie.and.returnValue('foo');
160
+ var test = new GOVUK.MultivariateTest({
161
+ name: 'cookie_duration_test',
162
+ cookieDuration: 14,
163
+ cohorts: {
164
+ foo: {callback: function(){}}
165
+ }
166
+ });
167
+ expect(test.cookieDuration).toEqual(14);
168
+ });
169
+
127
170
  it("should assign a new random cohort if the assigned cohort does not exist", function() {
128
171
  var fooSpy = jasmine.createSpy('fooSpy');
129
172
  var barSpy = jasmine.createSpy('barSpy');
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = "govuk_frontend_toolkit"
7
7
  s.version = GovUKFrontendToolkit.toolkit_version
8
8
  s.summary = 'Tools for building frontend applications'
9
- s.authors = ['Bradley Wright']
10
- s.email = 'bradley.wright@digital.cabinet-office.gov.uk'
9
+ s.authors = ["Government Digital Service"]
10
+ s.email = ["govuk-dev@digital.cabinet-office.gov.uk"]
11
11
  s.homepage = 'https://github.com/alphagov/govuk_frontend_toolkit'
12
12
  s.license = 'MIT'
13
13
 
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.13.0
4
+ version: 4.14.0
5
5
  platform: ruby
6
6
  authors:
7
- - Bradley Wright
7
+ - Government Digital Service
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-23 00:00:00.000000000 Z
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -67,7 +67,8 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.9.2.2
69
69
  description:
70
- email: bradley.wright@digital.cabinet-office.gov.uk
70
+ email:
71
+ - govuk-dev@digital.cabinet-office.gov.uk
71
72
  executables: []
72
73
  extensions: []
73
74
  extra_rdoc_files: []