Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Mark unreasonably high engagement_time values as 0-s (#5190)
Karl-Aksel Puulmannca4da167445d
diff --git a/lib/plausible/ingestion/request.ex b/lib/plausible/ingestion/request.exindex 5807f5adf2..4548ef5a3b 100644--- a/lib/plausible/ingestion/request.ex+++ b/lib/plausible/ingestion/request.ex@@ -352,7 +352,14 @@ defmodule Plausible.Ingestion.Request doendend- defp parse_engagement_time(et) when is_integer(et) and et >= 0, do: et+ # :KLUDGE: Old version of tracker script sent huge values for engagement time. Ignore+ # these while users might still have the old script cached.+ @too_large_engagement_time :timer.hours(30 * 24)++ defp parse_engagement_time(et)+ when is_integer(et) and et >= 0 and et < @too_large_engagement_time,+ do: et+defp parse_engagement_time(_), do: @missing_engagement_timeenddiff --git a/test/plausible_web/controllers/api/external_controller_test.exs b/test/plausible_web/controllers/api/external_controller_test.exsindex eba5946bf3..8874e9f5ed 100644--- a/test/plausible_web/controllers/api/external_controller_test.exs+++ b/test/plausible_web/controllers/api/external_controller_test.exs@@ -1339,6 +1339,26 @@ defmodule PlausibleWeb.Api.ExternalControllerTest doassert engagement.engagement_time == 0end+ test "ingests engagement_time as 0 when tracker is sending invalid high values", %{+ conn: conn,+ site: site+ } do+ post(conn, "/api/event", %{n: "pageview", u: "https://test.com", d: site.domain})++ post(conn, "/api/event", %{+ n: "engagement",+ u: "https://test.com",+ d: site.domain,+ sd: 50,+ e: 1_741_850_224_785+ })++ engagement = get_events(site) |> Enum.find(&(&1.name == "engagement"))++ assert engagement.engagement_time == 0+ assert engagement.scroll_depth == 50+ end+test "sd and e fields are ignored if name is not engagement", %{conn: conn, site: site} dopost(conn, "/api/event", %{n: "pageview",