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
Display private preview for non business accounts (#3502)
Vini Brasil2578391be273
diff --git a/lib/plausible_web/components/billing.ex b/lib/plausible_web/components/billing.exindex f980038b47..cdb3db5726 100644--- a/lib/plausible_web/components/billing.ex+++ b/lib/plausible_web/components/billing.ex@@ -18,47 +18,50 @@ defmodule PlausibleWeb.Components.Billing dodef premium_feature_notice(assigns) dobillable_user = Plausible.Users.with_subscription(assigns.billable_user)plan = Plans.get_regular_plan(billable_user.subscription, only_non_expired: true)- growth? = plan && plan.kind == :growth+ business? = plan && plan.kind == :businessprivate_preview? = FunWithFlags.enabled?(:premium_features_private_preview)- display_upgrade_link? = assigns.current_user.id == assigns.billable_user.idhas_access? = assigns.feature_mod.check_availability(assigns.billable_user) == :ok- message =- cond do- Plausible.Billing.on_trial?(assigns.billable_user) ->- "#{assigns.feature_mod.display_name()} is part of the Plausible Business plan. You can access it during your trial, but you'll need to subscribe to the Business plan to retain access after the trial ends."-- private_preview? && display_upgrade_link? && growth? ->- ~H"""- Business plans are now live! The private preview of <%= @feature_mod.display_name() %> for Plausible Growth plans ends <%= private_preview_days_remaining() %>. If you wish to continue using this feature, please- <.link class="underline" href={Routes.billing_path(PlausibleWeb.Endpoint, :upgrade)}>- upgrade your subscription- </.link> to the Plausible Business plan.- """-- not has_access? && display_upgrade_link? ->- ~H"""- <%= @feature_mod.display_name() %> is part of the Plausible Business plan. To get access to it, please- <.link class="underline inline-block" href={Plausible.Billing.upgrade_route_for(@current_user)}>- upgrade your subscription- </.link> to the Business plan.- """-- not has_access? && not display_upgrade_link? ->- "#{assigns.feature_mod.display_name()} is part of the Plausible Business plan. To get access to it, please reach out to the site owner to upgrade your subscription to the Business plan."+ cond do+ Plausible.Billing.on_trial?(assigns.billable_user) ->+ ~H"""+ <.notice class="rounded-t-md rounded-b-none" size={@size} {@rest}>+ <%= @feature_mod.display_name() %> is part of the Plausible Business plan. You can access it during your trial, but you'll need to subscribe to the Business plan to retain access after the trial ends."+ </.notice>+ """++ private_preview? && !business? ->+ ~H"""+ <.notice class="rounded-t-md rounded-b-none" size={@size} {@rest}>+ Business plans are now live! The private preview of <%= @feature_mod.display_name() %> ends <%= private_preview_days_remaining() %>. If you wish to continue using this feature,+ <.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />.+ </.notice>+ """++ not has_access? ->+ ~H"""+ <.notice class="rounded-t-md rounded-b-none" size={@size} {@rest}>+ This account does not have access to <%= assigns.feature_mod.display_name() %>. To get access to this feature,+ <.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />.+ </.notice>+ """++ true ->+ ~H""+ end+ end- true ->- nil- end+ defp private_preview_days_remaining do+ private_preview_ends_at = Timex.shift(Plausible.Billing.Plans.business_tier_launch(), days: 7)- assigns = assign(assigns, :message, message)+ days_remaining = Timex.diff(private_preview_ends_at, NaiveDateTime.utc_now(), :day)- ~H"""- <.notice :if={@message} class="rounded-t-md rounded-b-none" size={@size} {@rest}>- <%= @message %>- </.notice>- """+ cond do+ days_remaining <= 0 -> "today"+ days_remaining == 1 -> "tomorrow"+ true -> "in #{days_remaining} days"+ endendattr(:billable_user, Plausible.Auth.User, required: true)@@ -77,43 +80,37 @@ defmodule PlausibleWeb.Components.Billing dotrial? = Plausible.Billing.on_trial?(assigns.billable_user)growth? = plan && plan.kind == :growth- display_upgrade_link? = assigns.current_user.id == assigns.billable_user.id-- message =- cond do- !display_upgrade_link? ->- "This account is limited to #{assigns.limit} #{assigns.resource}. To increase this limit, please reach out to the site owner to upgrade their subscription"-- growth? || trial? ->- ~H"""- Your account is limited to <%= @limit %> <%= @resource %>. To increase this limit, please- <.link class="underline inline-block" href={Plausible.Billing.upgrade_route_for(@current_user)}>- upgrade your subscription- </.link> to the Business plan.- """-- true ->- "Your account is limited to #{assigns.limit} #{assigns.resource}. To increase this limit, please contact [email protected] about the Enterprise plan"- end-- assigns = assign(assigns, :message, message)-- ~H"""- <.notice :if={@message} {@rest}>- <%= @message %>- </.notice>- """+ if growth? || trial? do+ ~H"""+ <.notice {@rest}>+ This account is limited to <%= @limit %> <%= @resource %>. To increase this limit,+ <.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />.+ </.notice>+ """+ else+ ~H"""+ <.notice {@rest}>+ Your account is limited to <%= @limit %> <%= @resource %>. To increase this limit, please contact [email protected] about the Enterprise plan+ </.notice>+ """+ endend- defp private_preview_days_remaining do- private_preview_ends_at = Timex.shift(Plausible.Billing.Plans.business_tier_launch(), days: 7)-- days_remaining = Timex.diff(private_preview_ends_at, NaiveDateTime.utc_now(), :day)-- if days_remaining <= 0 do- "today"+ attr(:current_user, :map)+ attr(:billable_user, :map)++ defp upgrade_call_to_action(assigns) do+ if assigns.current_user.id == assigns.billable_user.id do+ ~H"""+ please+ <.link class="underline" href={Routes.billing_path(PlausibleWeb.Endpoint, :upgrade)}>+ upgrade your subscription+ </.link>+ """else- "in #{days_remaining} days"+ ~H"""+ please reach out to the site owner to upgrade their subscription+ """endenddiff --git a/test/plausible_web/components/billing_test.exs b/test/plausible_web/components/billing_test.exsindex aff369bce9..3525c1bd2e 100644--- a/test/plausible_web/components/billing_test.exs+++ b/test/plausible_web/components/billing_test.exs@@ -24,9 +24,9 @@ defmodule PlausibleWeb.Components.BillingTest dofeature_mod: Plausible.Billing.Feature.Props)- assert rendered =~ "Custom Properties is part of the Plausible Business plan."+ assert rendered =~ "This account does not have access to Custom Properties"assert rendered =~ "upgrade your subscription"- assert rendered =~ "/billing/choose-plan"+ assert rendered =~ "/billing/upgrade"endtest "premium_feature_notice/1 does not render an upgrade link when user is not the site owner" do@@ -40,10 +40,8 @@ defmodule PlausibleWeb.Components.BillingTest dofeature_mod: Plausible.Billing.Feature.Funnels)- assert rendered =~- "Funnels is part of the Plausible Business plan. To get access to it, please reach out to the site owner to upgrade your subscription to the Business plan."-- refute rendered =~ "/billing/choose-plan"+ assert rendered =~ "This account does not have access to Funnels"+ assert rendered =~ "please reach out to the site owner to upgrade their subscription"endtest "premium_feature_notice/1 does not render a notice when the user has access to the feature" do@@ -70,9 +68,9 @@ defmodule PlausibleWeb.Components.BillingTest doresource: "users")- assert rendered =~ "Your account is limited to 10 users. To increase this limit"+ assert rendered =~ "This account is limited to 10 users. To increase this limit"assert rendered =~ "upgrade your subscription"- assert rendered =~ "/billing/choose-plan"+ assert rendered =~ "/billing/upgrade"endtest "limit_exceeded_notice/1 when billable user is on growth but is not current user does not display upgrade link" do@@ -86,8 +84,8 @@ defmodule PlausibleWeb.Components.BillingTest doresource: "users")- assert rendered =~- "This account is limited to 10 users. To increase this limit, please reach out to the site owner to upgrade their subscription"+ assert rendered =~ "This account is limited to 10 users"+ assert rendered =~ "please reach out to the site owner to upgrade their subscription"endtest "limit_exceeded_notice/1 when billable user is on trial displays upgrade link" do@@ -101,9 +99,9 @@ defmodule PlausibleWeb.Components.BillingTest doresource: "users")- assert rendered =~ "Your account is limited to 10 users. To increase this limit"+ assert rendered =~ "This account is limited to 10 users"assert rendered =~ "upgrade your subscription"- assert rendered =~ "/billing/choose-plan"+ assert rendered =~ "/billing/upgrade"endtest "limit_exceeded_notice/1 when billable user is on an enterprise plan displays support email" dodiff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exsindex 09dbf0425e..02bb233874 100644--- a/test/plausible_web/controllers/site_controller_test.exs+++ b/test/plausible_web/controllers/site_controller_test.exs@@ -271,7 +271,7 @@ defmodule PlausibleWeb.SiteControllerTest do})assert html = html_response(conn, 200)- assert html =~ "Your account is limited to 10 sites"+ assert html =~ "This account is limited to 10 sites"refute Repo.get_by(Plausible.Site, domain: "over-limit.example.com")end