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
Use correct headers
Uku Taht2b50c6cf2afa
diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.exindex 2a6affcb79..55c82a33de 100644--- a/lib/plausible_web/controllers/api/external_controller.ex+++ b/lib/plausible_web/controllers/api/external_controller.ex@@ -34,7 +34,7 @@ defmodule PlausibleWeb.Api.ExternalController dodefp create_event(conn, params) douri = params["url"] && URI.parse(params["url"])- country_code = Plug.Conn.get_req_header(conn, "cf-ipcountry") |> List.first+ country_code = Plug.Conn.get_req_header(conn, "x-country") |> List.firstuser_agent = Plug.Conn.get_req_header(conn, "user-agent") |> List.firstif UAInspector.bot?(user_agent) do{:ok, nil}@@ -80,7 +80,7 @@ defmodule PlausibleWeb.Api.ExternalController dodefp calculate_fingerprint(conn, params) douser_agent = List.first(Plug.Conn.get_req_header(conn, "user-agent")) || ""- ip_address = List.first(Plug.Conn.get_req_header(conn, "cf-connecting-ip")) || ""+ ip_address = List.first(Plug.Conn.get_req_header(conn, "x-bb-ip")) || "" # Netlify sets this header as the remote client IPdomain = strip_www(params["domain"]) || "":crypto.hash(:sha256, [user_agent, ip_address, domain])diff --git a/test/plausible_web/controllers/api/external_controller_test.exs b/test/plausible_web/controllers/api/external_controller_test.exsindex 5b313b8bb0..9c4f52a2b6 100644--- a/test/plausible_web/controllers/api/external_controller_test.exs+++ b/test/plausible_web/controllers/api/external_controller_test.exs@@ -24,7 +24,7 @@ defmodule PlausibleWeb.Api.ExternalControllerTest doconn = conn|> put_req_header("content-type", "text/plain")|> put_req_header("user-agent", @user_agent)- |> put_req_header("cf-ipcountry", @country_code)+ |> put_req_header("x-country", @country_code)|> post("/api/event", Jason.encode!(params))pageview = Repo.one(Plausible.Event)