Skip to content

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

Use correct headers

Uku Taht2b50c6cf2afa
diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.ex
index 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 do
defp create_event(conn, params) do
uri = 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.first
user_agent = Plug.Conn.get_req_header(conn, "user-agent") |> List.first
if UAInspector.bot?(user_agent) do
{:ok, nil}
@@ -80,7 +80,7 @@ defmodule PlausibleWeb.Api.ExternalController do
defp calculate_fingerprint(conn, params) do
user_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 IP
domain = 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.exs
index 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 do
conn = 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)