Remove raw fingerprint

This commit is contained in:
Uku Taht 2020-02-11 11:02:44 +02:00
parent 759c21fff0
commit 7bb5d98956
3 changed files with 14 additions and 12 deletions

View File

@ -10,7 +10,6 @@ defmodule Plausible.Event do
field :new_visitor, :boolean
field :user_id, :binary_id
field :fingerprint, :string
field :raw_fingerprint, :string
field :referrer, :string
field :referrer_source, :string
@ -24,7 +23,7 @@ defmodule Plausible.Event do
def changeset(pageview, attrs) do
pageview
|> cast(attrs, [:name, :domain, :hostname, :pathname, :referrer, :new_visitor, :user_id, :fingerprint, :raw_fingerprint, :operating_system, :browser, :referrer_source, :country_code, :screen_size])
|> cast(attrs, [:name, :domain, :hostname, :pathname, :referrer, :new_visitor, :user_id, :fingerprint, :operating_system, :browser, :referrer_source, :country_code, :screen_size])
|> validate_required([:name, :domain, :hostname, :pathname, :new_visitor, :user_id, :fingerprint])
end
end

View File

@ -56,7 +56,6 @@ 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),
@ -70,18 +69,13 @@ defmodule PlausibleWeb.Api.ExternalController do
end
defp calculate_fingerprint(conn, params) do
fingerprint = calculate_raw_fingerprint(conn, params)
: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 = List.first(Plug.Conn.get_req_header(conn, "cf-connecting-ip")) || ""
domain = strip_www(params["domain"]) || ""
Enum.join([user_agent, ip_address, domain], ":")
:crypto.hash(:sha256, [user_agent, ip_address, domain])
|> Base.encode16
|> String.downcase
end
defp calculate_screen_size(nil) , do: nil

View File

@ -0,0 +1,9 @@
defmodule Plausible.Repo.Migrations.RemoveRawFingerprint do
use Ecto.Migration
def change do
alter table(:events) do
remove :raw_fingerprint
end
end
end