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
Turn Revenue Goals into Custom Events if the plan doesn't support them (#3768)
hq1f5129f1b0d50
diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.exindex 2632ef625b..dda5eb3a05 100644--- a/lib/plausible_web/controllers/api/stats_controller.ex+++ b/lib/plausible_web/controllers/api/stats_controller.ex@@ -1144,7 +1144,8 @@ defmodule PlausibleWeb.Api.StatsController dometrics =on_full_build do- if Enum.any?(site.goals, &Plausible.Goal.Revenue.revenue?/1) do+ if Enum.any?(site.goals, &Plausible.Goal.Revenue.revenue?/1) and+ Plausible.Billing.Feature.RevenueGoals.enabled?(site) do[:visitors, :events] ++ @revenue_metricselse[:visitors, :events]diff --git a/lib/plausible_web/live/goal_settings.ex b/lib/plausible_web/live/goal_settings.exindex 2b154a83f6..32d11eca27 100644--- a/lib/plausible_web/live/goal_settings.ex+++ b/lib/plausible_web/live/goal_settings.ex@@ -61,6 +61,7 @@ defmodule PlausibleWeb.Live.GoalSettings dogoals={@displayed_goals}domain={@domain}filter_text={@filter_text}+ site={@site}/></div>"""diff --git a/lib/plausible_web/live/goal_settings/list.ex b/lib/plausible_web/live/goal_settings/list.exindex 6dd47a0fb0..839a5d6c4b 100644--- a/lib/plausible_web/live/goal_settings/list.ex+++ b/lib/plausible_web/live/goal_settings/list.ex@@ -10,8 +10,12 @@ defmodule PlausibleWeb.Live.GoalSettings.List doattr(:goals, :list, required: true)attr(:domain, :string, required: true)attr(:filter_text, :string)+ attr(:site, Plausible.Site, required: true)def render(assigns) do+ revenue_goals_enabled? = Plausible.Billing.Feature.RevenueGoals.enabled?(assigns.site)+ assigns = assign(assigns, :revenue_goals_enabled?, revenue_goals_enabled?)+~H"""<div><div class="border-t border-gray-200 pt-4 sm:flex sm:items-center sm:justify-between">@@ -56,14 +60,23 @@ defmodule PlausibleWeb.Live.GoalSettings.List do<span class="text-sm font-medium text-gray-900 dark:text-gray-100 w-3/4"><div class="flex"><span class="truncate">- <%= goal %>- <br />+ <%= if not @revenue_goals_enabled? && goal.currency do %>+ <div class="text-gray-600 flex items-center">+ <Heroicons.lock_closed class="w-4 h-4 mr-1 inline" />+ <span><%= goal %></span>+ </div>+ <% else %>+ <%= goal %>+ <% end %><span class="text-sm text-gray-400 block mt-1 font-normal"><span :if={goal.page_path}>Pageview</span><span :if={goal.event_name && !goal.currency}>Custom Event</span>- <span :if={goal.currency}>+ <span :if={goal.currency && @revenue_goals_enabled?}>Revenue Goal</span>+ <span :if={goal.currency && not @revenue_goals_enabled?} class="text-red-600">+ Unlock Revenue Goals by upgrading to a business plan+ </span><span :if={not Enum.empty?(goal.funnels)}> - belongs to funnel(s)</span></span></span>diff --git a/test/plausible_web/controllers/api/stats_controller/conversions_test.exs b/test/plausible_web/controllers/api/stats_controller/conversions_test.exsindex c76841ceff..a454f59f69 100644--- a/test/plausible_web/controllers/api/stats_controller/conversions_test.exs+++ b/test/plausible_web/controllers/api/stats_controller/conversions_test.exs@@ -260,6 +260,50 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do]end+ @tag :full_build_only+ test "returns revenue goals as custom events if the plan doesn't cover the feature", %{+ conn: conn,+ site: site,+ user: user+ } do+ user+ |> Plausible.Auth.User.end_trial()+ |> Plausible.Repo.update!()++ populate_stats(site, [+ build(:event,+ name: "Payment",+ revenue_reporting_amount: Decimal.new("200100300.123"),+ revenue_reporting_currency: "USD"+ ),+ build(:event,+ name: "Payment",+ revenue_reporting_amount: Decimal.new("300100400.123"),+ revenue_reporting_currency: "USD"+ ),+ build(:event,+ name: "Payment",+ revenue_reporting_amount: Decimal.new("0"),+ revenue_reporting_currency: "USD"+ ),+ build(:event, name: "Payment", revenue_reporting_amount: nil),+ build(:event, name: "Payment", revenue_reporting_amount: nil)+ ])++ insert(:goal, %{site: site, event_name: "Payment", currency: :EUR})++ conn = get(conn, "/api/stats/#{site.domain}/conversions?period=day")++ assert json_response(conn, 200) == [+ %{+ "name" => "Payment",+ "visitors" => 5,+ "events" => 5,+ "conversion_rate" => 100.0+ }+ ]+ end+@tag :full_build_onlytest "returns revenue metrics as nil for non-revenue goals", %{conn: conn,diff --git a/test/plausible_web/live/goal_settings_test.exs b/test/plausible_web/live/goal_settings_test.exsindex 99e51b1ed0..b098da83ab 100644--- a/test/plausible_web/live/goal_settings_test.exs+++ b/test/plausible_web/live/goal_settings_test.exs@@ -25,6 +25,24 @@ defmodule PlausibleWeb.Live.GoalSettingsTest doassert resp =~ "Revenue Goal"end+ @tag :full_build_only+ test "lists Revenue Goals with feature availability annotation if the plan does not cover them",+ %{conn: conn, user: user, site: site} do+ {:ok, [_, _, g3]} = setup_goals(site)++ user+ |> Plausible.Auth.User.end_trial()+ |> Plausible.Repo.update!()++ conn = get(conn, "/#{site.domain}/settings/goals")++ resp = html_response(conn, 200)++ assert g3.currency+ assert resp =~ to_string(g3)+ assert resp =~ "Unlock Revenue Goals by upgrading to a business plan"+ end+test "lists goals with delete actions", %{conn: conn, site: site} do{:ok, goals} = setup_goals(site)conn = get(conn, "/#{site.domain}/settings/goals")