Class: Growthbook::InlineExperiment

Inherits:
Object
  • Object
show all
Defined in:
lib/growthbook/inline_experiment.rb

Overview

Class for creating an inline experiment for evaluating

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ InlineExperiment

Returns a new instance of InlineExperiment.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/growthbook/inline_experiment.rb', line 69

def initialize(options = {})
  @key = get_option(options, :key, '').to_s
  @variations = get_option(options, :variations, [])
  @weights = get_option(options, :weights)
  @active = get_option(options, :active, true)
  @coverage = get_option(options, :coverage, 1.0)
  @ranges = get_option(options, :ranges)
  @condition = get_option(options, :condition)
  @namespace = get_option(options, :namespace)
  @force = get_option(options, :force)
  @hash_attribute = get_option(options, :hash_attribute) || get_option(options, :hashAttribute) || 'id'
  @hash_version = get_option(options, :hash_version) || get_option(options, :hashVersion)
  @meta = get_option(options, :meta)
  @filters = get_option(options, :filters)
  @seed = get_option(options, :seed)
  @name = get_option(options, :name)
  @phase = get_option(options, :phase)
  @fallback_attribute = get_option(options, :fallback_attribute) || get_option(options, :fallbackAttribute)
  @disable_sticky_bucketing = get_option(options, :disable_sticky_bucketing, false) || get_option(options, :disableStickyBucketing, false)
  @bucket_version = get_option(options, :bucket_version) || get_option(options, :bucketVersion) || 0
  @min_bucket_version = get_option(options, :min_bucket_version) || get_option(options, :minBucketVersion) || 0
  @parent_conditions = get_option(options, :parent_conditions) || get_option(options, :parentConditions) || []

  return unless @disable_sticky_bucketing

  @fallback_attribute = nil
end

Instance Attribute Details

#activetrue, false

Returns If set to false, always return the control (first variation).

Returns:

  • (true, false)

    If set to false, always return the control (first variation)



16
17
18
# File 'lib/growthbook/inline_experiment.rb', line 16

def active
  @active
end

#bucket_versioninteger

Returns Appended to the experiment key for sticky bucketing.

Returns:

  • (integer)

    Appended to the experiment key for sticky bucketing



61
62
63
# File 'lib/growthbook/inline_experiment.rb', line 61

def bucket_version
  @bucket_version
end

#conditionHash

Returns Optional targeting condition.

Returns:

  • (Hash)

    Optional targeting condition



25
26
27
# File 'lib/growthbook/inline_experiment.rb', line 25

def condition
  @condition
end

#coverageFloat

Returns What percent of users should be included in the experiment (between 0 and 1, inclusive).

Returns:

  • (Float)

    What percent of users should be included in the experiment (between 0 and 1, inclusive)



19
20
21
# File 'lib/growthbook/inline_experiment.rb', line 19

def coverage
  @coverage
end

#disable_sticky_bucketingbool?

Returns When true, disables sticky bucketing.

Returns:

  • (bool, nil)

    When true, disables sticky bucketing



58
59
60
# File 'lib/growthbook/inline_experiment.rb', line 58

def disable_sticky_bucketing
  @disable_sticky_bucketing
end

#fallback_attributeString?

Returns The attribute to use when hash_attribute is missing (requires Sticky Bucketing).

Returns:

  • (String, nil)

    The attribute to use when hash_attribute is missing (requires Sticky Bucketing)



55
56
57
# File 'lib/growthbook/inline_experiment.rb', line 55

def fallback_attribute
  @fallback_attribute
end

#filtersArray<Hash>

Returns Array of filters to apply.

Returns:

  • (Array<Hash>)

    Array of filters to apply



43
44
45
# File 'lib/growthbook/inline_experiment.rb', line 43

def filters
  @filters
end

#forceinteger?

Returns All users included in the experiment will be forced into the specific variation index.

Returns:

  • (integer, nil)

    All users included in the experiment will be forced into the specific variation index



31
32
33
# File 'lib/growthbook/inline_experiment.rb', line 31

def force
  @force
end

#hash_attributeString

Returns What user attribute should be used to assign variations (defaults to id).

Returns:

  • (String)

    What user attribute should be used to assign variations (defaults to id)



34
35
36
# File 'lib/growthbook/inline_experiment.rb', line 34

def hash_attribute
  @hash_attribute
