Class: Growthbook::InlineExperiment
- Inherits:
-
Object
- Object
- Growthbook::InlineExperiment
- Defined in:
- lib/growthbook/inline_experiment.rb
Overview
Class for creating an inline experiment for evaluating
Instance Attribute Summary collapse
-
#active ⇒ true, false
If set to false, always return the control (first variation).
-
#bucket_version ⇒ integer
Appended to the experiment key for sticky bucketing.
-
#condition ⇒ Hash
Optional targeting condition.
-
#coverage ⇒ Float
What percent of users should be included in the experiment (between 0 and 1, inclusive).
-
#disable_sticky_bucketing ⇒ bool?
When true, disables sticky bucketing.
-
#fallback_attribute ⇒ String?
The attribute to use when hash_attribute is missing (requires Sticky Bucketing).
-
#filters ⇒ Array<Hash>
Array of filters to apply.
-
#force ⇒ integer?
All users included in the experiment will be forced into the specific variation index.
-
#hash_attribute ⇒ String
What user attribute should be used to assign variations (defaults to id).
-
#hash_version ⇒ Integer
The hash version to use (default to 1).
-
#key ⇒ String
The globally unique identifier for the experiment.
-
#meta ⇒ Array<Hash>
Meta info about the variations.
-
#min_bucket_version ⇒ integer
Minimum bucket version required for sticky bucketing.
-
#name ⇒ String
Human-readable name for the experiment.
-
#namespace ⇒ String?
Adds the experiment to a namespace.
-
#parent_conditions ⇒ Array<Hash>
Array of prerequisite flags.
-
#phase ⇒ String?
Id of the current experiment phase.
-
#ranges ⇒ Array<Hash>
Array of ranges, one per variation.
-
#seed ⇒ String?
The hash seed to use.
-
#variations ⇒ Array<String, Integer, Hash>
The different variations to choose between.
-
#weights ⇒ Array<Float>
How to weight traffic between variations.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ InlineExperiment
constructor
A new instance of InlineExperiment.
- #to_json(*_args) ⇒ Object
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( = {}) @key = get_option(, :key, '').to_s @variations = get_option(, :variations, []) @weights = get_option(, :weights) @active = get_option(, :active, true) @coverage = get_option(, :coverage, 1.0) @ranges = get_option(, :ranges) @condition = get_option(, :condition) @namespace = get_option(, :namespace) @force = get_option(, :force) @hash_attribute = get_option(, :hash_attribute) || get_option(, :hashAttribute) || 'id' @hash_version = get_option(, :hash_version) || get_option(, :hashVersion) @meta = get_option(, :meta) @filters = get_option(, :filters) @seed = get_option(, :seed) @name = get_option(, :name) @phase = get_option(, :phase) @fallback_attribute = get_option(, :fallback_attribute) || get_option(, :fallbackAttribute) @disable_sticky_bucketing = get_option(, :disable_sticky_bucketing, false) || get_option(, :disableStickyBucketing, false) @bucket_version = get_option(, :bucket_version) || get_option(, :bucketVersion) || 0 @min_bucket_version = get_option(, :min_bucket_version) || get_option(, :minBucketVersion) || 0 @parent_conditions = get_option(, :parent_conditions) || get_option(, :parentConditions) || [] return unless @disable_sticky_bucketing @fallback_attribute = nil end |
Instance Attribute Details
#active ⇒ true, false
Returns 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_version ⇒ integer
Returns 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 |
#condition ⇒ Hash
Returns Optional targeting condition.
25 26 27 |
# File 'lib/growthbook/inline_experiment.rb', line 25 def condition @condition end |
#coverage ⇒ Float
Returns 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_bucketing ⇒ bool?
Returns 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_attribute ⇒ String?
Returns 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 |
#filters ⇒ Array<Hash>
Returns Array of filters to apply.
43 44 45 |
# File 'lib/growthbook/inline_experiment.rb', line 43 def filters @filters end |
#force ⇒ integer?
Returns 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_attribute ⇒ String
Returns 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_version ⇒ Integer
Returns 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 |
#key ⇒ String
Returns The globally unique identifier for the experiment.
7 8 9 |
# File 'lib/growthbook/inline_experiment.rb', line 7 def key @key end |
#meta ⇒ Array<Hash>
Returns Meta info about the variations.
40 41 42 |
# File 'lib/growthbook/inline_experiment.rb', line 40 def @meta end |
#min_bucket_version ⇒ integer
Returns 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 |
#name ⇒ String
Returns Human-readable name for the experiment.
49 50 51 |
# File 'lib/growthbook/inline_experiment.rb', line 49 def name @name end |
#namespace ⇒ String?
Returns Adds the experiment to a namespace.
28 29 30 |
# File 'lib/growthbook/inline_experiment.rb', line 28 def namespace @namespace end |
#parent_conditions ⇒ Array<Hash>
Returns Array of prerequisite flags.
67 68 69 |
# File 'lib/growthbook/inline_experiment.rb', line 67 def parent_conditions @parent_conditions end |
#phase ⇒ String?
Returns Id of the current experiment phase.
52 53 54 |
# File 'lib/growthbook/inline_experiment.rb', line 52 def phase @phase end |
#ranges ⇒ Array<Hash>
Returns Array of ranges, one per variation.
22 23 24 |
# File 'lib/growthbook/inline_experiment.rb', line 22 def ranges @ranges end |
#seed ⇒ String?
Returns The hash seed to use.
46 47 48 |
# File 'lib/growthbook/inline_experiment.rb', line 46 def seed @seed end |
#variations ⇒ Array<String, Integer, Hash>
Returns The different variations to choose between.
10 11 12 |
# File 'lib/growthbook/inline_experiment.rb', line 10 def variations @variations end |
#weights ⇒ Array<Float>
Returns 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 |