Class: GovukAbTesting::AbTest

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_ab_testing/ab_test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ab_test_name, dimension:, allowed_variants: %w[A B], control_variant: "A") ⇒ AbTest

for this specific A/B test possible variants

Parameters:

  • request (String)

    the name of the A/B test

  • dimension (Integer)

    the dimension registered with Google Analytics

  • allowed_variants (Array) (defaults to: %w[A B])

    an array of Strings representing the

  • control_variant (String) (defaults to: "A")

    the control variant (typically ‘A’)



13
14
15
16
17
18
# File 'lib/govuk_ab_testing/ab_test.rb', line 13

def initialize(ab_test_name, dimension:, allowed_variants: %w[A B], control_variant: "A")
  @ab_test_name = ab_test_name
  @dimension = dimension
  @allowed_variants = allowed_variants
  @control_variant = control_variant
end

Instance Attribute Details

#ab_test_nameObject (readonly) Also known as: name

Returns the value of attribute ab_test_name.



3
4
5
# File 'lib/govuk_ab_testing/ab_test.rb', line 3

def ab_test_name
  @ab_test_name
end

#allowed_variantsObject (readonly)

Returns the value of attribute allowed_variants.



3
4
5
# File 'lib/govuk_ab_testing/ab_test.rb', line 3

def allowed_variants
  @allowed_variants
end

#control_variantObject (readonly)

Returns the value of attribute control_variant.



3
4
5
# File 'lib/govuk_ab_testing/ab_test.rb', line 3

def control_variant
  @control_variant
end

#dimensionObject (readonly)

Returns the value of attribute dimension.



3
4
5
# File 'lib/govuk_ab_testing/ab_test.rb', line 3

def dimension
  @dimension
end

Instance Method Details

#meta_tag_nameObject



35
36
37
# File 'lib/govuk_ab_testing/ab_test.rb', line 35

def meta_tag_name
  ab_test_name
end

#request_headerObject

Internal name of the header



27
28
29
# File 'lib/govuk_ab_testing/ab_test.rb', line 27

def request_header
  "HTTP_GOVUK_ABTEST_#{ab_test_name.upcase}"
end

#requested_variant(request_headers) ⇒ Object

the controller.

Parameters:

  • request (ActionDispatch::Http::Headers)

    the ‘request.headers` in



22
23
24
# File 'lib/govuk_ab_testing/ab_test.rb', line 22

def requested_variant(request_headers)
  RequestedVariant.new(self, request_headers, @dimension)
end

#response_headerObject



31
32
33
# File 'lib/govuk_ab_testing/ab_test.rb', line 31

def response_header
  "GOVUK-ABTest-#{meta_tag_name}"
end