diff --git a/lib/ahoy/tracker.rb b/lib/ahoy/tracker.rb index 3fedfaec..e63115f1 100644 --- a/lib/ahoy/tracker.rb +++ b/lib/ahoy/tracker.rb @@ -241,7 +241,9 @@ def existing_visitor_token end def visitor_anonymity_set - @visitor_anonymity_set ||= Digest::UUID.uuid_v5(UUID_NAMESPACE, ["visitor", Ahoy.mask_ip(request.remote_ip), request.user_agent].join("/")) + @visitor_anonymity_set ||= Digest::UUID.uuid_v5( + UUID_NAMESPACE, ["visitor", Ahoy.mask_ip(request.remote_ip), request.user_agent].join("/") + ) if request end def visit_cookie diff --git a/test/tracker_test.rb b/test/tracker_test.rb index 9e7b8947..25c1166f 100644 --- a/test/tracker_test.rb +++ b/test/tracker_test.rb @@ -11,6 +11,21 @@ def test_no_request assert_nil event.user_id end + def test_no_request_with_cookies_none + old_cookies = Ahoy.cookies + Ahoy.cookies = :none + + ahoy = Ahoy::Tracker.new + ahoy.track("Some event", some_prop: true) + + event = Ahoy::Event.last + assert_equal "Some event", event.name + assert_equal({"some_prop" => true}, event.properties) + assert_nil event.user_id + ensure + Ahoy.cookies = old_cookies + end + def test_no_cookies request = ActionDispatch::TestRequest.create