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
Upgrade page fixes (#5248)
RobertJoonas8d98a75cd522
diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.exindex 3931bbe580..a8d4ebfc3c 100644--- a/lib/plausible/billing/billing.ex+++ b/lib/plausible/billing/billing.ex@@ -253,4 +253,12 @@ defmodule Plausible.Billing doteamend++ def dashboard_locked_notice_title(), do: "Dashboard locked"+ def active_grace_period_notice_title(), do: "You have outgrown your Plausible subscription tier"+ def subscription_cancelled_notice_title(), do: "Subscription cancelled"+ def subscription_past_due_notice_title(), do: "Payment failed"+ def subscription_paused_notice_title(), do: "Subscription paused"+ def upgrade_ineligible_notice_title(), do: "No sites owned"+ def pending_site_ownerships_notice_title(), do: "Pending ownership transfers"enddiff --git a/lib/plausible/billing/qouta/quota.ex b/lib/plausible/billing/qouta/quota.exindex 7ad415eb04..65e5d83e1a 100644--- a/lib/plausible/billing/qouta/quota.ex+++ b/lib/plausible/billing/qouta/quota.ex@@ -46,15 +46,17 @@ defmodule Plausible.Billing.Quota do`:custom` is returned. This means that this kind of usage should get ona custom plan.+ To avoid confusion, we do not recommend Growth tiers for customers that+ are already on a Business tier (even if their usage would fit Growth).+`nil` is returned if the usage is not eligible for upgrade."""- def suggest_tier(usage, highest_growth_plan, highest_business_plan) do- if eligible_for_upgrade?(usage) do- cond do- usage_fits_plan?(usage, highest_growth_plan) -> :growth- usage_fits_plan?(usage, highest_business_plan) -> :business- true -> :custom- end+ def suggest_tier(usage, highest_growth, highest_business, owned_tier) do+ cond do+ not eligible_for_upgrade?(usage) -> nil+ usage_fits_plan?(usage, highest_growth) and owned_tier != :business -> :growth+ usage_fits_plan?(usage, highest_business) -> :business+ true -> :customendenddiff --git a/lib/plausible_web/components/billing/notice.ex b/lib/plausible_web/components/billing/notice.exindex 4e4e8e1c04..a97fd0ee86 100644--- a/lib/plausible_web/components/billing/notice.ex+++ b/lib/plausible_web/components/billing/notice.ex@@ -11,7 +11,7 @@ defmodule PlausibleWeb.Components.Billing.Notice do~H"""<aside class="container"><.notice- title="You have outgrown your Plausible subscription tier"+ title={Plausible.Billing.active_grace_period_notice_title()}class="shadow-md dark:shadow-none">To keep your stats running smoothly, it’s time to upgrade your subscription to match your growing usage.@@ -28,7 +28,7 @@ defmodule PlausibleWeb.Components.Billing.Notice do~H"""<aside class="container"><.notice- title="You have outgrown your Plausible subscription tier"+ title={Plausible.Billing.active_grace_period_notice_title()}class="shadow-md dark:shadow-none">To keep your stats running smoothly, it’s time to upgrade your subscription to match your growing usage.@@ -47,7 +47,10 @@ defmodule PlausibleWeb.Components.Billing.Notice dodef dashboard_locked(assigns) do~H"""<aside class="container">- <.notice title="Dashboard locked" class="shadow-md dark:shadow-none">+ <.notice+ title={Plausible.Billing.dashboard_locked_notice_title()}+ class="shadow-md dark:shadow-none"+ >Since you’ve outgrown your current subscription tier, it’s time to upgrade to match your growing usage.<.linkhref={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)}@@ -123,7 +126,7 @@ defmodule PlausibleWeb.Components.Billing.Notice do<aside id="global-subscription-cancelled-notice" class="container"><.noticedismissable_id={Plausible.Billing.cancelled_subscription_notice_dismiss_id(@subscription.id)}- title="Subscription cancelled"+ title={Plausible.Billing.subscription_cancelled_notice_title()}theme={:red}class="shadow-md dark:shadow-none">@@ -143,7 +146,11 @@ defmodule PlausibleWeb.Components.Billing.Notice do~H"""<aside id={@container_id} class="hidden">- <.notice title="Subscription cancelled" theme={:red} class="shadow-md dark:shadow-none">+ <.notice+ title={Plausible.Billing.subscription_cancelled_notice_title()}+ theme={:red}+ class="shadow-md dark:shadow-none"+ ><.subscription_cancelled_notice_body subscription={@subscription} /></.notice></aside>@@ -170,7 +177,10 @@ defmodule PlausibleWeb.Components.Billing.Notice do) do~H"""<aside class={@class}>- <.notice title="Payment failed" class="shadow-md dark:shadow-none">+ <.notice+ title={Plausible.Billing.subscription_past_due_notice_title()}+ class="shadow-md dark:shadow-none"+ >There was a problem with your latest payment. Please update your payment information to keep using Plausible.<.linkhref={@subscription.update_url}class="whitespace-nowrap font-semibold"@@ -190,7 +200,11 @@ defmodule PlausibleWeb.Components.Billing.Notice do) do~H"""<aside class={@class}>- <.notice title="Subscription paused" theme={:red} class="shadow-md dark:shadow-none">+ <.notice+ title={Plausible.Billing.subscription_paused_notice_title()}+ theme={:red}+ class="shadow-md dark:shadow-none"+ >Your subscription is paused due to failed payments. Please provide valid payment details to keep using Plausible.<.linkhref={@subscription.update_url}class="whitespace-nowrap font-semibold"@@ -205,7 +219,11 @@ defmodule PlausibleWeb.Components.Billing.Notice dodef upgrade_ineligible(assigns) do~H"""<aside id="upgrade-eligible-notice" class="pb-6">- <.notice title="No sites owned" theme={:yellow} class="shadow-md dark:shadow-none">+ <.notice+ title={Plausible.Billing.upgrade_ineligible_notice_title()}+ theme={:yellow}+ class="shadow-md dark:shadow-none"+ >You cannot start a subscription as your account doesn't own any sites. The account that owns the sites is responsible for the billing. Please either<.styled_link href="https://plausible.io/docs/transfer-ownership">transfer the sites@@ -227,7 +245,10 @@ defmodule PlausibleWeb.Components.Billing.Notice do~H"""<aside class={@class}>- <.notice title="Pending ownership transfers" class="shadow-md dark:shadow-none mt-4">+ <.notice+ title={Plausible.Billing.pending_site_ownerships_notice_title()}+ class="shadow-md dark:shadow-none mt-4"+ >{@message} To exclude pending sites from your usage, please go to<.link href="https://plausible.io/sites" class="whitespace-nowrap font-semibold">plausible.io/sitesdiff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.exindex 2624cb74db..93805afaed 100644--- a/lib/plausible_web/controllers/billing_controller.ex+++ b/lib/plausible_web/controllers/billing_controller.ex@@ -23,6 +23,7 @@ defmodule PlausibleWeb.BillingController doredirect(conn, to: Routes.billing_path(conn, :upgrade_to_enterprise_plan))elserender(conn, "choose_plan.html",+ disable_global_notices?: true,skip_plausible_tracking: true,connect_live_socket: true)diff --git a/lib/plausible_web/live/choose_plan.ex b/lib/plausible_web/live/choose_plan.exindex 504b96f7d1..2a5af59e43 100644--- a/lib/plausible_web/live/choose_plan.ex+++ b/lib/plausible_web/live/choose_plan.ex@@ -42,10 +42,14 @@ defmodule PlausibleWeb.Live.ChoosePlan do|> assign_new(:available_plans, fn %{subscription: subscription} ->Plans.available_plans_for(subscription, with_prices: true, customer_ip: remote_ip)end)- |> assign_new(:recommended_tier, fn %{usage: usage, available_plans: available_plans} ->+ |> assign_new(:recommended_tier, fn %{+ usage: usage,+ available_plans: available_plans,+ owned_tier: owned_tier+ } ->highest_growth_plan = List.last(available_plans.growth)highest_business_plan = List.last(available_plans.business)- Quota.suggest_tier(usage, highest_growth_plan, highest_business_plan)+ Quota.suggest_tier(usage, highest_growth_plan, highest_business_plan, owned_tier)end)|> assign_new(:available_volumes, fn %{available_plans: available_plans} ->get_available_volumes(available_plans)diff --git a/lib/plausible_web/templates/layout/app.html.heex b/lib/plausible_web/templates/layout/app.html.heexindex ac040c3b43..e68627f084 100644--- a/lib/plausible_web/templates/layout/app.html.heex+++ b/lib/plausible_web/templates/layout/app.html.heex@@ -35,7 +35,10 @@><%= if !assigns[:embedded] do %>{render("_header.html", assigns)}- {render("_notice.html", assigns)}++ <%= if !assigns[:disable_global_notices?] do %>+ {render("_notice.html", assigns)}+ <% end %><% end %><main class="flex-1">diff --git a/test/plausible/billing/quota_test.exs b/test/plausible/billing/quota_test.exsindex 02f442b469..a2e709769a 100644--- a/test/plausible/billing/quota_test.exs+++ b/test/plausible/billing/quota_test.exs@@ -21,6 +21,9 @@ defmodule Plausible.Billing.QuotaTest do@v4_10m_growth_plan_id "857104"@v4_10m_business_plan_id "857112"+ @highest_growth_plan Plausible.Billing.Plans.find(@v4_10m_growth_plan_id)+ @highest_business_plan Plausible.Billing.Plans.find(@v4_10m_business_plan_id)+describe "site_limit/1" do@describetag :ee_only@@ -918,21 +921,57 @@ defmodule Plausible.Billing.QuotaTest do%{user: user, team: team}end- test "returns nil if the monthly pageview limit exceeds regular plans",+ test "returns nil if usage doesn't have any sites", %{team: team} do+ suggested_tier =+ team+ |> Plausible.Teams.Billing.quota_usage(with_features: true)+ |> Quota.suggest_tier(@highest_growth_plan, @highest_business_plan, nil)++ assert suggested_tier == nil+ end++ test "returns :custom if the monthly pageview limit exceeds regular plans",+ %{team: team} do+ suggested_tier =+ team+ |> Plausible.Teams.Billing.quota_usage(with_features: true)+ |> Map.merge(%{monthly_pageviews: %{last_30_days: %{total: 12_000_000}}, sites: 1})+ |> Quota.suggest_tier(@highest_growth_plan, @highest_business_plan, nil)++ assert suggested_tier == :custom+ end++ test "returns :growth if usage within growth limits",%{team: team} do- highest_growth_plan = Plausible.Billing.Plans.find(@v4_10m_growth_plan_id)- highest_business_plan = Plausible.Billing.Plans.find(@v4_10m_business_plan_id)+ suggested_tier =+ team+ |> Plausible.Teams.Billing.quota_usage(with_features: true)+ |> Map.put(:sites, 1)+ |> Quota.suggest_tier(@highest_growth_plan, @highest_business_plan, nil)- usage =+ assert suggested_tier == :growth+ end++ test "returns :business if usage within growth limits but already on a business plan",+ %{team: team} do+ suggested_tier =team- |> Plausible.Teams.Billing.quota_usage()- |> Map.replace!(:monthly_pageviews, %{last_30_days: %{total: 12_000_000}})+ |> Plausible.Teams.Billing.quota_usage(with_features: true)+ |> Map.put(:sites, 1)+ |> Quota.suggest_tier(@highest_growth_plan, @highest_business_plan, :business)++ assert suggested_tier == :business+ end+ test "returns :business if business features used",+ %{team: team} dosuggested_tier =- usage- |> Quota.suggest_tier(highest_growth_plan, highest_business_plan)+ team+ |> Plausible.Teams.Billing.quota_usage(with_features: true)+ |> Map.merge(%{sites: 1, features: [Plausible.Billing.Feature.Funnels]})+ |> Quota.suggest_tier(@highest_growth_plan, @highest_business_plan, nil)- assert suggested_tier == nil+ assert suggested_tier == :businessendendenddiff --git a/test/plausible_web/live/choose_plan_test.exs b/test/plausible_web/live/choose_plan_test.exsindex d3345afa13..b2a1a27921 100644--- a/test/plausible_web/live/choose_plan_test.exs+++ b/test/plausible_web/live/choose_plan_test.exs@@ -6,7 +6,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest doimport Phoenix.LiveViewTestimport Plausible.Test.Support.HTMLrequire Plausible.Billing.Subscription.Status- alias Plausible.{Repo, Billing.Subscription}+ alias Plausible.{Repo, Billing, Billing.Subscription}@v1_10k_yearly_plan_id "572810"@v1_50m_yearly_plan_id "650653"@@ -56,6 +56,11 @@ defmodule PlausibleWeb.Live.ChoosePlanTest doassert doc =~ "+ VAT if applicable"end+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end+test "displays plan benefits", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)@@ -371,7 +376,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest doendend- describe "for a user with a v4 growth subscription plan" do+ describe "for a user with an active v4 growth subscription plan" dosetup [:create_user, :create_site, :log_in, :subscribe_v4_growth]test "displays basic page content", %{conn: conn} do@@ -382,6 +387,11 @@ defmodule PlausibleWeb.Live.ChoosePlanTest dorefute doc =~ "What happens if I go over my page views limit?"end+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end+test "displays plan benefits", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)@@ -462,6 +472,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do{:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [Billing.pending_site_ownerships_notice_title()])assert doc =~ "Your account has been invited to become the owner of a site"assert text_of_element(doc, @growth_plan_tooltip) ==@@ -569,7 +580,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest doendend- describe "for a user with a v4 business subscription plan" do+ describe "for a user with an active v4 business subscription plan" dosetup [:create_user, :create_site, :log_in, :subscribe_v4_business]test "sets pageview slider according to last cycle usage", %{conn: conn} do@@ -577,7 +588,12 @@ defmodule PlausibleWeb.Live.ChoosePlanTest doassert text_of_element(doc, @slider_value) == "10k"end- test "highlights Business box as the 'Current' tier if it's suitable for their usage", %{+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end++ test "highlights Business box as the 'Current' tier", %{conn: conn,site: site} do@@ -594,20 +610,6 @@ defmodule PlausibleWeb.Live.ChoosePlanTest dorefute element_exists?(doc, @growth_highlight_pill)end- test "highlights Growth box as the 'Recommended' tier if it would accommodate their usage", %{- conn: conn- } do- {:ok, _lv, doc} = get_liveview(conn)-- class = class_of_element(doc, @growth_plan_box)-- assert class =~ "ring-2"- assert class =~ "ring-indigo-600"- assert text_of_element(doc, @growth_highlight_pill) == "Recommended"-- refute element_exists?(doc, @business_highlight_pill)- end-test "recommends Enterprise when site limit exceeds Business tier due to pending ownerships",%{conn: conn,@@ -747,6 +749,11 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do{:ok, context}end+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end+test "displays plan benefits", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)@@ -791,6 +798,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest dotest "renders failed payment notice and link to update billing details", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [Billing.subscription_past_due_notice_title()])assert doc =~ "There was a problem with your latest payment"assert doc =~ "https://update.billing.details"end@@ -824,6 +832,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest dotest "renders subscription paused notice and link to update billing details", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [Billing.subscription_paused_notice_title()])assert doc =~ "Your subscription is paused due to failed payments"assert doc =~ "https://update.billing.details"end@@ -852,9 +861,14 @@ defmodule PlausibleWeb.Live.ChoosePlanTest doendend- describe "for a user with a cancelled subscription" do+ describe "for a user with a cancelled, but still active subscription" dosetup [:create_user, :create_site, :log_in, :create_cancelled_subscription]+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end+test "checkout buttons are paddle buttons", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~ "Paddle.Checkout.open"@@ -863,7 +877,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do"Paddle.Checkout.open"end- test "currently owned tier is highlighted if stats are still unlocked", %{conn: conn} do+ test "currently owned tier is highlighted", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)assert text_of_element(doc, @growth_highlight_pill) == "Current"end@@ -872,9 +886,12 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do{:ok, _lv, doc} = get_liveview(conn)refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"end+ end- test "highlights recommended tier if subscription expired and no days are paid for anymore",- %{conn: conn, user: user} do+ describe "for a user with a cancelled and expired subscription" do+ setup [:create_user, :create_site, :log_in, :create_cancelled_subscription]++ setup %{user: user} douser|> team_of()|> Repo.preload(:subscription)@@ -882,6 +899,15 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do|> Subscription.changeset(%{next_bill_date: Timex.shift(Timex.now(), months: -2)})|> Repo.update!()+ :ok+ end++ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end++ test "highlights recommended tier", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)assert text_of_element(doc, @growth_highlight_pill) == "Recommended"refute text_of_element(doc, @business_highlight_pill) == "Recommended"@@ -891,6 +917,12 @@ defmodule PlausibleWeb.Live.ChoosePlanTest dodescribe "for a grandfathered user with a high volume plan" dosetup [:create_user, :create_site, :log_in]+ test "does not render any global notices", %{conn: conn, user: user} do+ create_subscription_for(user, paddle_plan_id: @v1_50m_yearly_plan_id)+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end+test "on a 50M v1 plan, Growth tiers are available at 20M, 50M, 50M+, but Business tiers are not",%{conn: conn, user: user} docreate_subscription_for(user, paddle_plan_id: @v1_50m_yearly_plan_id)@@ -947,6 +979,11 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do{:ok, context}end+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end+test "v1 20M and 50M Growth plans are not available",%{conn: conn} do{:ok, lv, _doc} = get_liveview(conn)@@ -993,16 +1030,26 @@ defmodule PlausibleWeb.Live.ChoosePlanTest dorefute enterprise_box =~ "10+ team members"refute enterprise_box =~ "Unlimited team members"end+ end- test "allows to upgrade without a trial_expiry_date when the user owns a site", %{- conn: conn,- user: user- } do+ describe "for a user without a trial_expiry_date (invited user) who owns a site (transferred)" do+ setup [:create_user, :create_site, :log_in]++ setup %{user: user} douser|> team_of()|> Ecto.Changeset.change(trial_expiry_date: nil)|> Repo.update!()+ :ok+ end++ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end++ test "allows to upgrade", %{conn: conn} do{:ok, lv, _doc} = get_liveview(conn)doc = set_slider(lv, "100k")@@ -1053,6 +1100,8 @@ defmodule PlausibleWeb.Live.ChoosePlanTest dotest "does not allow to subscribe and renders notice", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [Billing.upgrade_ineligible_notice_title()])+assert text_of_element(doc, "#upgrade-eligible-notice") =~ "You cannot start a subscription"assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"@@ -1062,23 +1111,50 @@ defmodule PlausibleWeb.Live.ChoosePlanTest dodescribe "for a user with no sites but pending ownership transfer" dosetup [:create_user, :log_in]- test "allows to subscribe and does not render the 'upgrade ineligible' notice", %{- conn: conn,- user: user- } do+ setup %{user: user} doold_owner = new_user()site = new_site(owner: old_owner)invite_transfer(site, user, inviter: old_owner)+ :ok+ end++ test "renders only the pending ownership transfer notice", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [Billing.pending_site_ownerships_notice_title()])+ end++ test "allows to subscribe", %{conn: conn} do{:ok, _lv, doc} = get_liveview(conn)- refute text_of_element(doc, "#upgrade-eligible-notice") =~ "You cannot start a subscription"refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"assert text_of_element(doc, @growth_plan_box) =~ "Recommended"endend+ # Checks the given HTML document for the presence of all possible billing+ # notices. For those expected, we assert that only one is present. Others+ # should not appear in the document.+ defp check_notice_titles(doc, expected) do+ [+ Billing.dashboard_locked_notice_title(),+ Billing.active_grace_period_notice_title(),+ Billing.subscription_cancelled_notice_title(),+ Billing.subscription_past_due_notice_title(),+ Billing.subscription_paused_notice_title(),+ Billing.upgrade_ineligible_notice_title(),+ Billing.pending_site_ownerships_notice_title()+ ]+ |> Enum.each(fn title ->+ if title in expected do+ assert length(String.split(doc, title)) == 2+ else+ refute doc =~ title+ end+ end)+ end+defp subscribe_v4_growth(%{user: user}) docreate_subscription_for(user, paddle_plan_id: @v4_growth_200k_yearly_plan_id)end