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
Fetch config options at runtime
Uku Taht390a4577b5b7
diff --git a/lib/mix/tasks/hydrate_clickhouse.ex b/lib/mix/tasks/hydrate_clickhouse.exindex 0a0f03c294..c072592695 100644--- a/lib/mix/tasks/hydrate_clickhouse.ex+++ b/lib/mix/tasks/hydrate_clickhouse.ex@@ -2,7 +2,6 @@ defmodule Mix.Tasks.HydrateClickhouse douse Mix.Taskuse Plausible.Reporequire Logger- @hash_key Keyword.fetch!(Application.get_env(:plausible, PlausibleWeb.Endpoint), :secret_key_base) |> binary_part(0, 16)# coveralls-ignore-start@@ -101,6 +100,7 @@ defmodule Mix.Tasks.HydrateClickhouse doenddef hydrate_events(repo, _args \\ []) do+ hash_key = Keyword.fetch!(Application.get_env(:plausible, PlausibleWeb.Endpoint), :secret_key_base) |> binary_part(0, 16)end_time = ~N[2020-05-21 10:46:51]total = Repo.aggregate(from(e in Plausible.Event, where: e.timestamp < ^end_time), :count, :id)@@ -114,7 +114,7 @@ defmodule Mix.Tasks.HydrateClickhouse do{session_cache, sessions, events} = Enum.reduce(events, {session_cache, [], []}, fn event, {session_cache, sessions, new_events} ->found_session = session_cache[event.fingerprint]active = is_active?(found_session, event)- user_id = SipHash.hash!(@hash_key, event.fingerprint)+ user_id = SipHash.hash!(hash_key, event.fingerprint)clickhouse_event = struct(Plausible.ClickhouseEvent, Map.from_struct(event) |> Map.put(:user_id, user_id))cond dodiff --git a/lib/plausible/billing/paddle_api.ex b/lib/plausible/billing/paddle_api.exindex 941c3f16e3..38c39a38eb 100644--- a/lib/plausible/billing/paddle_api.ex+++ b/lib/plausible/billing/paddle_api.ex@@ -2,17 +2,17 @@ defmodule Plausible.Billing.PaddleApi do@update_preview_endpoint "https://vendors.paddle.com/api/2.0/subscription/preview_update"@update_endpoint "https://vendors.paddle.com/api/2.0/subscription/users/update"@get_endpoint "https://vendors.paddle.com/api/2.0/subscription/users"- @vendor_id Keyword.fetch!(Application.get_env(:plausible, :paddle), :vendor_id)- @vendor_auth_code Keyword.fetch!(Application.get_env(:plausible, :paddle), :vendor_auth_code)@headers [{"Content-type", "application/json"},{"Accept", "application/json"}]def update_subscription_preview(paddle_subscription_id, new_plan_id) do+ config = get_config()+params = %{- vendor_id: @vendor_id,- vendor_auth_code: @vendor_auth_code,+ vendor_id: config[:vendor_id],+ vendor_auth_code: config[:vendor_auth_code],subscription_id: paddle_subscription_id,plan_id: new_plan_id,prorate: true,@@ -32,9 +32,11 @@ defmodule Plausible.Billing.PaddleApi doenddef update_subscription(paddle_subscription_id, params) do+ config = get_config()+params = Map.merge(params, %{- vendor_id: @vendor_id,- vendor_auth_code: @vendor_auth_code,+ vendor_id: config[:vendor_id],+ vendor_auth_code: config[:vendor_auth_code],subscription_id: paddle_subscription_id,quantity: 1})@@ -50,9 +52,10 @@ defmodule Plausible.Billing.PaddleApi doenddef get_subscription(paddle_subscription_id) do+ config = get_config()params = %{- vendor_id: @vendor_id,- vendor_auth_code: @vendor_auth_code,+ vendor_id: config[:vendor_id],+ vendor_auth_code: config[:vendor_auth_code],subscription_id: paddle_subscription_id}@@ -66,4 +69,8 @@ defmodule Plausible.Billing.PaddleApi do{:error, body["error"]}endend++ defp get_config() do+ Application.get_env(:plausible, :paddle)+ endenddiff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.exindex b78dc1c4f9..b71d4a9208 100644--- a/lib/plausible_web/controllers/api/external_controller.ex+++ b/lib/plausible_web/controllers/api/external_controller.ex@@ -1,7 +1,6 @@defmodule PlausibleWeb.Api.ExternalController douse PlausibleWeb, :controllerrequire Logger- @hash_key Keyword.fetch!(Application.get_env(:plausible, PlausibleWeb.Endpoint), :secret_key_base) |> binary_part(0, 16)def event(conn, _params) doparams = parse_body(conn)@@ -98,11 +97,12 @@ defmodule PlausibleWeb.Api.ExternalController doenddefp generate_user_id(conn, params) do+ hash_key = Keyword.fetch!(Application.get_env(:plausible, PlausibleWeb.Endpoint), :secret_key_base) |> binary_part(0, 16)user_agent = List.first(Plug.Conn.get_req_header(conn, "user-agent")) || ""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"]) || ""- SipHash.hash!(@hash_key, user_agent <> ip_address <> domain)+ SipHash.hash!(hash_key, user_agent <> ip_address <> domain)enddefp calculate_screen_size(nil) , do: nil