From 8e84e9a1d943f3a2ed1e319768d82691d614ae2f Mon Sep 17 00:00:00 2001
From: Steve Hull
Date: Wed, 30 Nov 2016 13:14:31 -0800
Subject: [PATCH] Only count conversions for participants (or implicit
conversions)
This makes it so the "total conversion count" (as opposed to unique converted participant count) will only be tallied for participants (or implicit conversions), thus making it behave similarly to how unique participant conversions are tallied.
Coincidentally, also fixes active record conversion counting (previously it treated conversions as implicit even though the argument defaults to false).
---
lib/vanity/adapters/active_record_adapter.rb | 6 +++---
lib/vanity/adapters/mongodb_adapter.rb | 14 +++++++-------
lib/vanity/adapters/redis_adapter.rb | 3 +--
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/lib/vanity/adapters/active_record_adapter.rb b/lib/vanity/adapters/active_record_adapter.rb
index 0d341357..4d8b6f26 100644
--- a/lib/vanity/adapters/active_record_adapter.rb
+++ b/lib/vanity/adapters/active_record_adapter.rb
@@ -276,9 +276,9 @@ def ab_add_conversion(experiment, alternative, identity, options={})
implicit = !!options[:implicit]
metric_id = options[:metric_id] # unsupported for ActiveRecord
- VanityParticipant.retrieve(experiment, identity, false)
- VanityParticipant.retrieve(experiment, identity, implicit, :converted => alternative)
- VanityExperiment.retrieve(experiment).increment_conversion(alternative, count)
+ if VanityParticipant.retrieve(experiment, identity, implicit, :converted => alternative)
+ VanityExperiment.retrieve(experiment).increment_conversion(alternative, count)
+ end
end
# Returns the outcome of this experiment (if set), the index of a
diff --git a/lib/vanity/adapters/mongodb_adapter.rb b/lib/vanity/adapters/mongodb_adapter.rb
index d159ba31..7861806a 100644
--- a/lib/vanity/adapters/mongodb_adapter.rb
+++ b/lib/vanity/adapters/mongodb_adapter.rb
@@ -234,14 +234,14 @@ def ab_add_conversion(experiment, alternative, identity, options={})
},
:upsert=>true
)
- end
- @experiments.find(:_id=>experiment).find_one_and_replace(
- {
- "$inc"=>{ "conversions.#{alternative}"=>count }
- },
- :upsert=>true
- )
+ @experiments.find(:_id=>experiment).find_one_and_replace(
+ {
+ "$inc"=>{ "conversions.#{alternative}"=>count }
+ },
+ :upsert=>true
+ )
+ end
end
def ab_get_outcome(experiment)
diff --git a/lib/vanity/adapters/redis_adapter.rb b/lib/vanity/adapters/redis_adapter.rb
index e744200f..bd53c7ba 100644
--- a/lib/vanity/adapters/redis_adapter.rb
+++ b/lib/vanity/adapters/redis_adapter.rb
@@ -223,9 +223,8 @@ def ab_add_conversion(experiment_id, alternative, identity, options={})
if implicit || participating
@experiments.sadd "#{experiment_id}:alts:#{alternative}:metric:#{metric_id}:converted", identity
+ @experiments.incrby "#{experiment_id}:alts:#{alternative}:metric:#{metric_id}:conversions", count
end
-
- @experiments.incrby "#{experiment_id}:alts:#{alternative}:metric:#{metric_id}:conversions", count
end
end