end

#hash_versionInteger

Returns The hash version to use (default to 1).

Returns:

  • (Integer)

    The hash version to use (default to 1)



37
38
39
# File 'lib/growthbook/inline_experiment.rb', line 37

def hash_version
  @hash_version
end

#keyString

Returns The globally unique identifier for the experiment.

Returns:

  • (String)

    The globally unique identifier for the experiment



7
8
9
# File 'lib/growthbook/inline_experiment.rb', line 7

def key
  @key
end

#metaArray<Hash>

Returns Meta info about the variations.

Returns:

  • (Array<Hash>)

    Meta info about the variations



40
41
42
# File 'lib/growthbook/inline_experiment.rb', line 40

def meta
  @meta
end

#min_bucket_versioninteger

Returns Minimum bucket version required for sticky bucketing.

Returns:

  • (integer)

    Minimum bucket version required for sticky bucketing



64
65
66
# File 'lib/growthbook/inline_experiment.rb', line 64

def min_bucket_version
  @min_bucket_version
end

#nameString

Returns Human-readable name for the experiment.

Returns:

  • (String)

    Human-readable name for the experiment



49
50
51
# File 'lib/growthbook/inline_experiment.rb', line 49

def name
  @name
end

#namespaceString?

Returns Adds the experiment to a namespace.

Returns:

  • (String, nil)

    Adds the experiment to a namespace



28
29
30
# File 'lib/growthbook/inline_experiment.rb', line 28

def namespace
  @namespace
end

#parent_conditionsArray<Hash>

Returns Array of prerequisite flags.

Returns:

  • (Array<Hash>)

    Array of prerequisite flags



67
68
69
# File 'lib/growthbook/inline_experiment.rb', line 67

def parent_conditions
  @parent_conditions
end

#phaseString?

Returns Id of the current experiment phase.

Returns:

  • (String, nil)

    Id of the current experiment phase



52
53
54
# File 'lib/growthbook/inline_experiment.rb', line 52

def phase
  @phase
end

#rangesArray<Hash>

Returns Array of ranges, one per variation.

Returns:

  • (Array<Hash>)

    Array of ranges, one per variation



22
23
24
# File 'lib/growthbook/inline_experiment.rb', line 22

def ranges
  @ranges
end

#seedString?

Returns The hash seed to use.

Returns:

  • (String, nil)

    The hash seed to use



46
47
48
# File 'lib/growthbook/inline_experiment.rb', line 46

def seed
  @seed
end

#variationsArray<String, Integer, Hash>

Returns The different variations to choose between.

Returns:

  • (Array<String, Integer, Hash>)

    The different variations to choose between



10
11
12
# File 'lib/growthbook/inline_experiment.rb', line 10

def variations
  @variations
end

#weightsArray<Float>

Returns How to weight traffic between variations. Must add to 1.

Returns:

  • (Array<Float>)

    How to weight traffic between variations. Must add to 1.



13
14
15
# File 'lib/growthbook/inline_experiment.rb', line 13

def weights
  @weights
end

Instance Method Details

#to_json(*_args) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/growthbook/inline_experiment.rb', line 97

def to_json(*_args)
  res = {}
  res['key'] = @key
  res['variations'] = @variations
  res['weights'] = @weights unless @weights.nil?
  res['active'] = @active if @active != true && !@active.nil?
  res['coverage'] = @coverage if @coverage != 1 && !@coverage.nil?
  res['ranges'] = @ranges
  res['condition'] = @condition
  res['namespace'] = @namespace
  res['force'] = @force unless @force.nil?
  res['hashAttribute'] = @hash_attribute if @hash_attribute != 'id' && !@hash_attribute.nil?
  res['hashVersion'] = @hash_version
  res['meta'] = @meta
  res['filters'] = @filters
  res['seed'] = @seed
  res['name'] = @name
  res['phase'] = @phase
  res['fallbackAttribute'] = @fallback_attribute unless @fallback_attribute.nil?
  res['disableStickyBucketing'] = @disable_sticky_bucketing if @disable_sticky_bucketing
  res['bucketVersion'] = @bucket_version if @bucket_version != 0
  res['minBucketVersion'] = @min_bucket_version if @min_bucket_version != 0
  res['parentConditions'] = @parent_conditions unless @parent_conditions.empty?

  res.compact
end