Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not persist invalid extra_info on ab_record_extra_info. #717

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/split/dashboard/views/_experiment.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
summary_texts = {}
extra_columns.each do |column|
extra_infos = experiment.alternatives.map(&:extra_info).select{|extra_info| extra_info && extra_info[column] }
if extra_infos[0][column].kind_of?(Numeric)

if extra_infos.length > 0 && extra_infos.all? { |extra_info| extra_info[column].kind_of?(Numeric) }
summary_texts[column] = extra_infos.inject(0){|sum, extra_info| sum += extra_info[column]}
else
summary_texts[column] = "N/A"
Expand Down
2 changes: 1 addition & 1 deletion lib/split/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def ab_finished(metric_descriptor, options = { reset: true })
end

def ab_record_extra_info(metric_descriptor, key, value = 1)
return if exclude_visitor? || Split.configuration.disabled?
return if exclude_visitor? || Split.configuration.disabled? || value.nil?
metric_descriptor, _ = normalize_metric(metric_descriptor)
experiments = Metric.possible_experiments(metric_descriptor)

Expand Down
36 changes: 36 additions & 0 deletions spec/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,42 @@ def should_finish_experiment(experiment_name, should_finish = true)
end
end


describe "ab_record_extra_info" do
context "for an experiment that the user participates in" do
before(:each) do
@experiment_name = "link_color"
@alternatives = ["blue", "red"]
@experiment = Split::ExperimentCatalog.find_or_create(@experiment_name, *@alternatives)
@alternative_name = ab_test(@experiment_name, *@alternatives)
end

it "records extra data for a given experiment" do
alternative = Split::Alternative.new(@alternative_name, "link_color")

ab_record_extra_info(@experiment_name, "some_data", 10)

expect(alternative.extra_info).to eql({ "some_data" => 10 })
end

it "records extra data for a given experiment" do
alternative = Split::Alternative.new(@alternative_name, "link_color")

ab_record_extra_info(@experiment_name, "some_data")

expect(alternative.extra_info).to eql({ "some_data" => 1 })
end

it "records extra data for a given experiment" do
alternative = Split::Alternative.new(@alternative_name, "link_color")

ab_record_extra_info(@experiment_name, "some_data", nil)

expect(alternative.extra_info).to eql({})
end
end
end

describe "conversions" do
it "should return a conversion rate for an alternative" do
alternative_name = ab_test("link_color", "blue", "red")
Expand Down