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
Bugfix: Allow breakdown by internally used prop keys for Growth plans (#3562)
RobertJoonasff2c3346d253
diff --git a/lib/plausible/props.ex b/lib/plausible/props.exindex 726da24fe8..dde886f647 100644--- a/lib/plausible/props.ex+++ b/lib/plausible/props.ex@@ -96,6 +96,14 @@ defmodule Plausible.Props do"""def internal_keys, do: @internal_keys+ def ensure_prop_key_accessible(prop_key, user) do+ if prop_key in @internal_keys do+ :ok+ else+ Plausible.Billing.Feature.Props.check_availability(user)+ end+ end+@spec suggest_keys_to_allow(Plausible.Site.t(), non_neg_integer()) :: [String.t()]@doc """Queries the events table to fetch the #{@max_props} most frequent prop keysdiff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.exindex db0dbc3c38..c419fbad74 100644--- a/lib/plausible_web/controllers/api/stats_controller.ex+++ b/lib/plausible_web/controllers/api/stats_controller.ex@@ -1185,8 +1185,9 @@ defmodule PlausibleWeb.Api.StatsController dodef custom_prop_values(conn, params) dosite = Plausible.Repo.preload(conn.assigns.site, :owner)+ prop_key = Map.fetch!(params, "prop_key")- case Plausible.Billing.Feature.Props.check_availability(site.owner) do+ case Plausible.Props.ensure_prop_key_accessible(prop_key, site.owner) do:ok ->props = breakdown_custom_prop_values(site, params)json(conn, props)diff --git a/test/plausible_web/controllers/api/stats_controller/custom_prop_breakdown_test.exs b/test/plausible_web/controllers/api/stats_controller/custom_prop_breakdown_test.exsindex 7f26685bd3..46c6b1c61a 100644--- a/test/plausible_web/controllers/api/stats_controller/custom_prop_breakdown_test.exs+++ b/test/plausible_web/controllers/api/stats_controller/custom_prop_breakdown_test.exs@@ -177,17 +177,6 @@ defmodule PlausibleWeb.Api.StatsController.CustomPropBreakdownTest do}]end-- test "errors when site owner is on a growth plan", %{conn: conn, site: site, user: user} do- insert(:growth_subscription, user: user)-- conn = get(conn, "/api/stats/#{site.domain}/custom-prop-values/prop?period=day")-- assert json_response(conn, 402) == %{- "error" =>- "Custom Properties is part of the Plausible Business plan. To get access to this feature, please upgrade your account."- }- endenddescribe "GET /api/stats/:domain/custom-prop-values/:prop_key - with goal filter" do@@ -1058,4 +1047,42 @@ defmodule PlausibleWeb.Api.StatsController.CustomPropBreakdownTest do]endend++ describe "GET /api/stats/:domain/custom-prop-values/:prop_key - for a Growth subscription" do+ setup [:create_user, :log_in, :create_new_site]++ setup %{user: user, site: site} do+ insert(:growth_subscription, user: user)++ populate_stats(site, [+ build(:pageview,+ "meta.key": ["url", "path", "author"],+ "meta.value": ["one", "two", "three"]+ )+ ])++ :ok+ end++ test "returns breakdown for internally used prop keys", %{conn: conn, site: site} do+ [%{"visitors" => 1, "name" => "one"}] =+ conn+ |> get("/api/stats/#{site.domain}/custom-prop-values/url?period=day")+ |> json_response(200)++ [%{"visitors" => 1, "name" => "two"}] =+ conn+ |> get("/api/stats/#{site.domain}/custom-prop-values/path?period=day")+ |> json_response(200)+ end++ test "returns 402 'upgrade required' for any other prop key", %{conn: conn, site: site} do+ conn = get(conn, "/api/stats/#{site.domain}/custom-prop-values/prop?period=day")++ assert json_response(conn, 402) == %{+ "error" =>+ "Custom Properties is part of the Plausible Business plan. To get access to this feature, please upgrade your account."+ }+ end+ endend