Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Suggest enterprise plan when usage is greater than 10M pageviews (#2345)

Vinicius Brasilc9945e09cf0b
diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex
index 5454e86230..0eabbc867b 100644
--- a/lib/plausible/billing/plans.ex
+++ b/lib/plausible/billing/plans.ex
@@ -126,7 +126,7 @@ defmodule Plausible.Billing.Plans do
)
end
- @enterprise_level_usage 20_000_000
+ @enterprise_level_usage 10_000_000
@spec suggested_plan(Plausible.Auth.User.t(), non_neg_integer()) :: plan()
def suggested_plan(user, usage_during_cycle) do
cond do
diff --git a/test/workers/check_usage_test.exs b/test/workers/check_usage_test.exs
index a35e7e7bc0..c03843f3e6 100644
--- a/test/workers/check_usage_test.exs
+++ b/test/workers/check_usage_test.exs
@@ -97,6 +97,30 @@ defmodule Plausible.Workers.CheckUsageTest do
assert Repo.reload(user).grace_period.end_date == Timex.shift(Timex.today(), days: 7)
end
+ test "sends an email suggesting enterprise plan when usage is greater than 10M ", %{
+ user: user
+ } do
+ billing_stub =
+ Plausible.Billing
+ |> stub(:last_two_billing_months_usage, fn _user -> {11_000_000, 11_000_000} end)
+ |> stub(:last_two_billing_cycles, fn _user ->
+ {Date.range(Timex.today(), Timex.today()), Date.range(Timex.today(), Timex.today())}
+ end)
+
+ insert(:subscription,
+ user: user,
+ paddle_plan_id: @paddle_id_10k,
+ last_bill_date: Timex.shift(Timex.today(), days: -1)
+ )
+
+ CheckUsage.perform(nil, billing_stub)
+
+ assert_delivered_email_matches(%{html_body: html_body})
+
+ assert html_body =~
+ "This is more than our standard plans, so please reply back to this email to get a quote for your volume."
+ end
+
test "skips checking users who already have a grace period", %{user: user} do
user |> Plausible.Auth.GracePeriod.start_changeset(12_000) |> Repo.update()