Skip to content

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

Drop events when classified as datacenter IP (#3647)

Cenk Kücük147597cd98a1
diff --git a/lib/plausible/ingestion/event.ex b/lib/plausible/ingestion/event.ex
index 950579acf3..881353b436 100644
--- a/lib/plausible/ingestion/event.ex
+++ b/lib/plausible/ingestion/event.ex
@@ -144,8 +144,7 @@ defmodule Plausible.Ingestion.Event do
defp put_ip_classification(%__MODULE__{} = event) do
case event.request.ip_classification do
"dc_ip" ->
- emit_telemetry_dropped(event, :dc_ip)
- event
+ drop(event, :dc_ip)
_any ->
event
diff --git a/test/plausible/ingestion/event_test.exs b/test/plausible/ingestion/event_test.exs
index e4a6854b3d..3db601961c 100644
--- a/test/plausible/ingestion/event_test.exs
+++ b/test/plausible/ingestion/event_test.exs
@@ -100,6 +100,23 @@ defmodule Plausible.Ingestion.EventTest do
assert dropped.drop_reason == :throttle
end
+ test "event pipeline drops a request when header x-plausible-ip-type is dc_ip" do
+ site = insert(:site)
+
+ payload = %{
+ name: "pageview",
+ url: "http://dummy.site",
+ domain: site.domain
+ }
+
+ conn = build_conn(:post, "/api/events", payload)
+ conn = Plug.Conn.put_req_header(conn, "x-plausible-ip-type", "dc_ip")
+ assert {:ok, request} = Request.build(conn)
+
+ assert {:ok, %{buffered: [], dropped: [dropped]}} = Event.build_and_buffer(request)
+ assert dropped.drop_reason == :dc_ip
+ end
+
test "event pipeline drops events for site with accept_trafic_until in the past" do
yesterday = NaiveDateTime.add(NaiveDateTime.utc_now(), -1, :day)
site = insert(:site, ingest_rate_limit_threshold: 1, accept_traffic_until: yesterday)