lib/vanity/experiment/ab_test.rb in vanity-1.1.1 vs lib/vanity/experiment/ab_test.rb in vanity-1.2.0
- old
+ new
@@ -1,5 +1,7 @@
+require "digest/md5"
+
module Vanity
module Experiment
# One of several alternatives in an A/B test (see AbTest#alternatives).
class Alternative
@@ -398,15 +400,17 @@
end
# Called when tracking associated metric.
def track!(metric_id, timestamp, count, *args)
return unless active?
- identity = identity()
- return if redis[key("participants:#{identity}:show")]
- index = alternative_for(identity)
- redis.sadd key("alts:#{index}:converted"), identity if redis.sismember(key("alts:#{index}:participants"), identity)
- redis.incrby key("alts:#{index}:conversions"), count
- check_completion!
+ identity = identity() rescue nil
+ if identity
+ return if redis[key("participants:#{identity}:show")]
+ index = alternative_for(identity)
+ redis.sadd key("alts:#{index}:converted"), identity if redis.sismember(key("alts:#{index}:participants"), identity)
+ redis.incrby key("alts:#{index}:conversions"), count
+ check_completion!
+ end
end
# If you are not embarrassed by the first version of your product, you’ve
# launched too late.
# -- Reid Hoffman, founder of LinkedIn