Turn Revenue Goals into Custom Events if the plan doesn't support them (#3768)

* Turn Revenue Goals into Custom Events if the plan runs out

* Tag test with full_build
pull/3779/head
hq1 3 years ago committed by GitHub
parent 499be9f0b3
commit f5129f1b0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1144,7 +1144,8 @@ defmodule PlausibleWeb.Api.StatsController do
metrics =
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_metrics
else
[:visitors, :events]

@ -61,6 +61,7 @@ defmodule PlausibleWeb.Live.GoalSettings do
goals={@displayed_goals}
domain={@domain}
filter_text={@filter_text}
site={@site}
/>
</div>
"""

@ -10,8 +10,12 @@ defmodule PlausibleWeb.Live.GoalSettings.List do
attr(: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>

@ -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_only
test "returns revenue metrics as nil for non-revenue goals", %{
conn: conn,

@ -25,6 +25,24 @@ defmodule PlausibleWeb.Live.GoalSettingsTest do
assert 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")

Loading…
Cancel
Save