lib/field_test/helpers.rb in field_test-0.1.2 vs lib/field_test/helpers.rb in field_test-0.2.0
- old
+ new
@@ -11,10 +11,13 @@
end
if FieldTest.exclude_bots?
options[:exclude] = Browser.new(request.user_agent).bot?
end
+
+ options[:ip] = request.remote_ip
+ options[:user_agent] = request.user_agent
end
# cache results for request
@field_test_cache ||= {}
@field_test_cache[experiment] ||= exp.variant(participants, options)
@@ -52,16 +55,22 @@
# controllers and views
if try(:request)
# use cookie
cookie_key = "field_test"
+
token = cookies[cookie_key]
+ token = token.gsub(/[^a-z0-9\-]/i, "") if token
+
if participants.empty? && !token
token = SecureRandom.uuid
cookies[cookie_key] = {value: token, expires: 30.days.from_now}
end
if token
- participants << "cookie:#{token.gsub(/[^a-z0-9\-]/i, "")}"
+ participants << token
+
+ # backwards compatibility
+ participants << "cookie:#{token}"
end
end
# mailers
to = try(:message).try(:to).try(:first)