govuk_ab_testing 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +3 -6
- data/lib/govuk_ab_testing/ab_test.rb +8 -1
- data/lib/govuk_ab_testing/requested_variant.rb +25 -2
- data/lib/govuk_ab_testing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33722ac9662c30de4c5efa423f8de33da6341a78
|
4
|
+
data.tar.gz: 0c65ef65524a43ee0108e33c2be4599d83550386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b89a6c500a941ec1ff9c099c96be9663b0628bb8df81ef74a107ae561300ba16750047587d1287cf02f0cca78b9a600f475ff2ffcf08b2eaeb79e02d19ac161
|
7
|
+
data.tar.gz: 7ef09915ff51828ad9843a44a8c2f01cb196d5edafe7fb4dcf4e5e86c29a86b09dfb80efdbbb616c7c10305c36cd7729ef748ba162f743fe3974c3f4d9325f2a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## 2.4.0
|
2
|
+
|
3
|
+
* Add two new optional parameters to `GovukAbTesting::AbTest`:
|
4
|
+
`allowed_variants` and `control_variant`. These allow us to override the
|
5
|
+
traditional naming of the A/B tests and also setup a multivariate test if
|
6
|
+
needed.
|
7
|
+
* Add new method to `RequestedVariant` to query if a user is in a given variant.
|
8
|
+
The method is `variant?(name)`, where `name` is the name of the variant.
|
9
|
+
This new method allows for generic variant names, which are useful when
|
10
|
+
reusing A/B testing cookies/headers. If the cookie name and header name are
|
11
|
+
generic, the variant value should provide details on what test is running.
|
12
|
+
* Add deprecation warnings to `variant_a?` and `variant_b?`, as they will be
|
13
|
+
replaced by the method `variant?(name)`.
|
14
|
+
|
1
15
|
## 2.3.1
|
2
16
|
|
3
17
|
* Fix bug in order to allow us to set multiple headers (i.e. A/B tests) in a
|
data/README.md
CHANGED
@@ -18,12 +18,9 @@ And then execute:
|
|
18
18
|
|
19
19
|
### Usage
|
20
20
|
|
21
|
-
Before starting this, you'll need to
|
21
|
+
Before starting this, you'll need to:
|
22
22
|
|
23
|
-
-
|
24
|
-
- configure the CDN [like we did for the Education Navigation test](https://github.com/alphagov/govuk-cdn-config/pull/17).
|
25
|
-
The cookie and header name in the CDN config must match the test name parameter
|
26
|
-
that you pass to the Gem. The cookie name is case-sensitive.
|
23
|
+
- [read the documentation](https://docs.publishing.service.gov.uk/manual/ab-testing.html) on how to set up an a/b test. The cookie and header name in [fastly-configure](https://github.com/alphagov/fastly-configure) and [CDN config](https://github.digital.cabinet-office.gov.uk/gds/cdn-configs) must match the test name parameter that you pass to the Gem. The cookie name is case-sensitive.
|
27
24
|
- configure Google Analytics (guidelines to follow)
|
28
25
|
|
29
26
|
To enable testing in the app, your Rails app needs:
|
@@ -57,7 +54,7 @@ class PartyController < ApplicationController
|
|
57
54
|
@requested_variant = ab_test.requested_variant(request.headers)
|
58
55
|
@requested_variant.configure_response(response)
|
59
56
|
|
60
|
-
if @requested_variant.
|
57
|
+
if @requested_variant.variant?('B')
|
61
58
|
render "new_show_template_to_be_tested"
|
62
59
|
else
|
63
60
|
render "show"
|
@@ -2,15 +2,22 @@ module GovukAbTesting
|
|
2
2
|
class AbTest
|
3
3
|
attr_reader :ab_test_name
|
4
4
|
attr_reader :dimension
|
5
|
+
attr_reader :allowed_variants
|
6
|
+
attr_reader :control_variant
|
5
7
|
|
6
8
|
alias_method :name, :ab_test_name
|
7
9
|
|
8
10
|
# @param request [String] the name of the A/B test
|
9
11
|
# @param dimension [Integer] the dimension registered with Google Analytics
|
10
12
|
# for this specific A/B test
|
11
|
-
|
13
|
+
# @param allowed_variants [Array] an array of Strings representing the
|
14
|
+
# possible variants
|
15
|
+
# @param control_variant [String] the control variant (typically 'A')
|
16
|
+
def initialize(ab_test_name, dimension:, allowed_variants: %w(A B), control_variant: 'A')
|
12
17
|
@ab_test_name = ab_test_name
|
13
18
|
@dimension = dimension
|
19
|
+
@allowed_variants = allowed_variants
|
20
|
+
@control_variant = control_variant
|
14
21
|
end
|
15
22
|
|
16
23
|
# @param request [ActionDispatch::Http::Headers] the `request.headers` in
|
@@ -17,19 +17,41 @@ module GovukAbTesting
|
|
17
17
|
#
|
18
18
|
# @return [String] the current variant, "A" or "B"
|
19
19
|
def variant_name
|
20
|
-
|
20
|
+
variant = ab_test.allowed_variants.find do |allowed_variant|
|
21
|
+
allowed_variant == request_headers[ab_test.request_header]
|
22
|
+
end
|
23
|
+
|
24
|
+
variant || ab_test.control_variant
|
21
25
|
end
|
22
26
|
|
23
27
|
# @return [Boolean] if the user is to be served variant A
|
24
28
|
def variant_a?
|
29
|
+
warn 'DEPRECATION WARNING: the method `variant_a?` is deprecated. use `variant?("A")` instead'
|
30
|
+
|
25
31
|
variant_name == "A"
|
26
32
|
end
|
27
33
|
|
28
34
|
# @return [Boolean] if the user is to be served variant B
|
29
35
|
def variant_b?
|
36
|
+
warn 'DEPRECATION WARNING: the method `variant_b?` is deprecated. use `variant?("B")` instead'
|
37
|
+
|
30
38
|
variant_name == "B"
|
31
39
|
end
|
32
40
|
|
41
|
+
# Check if the user should be served a specific variant
|
42
|
+
#
|
43
|
+
# @param [String or Symbol] the name of the variant
|
44
|
+
#
|
45
|
+
# @return [Boolean] if the user is to be served variant :name
|
46
|
+
def variant?(name)
|
47
|
+
error_message =
|
48
|
+
"Invalid variant name '#{name}'. Allowed variants are: #{ab_test.allowed_variants}"
|
49
|
+
|
50
|
+
raise error_message unless ab_test.allowed_variants.include?(name.to_s)
|
51
|
+
|
52
|
+
variant_name == name.to_s
|
53
|
+
end
|
54
|
+
|
33
55
|
# Configure the response
|
34
56
|
#
|
35
57
|
# @param [ApplicationController::Response] the `response` in the controller
|
@@ -43,7 +65,8 @@ module GovukAbTesting
|
|
43
65
|
def analytics_meta_tag
|
44
66
|
'<meta name="govuk:ab-test" ' +
|
45
67
|
'content="' + ab_test.meta_tag_name + ':' + variant_name + '" ' +
|
46
|
-
'data-analytics-dimension="' + @dimension.to_s + '"
|
68
|
+
'data-analytics-dimension="' + @dimension.to_s + '" ' +
|
69
|
+
'data-allowed-variants="' + ab_test.allowed_variants.join(',') + '">'
|
47
70
|
end
|
48
71
|
end
|
49
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_ab_testing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|