growthbook 1.1.0 → 1.2.0

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
  SHA256:
3
- metadata.gz: f5919b4bd1e6564233d0fb61f00f2fcc5fee175f3122a35e9815df47ebdaeb6f
4
- data.tar.gz: 88bf0372e161e261a536fd8953f858e9f4ad60592a96cbfb8e3baa523414cbca
3
+ metadata.gz: 2d8ce0f8ecb79cd594b5b6e820410acb3abc3773c8a3012f8cf39df388d94acb
4
+ data.tar.gz: 0f9030d6c3db6fdcc7821e28fe18379967ed20aa88661d946ec67c56af3c6ef1
5
5
  SHA512:
6
- metadata.gz: 771a1f4fd4eeb6acb92606e67677d65717e3b3a98de80528d2adef3cce17f183a6524af1da74cb09ff18d195a062dd1c882c208cb8dfeaf631603c54b7d128e9
7
- data.tar.gz: 3b2386b97c64ea3609ad907005d90baec0a25e7b51d45bbd973490d66a204255d5a31d1d435da406cfcd8f3443a28bb8163e6f649af114999b847cbe822f2593
6
+ metadata.gz: 963c831c370739516b95dcecfb1ba321202a53ab053316f1e715df452b599fb0213b04355b5bd31d3f5c6c5b54100307f5ca2231321e4f04375a68774e8752c2
7
+ data.tar.gz: 4858df411e5cf01bf35d08e1ea77bf588f04e7d6b49d99d750f0280c0bc0513486604e574bf580b005c2d0eb703ce52ffe507221b8aa83e184d29123cacac7ed
@@ -15,6 +15,9 @@ module Growthbook
15
15
  # @return [Growthbook::TrackingCallback] An object that responds to `on_experiment_viewed(GrowthBook::InlineExperiment, GrowthBook::InlineExperimentResult)`
16
16
  attr_accessor :listener
17
17
 
18
+ # @return [Growthbook::FeatureUsageCallback] An object that responds to `on_feature_usage(String, Growthbook::FeatureResult)`
19
+ attr_accessor :on_feature_usage
20
+
18
21
  # @return [Hash] Map of user attributes that are used to assign variations
19
22
  attr_reader :attributes
20
23
 
@@ -61,6 +64,8 @@ module Growthbook
61
64
  @qa_mode = value
62
65
  when :listener
63
66
  @listener = value
67
+ when :on_feature_usage
68
+ @on_feature_usage = value
64
69
  else
65
70
  warn("Unknown context option: #{key}")
66
71
  end
@@ -94,11 +99,11 @@ module Growthbook
94
99
 
95
100
  def eval_feature(key)
96
101
  # Forced in the context
97
- return get_feature_result(@forced_features[key.to_s], 'override', nil, nil) if @forced_features.key?(key.to_s)
102
+ return get_feature_result(key.to_s, @forced_features[key.to_s], 'override', nil, nil) if @forced_features.key?(key.to_s)
98
103
 
99
104
  # Return if we can't find the feature definition
100
105
  feature = get_feature(key)
101
- return get_feature_result(nil, 'unknownFeature', nil, nil) unless feature
106
+ return get_feature_result(key.to_s, nil, 'unknownFeature', nil, nil) unless feature
102
107
 
103
108
  feature.rules.each do |rule|
104
109
  # Targeting condition
@@ -120,7 +125,7 @@ module Growthbook
120
125
  )
121
126
  next unless included_in_rollout
122
127
 
123
- return get_feature_result(rule.force, 'force', nil, nil)
128
+ return get_feature_result(key.to_s, rule.force, 'force', nil, nil)
124
129
  end
125
130
  # Experiment rule
126
131
  next unless rule.experiment?
@@ -132,11 +137,11 @@ module Growthbook
132
137
 
133
138
  next unless result.in_experiment && !result.passthrough
134
139
 
135
- return get_feature_result(result.value, 'experiment', exp, result)
140
+ return get_feature_result(key.to_s, result.value, 'experiment', exp, result)
136
141
  end
137
142
 
138
143
  # Fallback
139
- get_feature_result(feature.default_value.nil? ? nil : feature.default_value, 'defaultValue', nil, nil)
144
+ get_feature_result(key.to_s, feature.default_value.nil? ? nil : feature.default_value, 'defaultValue', nil, nil)
140
145
  end
141
146
 
142
147
  def run(exp)
@@ -285,8 +290,19 @@ module Growthbook
285
290
  result
286
291
  end
287
292
 
288
- def get_feature_result(value, source, experiment, experiment_result)
289
- Growthbook::FeatureResult.new(value, source, experiment, experiment_result)
293
+ def get_feature_result(key, value, source, experiment, experiment_result)
294
+ res = Growthbook::FeatureResult.new(value, source, experiment, experiment_result)
295
+
296
+ track_feature_usage(key, res)
297
+
298
+ res
299
+ end
300
+
301
+ def track_feature_usage(key, feature_result)
302
+ return unless on_feature_usage.respond_to?(:on_feature_usage)
303
+ return if feature_result.source == 'override'
304
+
305
+ on_feature_usage.on_feature_usage(key, feature_result)
290
306
  end
291
307
 
292
308
  def get_feature(key)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Growthbook
4
+ # Extendable class that can be used as the feature usage callback
5
+ class FeatureUsageCallback
6
+ def on_feature_usage(_feature_key, _result); end
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growthbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GrowthBook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-16 00:00:00.000000000 Z
11
+ date: 2023-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -94,6 +94,7 @@ files:
94
94
  - lib/growthbook/feature_repository.rb
95
95
  - lib/growthbook/feature_result.rb
96
96
  - lib/growthbook/feature_rule.rb
97
+ - lib/growthbook/feature_usage_callback.rb
97
98
  - lib/growthbook/fnv.rb
98
99
  - lib/growthbook/inline_experiment.rb
99
100
  - lib/growthbook/inline_experiment_result.rb
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
121
122
  requirements: []
122
- rubygems_version: 3.1.2
123
+ rubygems_version: 3.4.10
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: GrowthBook SDK for Ruby