|
|
|
|
@ -56,6 +56,7 @@ defmodule PlausibleWeb.Api.ExternalController do
|
|
|
|
|
country_code: country_code,
|
|
|
|
|
user_id: params["uid"],
|
|
|
|
|
fingerprint: calculate_fingerprint(conn, params),
|
|
|
|
|
raw_fingerprint: calculate_raw_fingerprint(conn, params),
|
|
|
|
|
operating_system: ua && os_name(ua),
|
|
|
|
|
browser: ua && browser_name(ua),
|
|
|
|
|
referrer_source: ref && referrer_source(uri, ref),
|
|
|
|
|
@ -69,15 +70,20 @@ defmodule PlausibleWeb.Api.ExternalController do
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp calculate_fingerprint(conn, params) do
|
|
|
|
|
user_agent = List.first(Plug.Conn.get_req_header(conn, "user-agent")) || ""
|
|
|
|
|
ip_address = to_string(:inet_parse.ntoa(conn.remote_ip)) || ""
|
|
|
|
|
domain = strip_www(params["domain"]) || ""
|
|
|
|
|
fingerprint = calculate_raw_fingerprint(conn, params)
|
|
|
|
|
|
|
|
|
|
:crypto.hash(:sha256, [user_agent, ip_address, domain])
|
|
|
|
|
:crypto.hash(:sha256, fingerprint)
|
|
|
|
|
|> Base.encode16
|
|
|
|
|
|> String.downcase
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp calculate_raw_fingerprint(conn, params) do
|
|
|
|
|
user_agent = List.first(Plug.Conn.get_req_header(conn, "user-agent")) || ""
|
|
|
|
|
ip_address = to_string(:inet_parse.ntoa(conn.remote_ip)) || ""
|
|
|
|
|
domain = strip_www(params["domain"]) || ""
|
|
|
|
|
Enum.join([user_agent, ip_address, domain], ":")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp calculate_screen_size(nil) , do: nil
|
|
|
|
|
defp calculate_screen_size(width) when width < 576, do: "Mobile"
|
|
|
|
|
defp calculate_screen_size(width) when width < 992, do: "Tablet"
|
|
|
|
|
|