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
Set root domain `(none)` for ingests without hostname (#4678)
hq1023e2041fb9f
diff --git a/lib/plausible/ingestion/event.ex b/lib/plausible/ingestion/event.exindex 94e13d04c2..f177ee9408 100644--- a/lib/plausible/ingestion/event.ex+++ b/lib/plausible/ingestion/event.ex@@ -541,7 +541,7 @@ defmodule Plausible.Ingestion.Event doendend- defp get_root_domain(nil), do: "(none)"+ defp get_root_domain("(none)"), do: "(none)"defp get_root_domain(hostname) docase :inet.parse_ipv4_address(String.to_charlist(hostname)) dodiff --git a/lib/plausible/ingestion/request.ex b/lib/plausible/ingestion/request.exindex fa2218611b..407b4c0325 100644--- a/lib/plausible/ingestion/request.ex+++ b/lib/plausible/ingestion/request.ex@@ -194,11 +194,11 @@ defmodule Plausible.Ingestion.Request dodefp put_hostname(changeset) dohost =case Changeset.get_field(changeset, :uri) do- %{host: host} when is_binary(host) and host != "" -> host+ %{host: host} when is_binary(host) and host != "" -> sanitize_hostname(host)_ -> "(none)"end- Changeset.put_change(changeset, :hostname, sanitize_hostname(host))+ Changeset.put_change(changeset, :hostname, host)end@max_props 30diff --git a/test/plausible/ingestion/event_test.exs b/test/plausible/ingestion/event_test.exsindex bc2a63696a..88fd25aab4 100644--- a/test/plausible/ingestion/event_test.exs+++ b/test/plausible/ingestion/event_test.exs@@ -397,4 +397,20 @@ defmodule Plausible.Ingestion.EventTest doassert {:ok, %{buffered: [event]}} = Event.build_and_buffer(request)assert event.clickhouse_event.hostname == "foo.netlify.app"end++ test "hostname is (none) when no hostname can be derived from the url" do+ site = insert(:site, domain: "foo.example.com")++ payload = %{+ domain: site.domain,+ name: "pageview",+ url: "/no/hostname"+ }++ conn = build_conn(:post, "/api/events", payload)+ assert {:ok, request} = Request.build(conn)++ assert {:ok, %{buffered: [event]}} = Event.build_and_buffer(request)+ assert event.clickhouse_event.hostname == "(none)"+ endend