govuk_ab_testing 0.1.0 → 0.1.1

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: a131dac8f3c6fe3c8bd613056c2c639790807519
4
- data.tar.gz: 247f153ccd3d578a4340594198858c34faec0bbb
3
+ metadata.gz: 9bc5b6a51bbc98c18d8b98be5bef8dc8f1da357b
4
+ data.tar.gz: 88fead7061b12d481392042abcf7c5538c719328
5
5
  SHA512:
6
- metadata.gz: da4a7338ea7be7c6535637bf7f8f0d9ab7e047bdd9a55786a6c7d90e2f7e00d7f907c2179ef2e25e85a914945f487054244eb470817c80c4ae0f3ba68af3a9ae
7
- data.tar.gz: 074fdfce8d5d4a9dc749fae59c495cfb3a57d5f97561939b5704e1f62ca7bc90e80fb3360ec2bddb61f30335a566c6700d0a937ecf6b8b0a8321b42570a17fec
6
+ metadata.gz: a923e35735f9643f0f08c59a2486fd9dbf47098996f302136a6590bd82f092bf47bd795ae1268a965d883e234b62ed8ae46e711cbd1d4ad626be4eee42ac2ec1
7
+ data.tar.gz: 7c4aaa517b641a8cab5437016bae55e4d3709323ebc3a3c53a4a7ef725efda1afbe9440475c66d2a1124a0bbb709c6755b90848152ca9eebfc19e8abed2f020f
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
data/README.md CHANGED
@@ -29,7 +29,8 @@ that you pass to the Gem. The cookie name is case-sensitive.
29
29
  To enable testing in the app, your Rails app needs:
30
30
 
31
31
  1. Some piece of logic to be A/B tested
32
- 2. A HTML meta tag that will be used to measure the results
32
+ 2. A HTML meta tag that will be used to measure the results, and which specifies
33
+ the dimension to use in Google Analytics
33
34
  3. A response HTTP header that tells Fastly you're doing an A/B test
34
35
 
35
36
  Let's say you have this controller:
@@ -38,7 +39,7 @@ Let's say you have this controller:
38
39
  # app/controllers/party_controller.rb
39
40
  class PartyController < ApplicationController
40
41
  def show
41
- ab_test = GovukAbTesting::AbTest.new("your_ab_test_name")
42
+ ab_test = GovukAbTesting::AbTest.new("your_ab_test_name", dimension: 300)
42
43
  @requested_variant = ab_test.requested_variant(request)
43
44
  @requested_variant.configure_response(response)
44
45
 
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "govuk-lint", "~> 1.2.1"
26
27
  spec.add_development_dependency "yard", "~> 0.8"
27
28
  spec.add_development_dependency "gem_publisher", "~> 1.5.0"
28
29
  end
@@ -2,14 +2,18 @@ module GovukAbTesting
2
2
  class AbTest
3
3
  attr_reader :ab_test_name
4
4
 
5
- def initialize(ab_test_name)
5
+ # @param request [String] the name of the A/B test
6
+ # @param dimension [Integer] the dimension registered with Google Analytics
7
+ # for this specific A/B test
8
+ def initialize(ab_test_name, dimension:)
6
9
  @ab_test_name = ab_test_name
10
+ @dimension = dimension
7
11
  end
8
12
 
9
13
  # @param request [ApplicationController::Request] the `request` in the
10
14
  # controller.
11
15
  def requested_variant(request)
12
- RequestedVariant.new(self, request)
16
+ RequestedVariant.new(self, request, @dimension)
13
17
  end
14
18
 
15
19
  # Internal name of the header
@@ -3,7 +3,7 @@ module GovukAbTesting
3
3
  def with_variant(args)
4
4
  ab_test_name, variant = args.first
5
5
 
6
- ab_test = GovukAbTesting::AbTest.new(ab_test_name.to_s)
6
+ ab_test = GovukAbTesting::AbTest.new(ab_test_name.to_s, dimension: args[:dimension])
7
7
 
8
8
  @request.headers[ab_test.request_header] = variant
9
9
  requested_variant = ab_test.requested_variant(@request)
@@ -13,8 +13,11 @@ module GovukAbTesting
13
13
  assert_equal ab_test.response_header, response.headers['Vary'], "You probably forgot to use `configure_response`"
14
14
 
15
15
  unless args[:assert_meta_tag] == false
16
+ raise "Cannot test the A/B meta tag because no expected :dimension parameter was specified by test" unless args[:dimension]
17
+
16
18
  assert_meta_tag "govuk:ab-test",
17
19
  ab_test.meta_tag_name + ':' + requested_variant.variant_name,
20
+ args[:dimension],
18
21
  "You probably forgot to add the `analytics_meta_tag`"
19
22
  end
20
23
  end
@@ -34,8 +37,8 @@ module GovukAbTesting
34
37
 
35
38
  private
36
39
 
37
- def assert_meta_tag(name, content, message)
38
- assert_select "meta[name='#{name}'][content='#{content}']", 1, message
40
+ def assert_meta_tag(name, content, dimension, message)
41
+ assert_select "meta[name='#{name}'][content='#{content}'][data-analytics-dimension='#{dimension}']", 1, message
39
42
  end
40
43
  end
41
44
  end
@@ -5,9 +5,12 @@ module GovukAbTesting
5
5
  # @param ab_test [AbTest] the A/B test being performed
6
6
  # @param request [ApplicationController::Request] the `request` in the
7
7
  # controller.
8
- def initialize(ab_test, request)
8
+ # @param dimension [Integer] the dimension registered with Google Analytics
9
+ # for this specific A/B test
10
+ def initialize(ab_test, request, dimension)
9
11
  @ab_test = ab_test
10
12
  @request = request
13
+ @dimension = dimension
11
14
  end
12
15
 
13
16
  # Get the bucket this user is in
@@ -39,7 +42,9 @@ module GovukAbTesting
39
42
  #
40
43
  # @return [String]
41
44
  def analytics_meta_tag
42
- '<meta name="govuk:ab-test" content="' + ab_test.meta_tag_name + ':' + variant_name + '">'
45
+ '<meta name="govuk:ab-test" ' +
46
+ 'content="' + ab_test.meta_tag_name + ':' + variant_name + '" ' +
47
+ 'data-analytics-dimension="' + @dimension.to_s + '">'
43
48
  end
44
49
  end
45
50
  end
@@ -1,3 +1,3 @@
1
1
  module GovukAbTesting
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1".freeze
3
3
  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: 0.1.0
4
+ version: 0.1.1
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-02-09 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: govuk-lint
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: yard
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +89,7 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - ".gitignore"
77
91
  - ".rspec"
92
+ - ".rubocop.yml"
78
93
  - ".ruby-version"
79
94
  - CHANGELOG.md
80
95
  - Gemfile