Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Ignore nil custom prop as well

Uku Taht02abbda06dd3
diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.ex
index 0790541ca2..732600baad 100644
--- a/lib/plausible_web/controllers/api/external_controller.ex
+++ b/lib/plausible_web/controllers/api/external_controller.ex
@@ -204,6 +204,7 @@ defmodule PlausibleWeb.Api.ExternalController do
{:ok, parsed_json} ->
Enum.filter(parsed_json, fn
{_, ""} -> false
+ {_, nil} -> false
{_, val} when is_list(val) -> false
{_, val} when is_map(val) -> false
_ -> true
diff --git a/test/plausible_web/controllers/api/external_controller_test.exs b/test/plausible_web/controllers/api/external_controller_test.exs
index 3079b76452..cfe92a6f86 100644
--- a/test/plausible_web/controllers/api/external_controller_test.exs
+++ b/test/plausible_web/controllers/api/external_controller_test.exs
@@ -558,6 +558,24 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
assert Map.get(event, :"meta.value") == ["true"]
end
+ test "ignores custom prop with nil value", %{conn: conn} do
+ params = %{
+ name: "Signup",
+ url: "http://gigride.live/",
+ domain: "custom-prop-test-nil.com",
+ props: Jason.encode!(%{foo: nil, other_key: true})
+ }
+
+ conn = post(conn, "/api/event", params)
+
+ assert conn.status == 202
+
+ event = get_event("custom-prop-test-nil.com")
+
+ assert Map.get(event, :"meta.key") == ["other_key"]
+ assert Map.get(event, :"meta.value") == ["true"]
+ end
+
test "ignores a malformed referrer URL", %{conn: conn} do
params = %{
name: "pageview",