From 5d9d05c1f6d78a35a6aaa4ea72ab5239d168698f Mon Sep 17 00:00:00 2001 From: Vini Brasil Date: Thu, 24 Aug 2023 14:22:49 -0300 Subject: [PATCH 1/3] Usage & Limits section (#3291) * Update user_settings template to HEEX * Move site_limit function to Billing.Quota * Create Billing.Quota.site_usage function * Move monthly_pageview_limit function to Billing.Quota * Create Billing.Quota.monthly_pageview_usage function * Add "Usage & Limits" section to user settings page * Apply suggestions from code review --- lib/plausible/billing/billing.ex | 9 +- lib/plausible/billing/plans.ex | 50 +-- lib/plausible/billing/quota.ex | 89 +++++ lib/plausible/sites.ex | 20 +- lib/plausible_web/components/billing.ex | 36 ++ .../controllers/auth_controller.ex | 12 +- .../controllers/billing_controller.ex | 2 +- .../controllers/site_controller.ex | 19 +- .../templates/auth/user_settings.html.eex | 281 ------------- .../templates/auth/user_settings.html.heex | 377 ++++++++++++++++++ lib/plausible_web/views/auth_view.ex | 2 +- lib/workers/check_usage.ex | 39 +- test/plausible/billing/billing_test.exs | 46 --- test/plausible/billing/plans_test.exs | 108 ----- test/plausible/billing/quota_test.exs | 196 +++++++++ 15 files changed, 750 insertions(+), 536 deletions(-) create mode 100644 lib/plausible/billing/quota.ex create mode 100644 lib/plausible_web/components/billing.ex delete mode 100644 lib/plausible_web/templates/auth/user_settings.html.eex create mode 100644 lib/plausible_web/templates/auth/user_settings.html.heex create mode 100644 test/plausible/billing/quota_test.exs diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex index d5de08524..5581c088e 100644 --- a/lib/plausible/billing/billing.ex +++ b/lib/plausible/billing/billing.ex @@ -108,11 +108,8 @@ defmodule Plausible.Billing do Timex.diff(user.trial_expiry_date, Timex.today(), :days) end - def usage(user) do - {pageviews, custom_events} = usage_breakdown(user) - pageviews + custom_events - end - + @spec last_two_billing_months_usage(Plausible.Auth.User.t(), Date.t()) :: + {non_neg_integer(), non_neg_integer()} def last_two_billing_months_usage(user, today \\ Timex.today()) do {first, second} = last_two_billing_cycles(user, today) @@ -248,7 +245,7 @@ defmodule Plausible.Billing do case user.grace_period do %GracePeriod{allowance_required: allowance_required} -> new_monthly_pageview_limit = - Plausible.Billing.Plans.monthly_pageview_limit(user.subscription) + Plausible.Billing.Quota.monthly_pageview_limit(user.subscription) if new_monthly_pageview_limit > allowance_required do user diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex index 2feb849c2..6effc2b4b 100644 --- a/lib/plausible/billing/plans.ex +++ b/lib/plausible/billing/plans.ex @@ -105,36 +105,7 @@ defmodule Plausible.Billing.Plans do end) end - @limit_sites_since ~D[2021-05-05] - @spec site_limit(Plausible.Auth.User.t()) :: non_neg_integer() | :unlimited - @doc """ - Returns the limit of sites a user can have. - - For enterprise customers, returns :unlimited. The site limit is checked in a - background job so as to avoid service disruption. - """ - def site_limit(user) do - cond do - Application.get_env(:plausible, :is_selfhost) -> :unlimited - Timex.before?(user.inserted_at, @limit_sites_since) -> :unlimited - true -> get_site_limit_from_plan(user) - end - end - - @site_limit_for_trials 50 - @site_limit_for_free_10k 50 - defp get_site_limit_from_plan(user) do - user = Plausible.Users.with_subscription(user) - - case get_subscription_plan(user.subscription) do - %Plausible.Billing.EnterprisePlan{} -> :unlimited - %Plausible.Billing.Plan{site_limit: site_limit} -> site_limit - :free_10k -> @site_limit_for_free_10k - nil -> @site_limit_for_trials - end - end - - defp get_subscription_plan(subscription) do + def get_subscription_plan(subscription) do if subscription && subscription.paddle_plan_id == "free_10k" do :free_10k else @@ -159,25 +130,6 @@ defmodule Plausible.Billing.Plans do end end - @spec monthly_pageview_limit(Plausible.Billing.Subscription.t()) :: non_neg_integer() | nil - def monthly_pageview_limit(subscription) do - case get_subscription_plan(subscription) do - %Plausible.Billing.EnterprisePlan{monthly_pageview_limit: limit} -> - limit - - %Plausible.Billing.Plan{monthly_pageview_limit: limit} -> - limit - - :free_10k -> - 10_000 - - _any -> - Sentry.capture_message("Unknown monthly pageview limit for plan", - extra: %{paddle_plan_id: subscription.paddle_plan_id} - ) - end - end - defp get_enterprise_plan(nil), do: nil defp get_enterprise_plan(%Plausible.Billing.Subscription{} = subscription) do diff --git a/lib/plausible/billing/quota.ex b/lib/plausible/billing/quota.ex new file mode 100644 index 000000000..bb5250bfc --- /dev/null +++ b/lib/plausible/billing/quota.ex @@ -0,0 +1,89 @@ +defmodule Plausible.Billing.Quota do + @moduledoc """ + This module provides functions to work with plans usage and limits. + """ + + alias Plausible.Billing.Plans + + @limit_sites_since ~D[2021-05-05] + @spec site_limit(Plausible.Auth.User.t()) :: non_neg_integer() | :unlimited + @doc """ + Returns the limit of sites a user can have. + + For enterprise customers, returns :unlimited. The site limit is checked in a + background job so as to avoid service disruption. + """ + def site_limit(user) do + cond do + Application.get_env(:plausible, :is_selfhost) -> :unlimited + Timex.before?(user.inserted_at, @limit_sites_since) -> :unlimited + true -> get_site_limit_from_plan(user) + end + end + + @site_limit_for_trials 50 + @site_limit_for_free_10k 50 + defp get_site_limit_from_plan(user) do + user = Plausible.Users.with_subscription(user) + + case Plans.get_subscription_plan(user.subscription) do + %Plausible.Billing.EnterprisePlan{} -> :unlimited + %Plausible.Billing.Plan{site_limit: site_limit} -> site_limit + :free_10k -> @site_limit_for_free_10k + nil -> @site_limit_for_trials + end + end + + @spec site_usage(Plausible.Auth.User.t()) :: non_neg_integer() + @doc """ + Returns the number of sites the given user owns. + """ + def site_usage(user) do + Plausible.Sites.owned_sites_count(user) + end + + @monthly_pageview_limit_for_free_10k 10_000 + + @spec monthly_pageview_limit(Plausible.Billing.Subscription.t()) :: + non_neg_integer() | :unlimited + @doc """ + Returns the limit of pageviews for a subscription. + """ + def monthly_pageview_limit(subscription) do + case Plans.get_subscription_plan(subscription) do + %Plausible.Billing.EnterprisePlan{monthly_pageview_limit: limit} -> + limit + + %Plausible.Billing.Plan{monthly_pageview_limit: limit} -> + limit + + :free_10k -> + @monthly_pageview_limit_for_free_10k + + _any -> + Sentry.capture_message("Unknown monthly pageview limit for plan", + extra: %{paddle_plan_id: subscription && subscription.paddle_plan_id} + ) + + :unlimited + end + end + + @spec monthly_pageview_usage(Plausible.Auth.User.t()) :: non_neg_integer() + @doc """ + Returns the amount of pageviews sent by the sites the user owns in last 30 days. + """ + def monthly_pageview_usage(user) do + user + |> Plausible.Billing.usage_breakdown() + |> Tuple.sum() + end + + @spec within_limit?(non_neg_integer(), non_neg_integer() | :unlimited) :: boolean() + @doc """ + Returns whether the limit has been exceeded or not. + """ + def within_limit?(usage, limit) do + if limit == :unlimited, do: true, else: usage < limit + end +end diff --git a/lib/plausible/sites.ex b/lib/plausible/sites.ex index 20306f02b..e544b6081 100644 --- a/lib/plausible/sites.ex +++ b/lib/plausible/sites.ex @@ -13,11 +13,12 @@ defmodule Plausible.Sites do Ecto.Multi.new() |> Ecto.Multi.run(:limit, fn _, _ -> - case {Plausible.Billing.Plans.site_limit(user), owned_sites_count(user)} do - {:unlimited, actual} -> {:ok, actual} - {limit, actual} when actual >= limit -> {:error, limit} - {_limit, actual} -> {:ok, actual} - end + limit = Plausible.Billing.Quota.site_limit(user) + usage = Plausible.Billing.Quota.site_usage(user) + + if Plausible.Billing.Quota.within_limit?(usage, limit), + do: {:ok, usage}, + else: {:error, limit} end) |> Ecto.Multi.insert(:site, site_changeset) |> Ecto.Multi.run(:site_membership, fn repo, %{site: site} -> @@ -111,8 +112,9 @@ defmodule Plausible.Sites do def has_goals?(site) do Repo.exists?( - from g in Plausible.Goal, + from(g in Plausible.Goal, where: g.site_id == ^site.id + ) ) end @@ -130,9 +132,10 @@ defmodule Plausible.Sites do def role(user_id, site) do Repo.one( - from sm in Site.Membership, + from(sm in Site.Membership, where: sm.user_id == ^user_id and sm.site_id == ^site.id, select: sm.role + ) ) end @@ -167,11 +170,12 @@ defmodule Plausible.Sites do def owner_for(site) do Repo.one( - from u in Plausible.Auth.User, + from(u in Plausible.Auth.User, join: sm in Site.Membership, on: sm.user_id == u.id, where: sm.site_id == ^site.id, where: sm.role == :owner + ) ) end end diff --git a/lib/plausible_web/components/billing.ex b/lib/plausible_web/components/billing.ex new file mode 100644 index 000000000..fdb5724f1 --- /dev/null +++ b/lib/plausible_web/components/billing.ex @@ -0,0 +1,36 @@ +defmodule PlausibleWeb.Components.Billing do + @moduledoc false + + use Phoenix.Component + + slot(:inner_block, required: true) + attr(:rest, :global) + + def usage_and_limits_table(assigns) do + ~H""" + + + <%= render_slot(@inner_block) %> + +
+ """ + end + + attr(:title, :string, required: true) + attr(:usage, :any, required: true) + attr(:limit, :integer, default: nil) + attr(:pad, :boolean, default: false) + attr(:rest, :global) + + def usage_and_limits_row(assigns) do + ~H""" + + <%= @title %> + + <%= Cldr.Number.to_string!(@usage) %> + <%= if is_number(@limit), do: "/ #{Cldr.Number.to_string!(@limit)}" %> + + + """ + end +end diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 6719b0b5e..416fe6101 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -489,8 +489,8 @@ defmodule PlausibleWeb.AuthController do end defp render_settings(conn, changeset) do - user = conn.assigns[:current_user] - {usage_pageviews, usage_custom_events} = Plausible.Billing.usage_breakdown(user) + user = Plausible.Users.with_subscription(conn.assigns[:current_user]) + {pageview_usage, custom_event_usage} = Plausible.Billing.usage_breakdown(user) render(conn, "user_settings.html", user: user |> Repo.preload(:api_keys), @@ -498,8 +498,12 @@ defmodule PlausibleWeb.AuthController do subscription: user.subscription, invoices: Plausible.Billing.paddle_api().get_invoices(user.subscription), theme: user.theme || "system", - usage_pageviews: usage_pageviews, - usage_custom_events: usage_custom_events + site_limit: Plausible.Billing.Quota.site_limit(user), + site_usage: Plausible.Billing.Quota.site_usage(user), + total_pageview_limit: Plausible.Billing.Quota.monthly_pageview_limit(user.subscription), + total_pageview_usage: pageview_usage + custom_event_usage, + custom_event_usage: custom_event_usage, + pageview_usage: pageview_usage ) end diff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.ex index b7128d96b..abbc450a5 100644 --- a/lib/plausible_web/controllers/billing_controller.ex +++ b/lib/plausible_web/controllers/billing_controller.ex @@ -28,7 +28,7 @@ defmodule PlausibleWeb.BillingController do true -> render(conn, "upgrade.html", skip_plausible_tracking: true, - usage: Plausible.Billing.usage(user), + usage: Plausible.Billing.Quota.monthly_pageview_usage(user), user: user, layout: {PlausibleWeb.LayoutView, "focus.html"} ) diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index b5eeff381..2f25fad06 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -51,27 +51,24 @@ defmodule PlausibleWeb.SiteController do def new(conn, _params) do current_user = conn.assigns[:current_user] - owned_site_count = Plausible.Sites.owned_sites_count(current_user) - {site_limit, is_at_limit} = - case Plausible.Billing.Plans.site_limit(current_user) do - :unlimited -> {:unlimited, false} - limit when is_integer(limit) -> {limit, owned_site_count >= limit} - end + limit = Plausible.Billing.Quota.site_limit(current_user) + usage = Plausible.Billing.Quota.site_usage(current_user) + within_limit? = Plausible.Billing.Quota.within_limit?(usage, limit) render(conn, "new.html", changeset: Plausible.Site.changeset(%Plausible.Site{}), - is_first_site: owned_site_count == 0, - is_at_limit: is_at_limit, - site_limit: site_limit, + is_first_site: usage == 0, + is_at_limit: !within_limit?, + site_limit: limit, layout: {PlausibleWeb.LayoutView, "focus.html"} ) end def create_site(conn, %{"site" => site_params}) do user = conn.assigns[:current_user] - site_count = Plausible.Sites.owned_sites_count(user) - is_first_site = site_count == 0 + usage = Plausible.Billing.Quota.site_usage(user) + is_first_site = usage == 0 case Sites.create(user, site_params) do {:ok, %{site: site}} -> diff --git a/lib/plausible_web/templates/auth/user_settings.html.eex b/lib/plausible_web/templates/auth/user_settings.html.eex deleted file mode 100644 index 6e82fb516..000000000 --- a/lib/plausible_web/templates/auth/user_settings.html.eex +++ /dev/null @@ -1,281 +0,0 @@ -<%= if !Application.get_env(:plausible, :is_selfhost) do %> -
-
-

Subscription Plan

- <%= if @subscription do %> - - <%= present_subscription_status(@subscription.status) %> - - <% end %> -
- -
- - <%= if @subscription && @subscription.status == "deleted" do %> -
-
-
- - - -

- <%= if @subscription.next_bill_date && Timex.compare(@subscription.next_bill_date, Timex.today()) >= 0 do %> - Your subscription is cancelled but you have access to your stats until <%= Timex.format!(@subscription.next_bill_date, "{Mshort} {D}, {YYYY}") %>. Upgrade below to make sure you don't lose access. - <% else %> - Your subscription is cancelled. Upgrade below to get access to your stats again. - <% end %> -

-
-
-
- <% end %> - -
-
-

Monthly quota

- <%= if @subscription do %> -
<%= subscription_quota(@subscription) %> pageviews
- <%= case @subscription.status do %> - <% "active" -> %> - <%= link("Change plan", to: "/billing/change-plan", class: "text-sm text-indigo-500 font-medium") %> - <% "past_due" -> %> - Change plan - <% _ -> %> - <% end %> - <% else %> -
Free trial
- <%= link("Upgrade", to: "/billing/upgrade", class: "text-sm text-indigo-500 font-medium") %> - <% end %> -
-
-

Next bill amount

- <%= if @subscription && @subscription.status in ["active", "past_due"] do %> -
<%= PlausibleWeb.BillingView.present_currency(@subscription.currency_code) %><%= @subscription.next_bill_amount %>
- <%= if @subscription.update_url do %> - <%= link("Update billing info", to: @subscription.update_url, class: "text-sm text-indigo-500 font-medium") %> - <% end %> - <% else %> -
---
- <% end %> -
-
-

Next bill date

- - <%= if @subscription && @subscription.next_bill_date && @subscription.status in ["active", "past_due"] do %> -
<%= Timex.format!(@subscription.next_bill_date, "{Mshort} {D}, {YYYY}") %>
-
(<%= subscription_interval(@subscription) %> billing)
- <% else %> -
---
- <% end %> -
-
- -

Your usage

-

Last 30 days total usage across all of your sites

-
-
-
-
-
- - - - - - - - - - - - - - - - -
- Pageviews - - <%= delimit_integer(@usage_pageviews) %> -
- Custom events - - <%= delimit_integer(@usage_custom_events) %> -
- Total billable pageviews - - <%= delimit_integer(@usage_pageviews + @usage_custom_events) %> -
-
-
-
-
-
- - <%= cond do %> - <% @subscription && @subscription.status in ["active", "past_due", "paused"] && @subscription.cancel_url -> %> -
- <%= link("Cancel my subscription", to: @subscription.cancel_url, class: "inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150") %> -
- <% true -> %> -
- <%= link("Upgrade", to: "/billing/upgrade", class: "inline-block px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:border-indigo-700 focus:ring active:bg-indigo-700 transition ease-in-out duration-150") %> -
- <% end %> -
- -<%= case @invoices do %> - <% {:error, :no_invoices} -> %> - - <% {:error, :request_failed} -> %> -
-

Invoices

-
-

- Something went wrong -

-
- - <% {:ok, invoice_list} when is_list(invoice_list) -> %> -
-

Invoices

-
- - - - - - - - - <%= for invoice <- format_invoices(invoice_list) do %> - - - - - - - - <% end %> -
- Date - - Amount - - Invoice -
- <%= invoice.date %> - - <%= invoice.currency <> invoice.amount %> - - <%= link("Link", to: invoice.url, target: "_blank" ) %> -
-
- <% end %> - -<% end %> - -
-

Dashboard Appearance

- -
- - <%= form_for @changeset, "/settings", [class: "max-w-sm"], fn f -> %> -
- <%= label f, :theme, "Theme Selection", class: "block text-sm font-medium leading-5 text-gray-700 dark:text-gray-300" %> - <%= select f, :theme, Plausible.Themes.options(), class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %> -
- <%= submit "Save", class: "button mt-4" %> - <% end %> -
- -
-

Account settings

- -
- - <%= form_for @changeset, "/settings", [class: "max-w-sm"], fn f -> %> -
- <%= label f, :name, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %> -
- <%= text_input f, :name, class: "shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800" %> - <%= error_tag f, :name %> -
-
-
- <%= label f, :email, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %> -
- <%= email_input f, :email, class: "shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md" %> - <%= error_tag f, :email %> -
-
- <%= submit "Save changes", class: "button mt-4" %> - <% end %> -
- -
-

API keys

- -
- -
-
-
- - <%= if Enum.any?(@user.api_keys) do %> -
- - - - - - - - - - <%= for api_key <- @user.api_keys do %> - - - - - - <% end %> - -
- Name - - Key - - Revoke -
- <%= api_key.name %> - - <%= api_key.key_prefix %><%= String.duplicate("*", 32 - 6) %> - - <%= button("Revoke", to: "/settings/api-keys/#{api_key.id}", class: "text-red-600 hover:text-red-900", method: :delete, "data-confirm": "Are you sure you want to revoke this key? This action cannot be reversed.") %> -
-
- <% end %> - - <%= link "+ New API key", to: "/settings/api-keys/new", class: "button mt-4" %> -
-
-
-
- -
-
-

Delete account

-
- -
- -

Deleting your account removes all sites and stats you've collected

- - <%= if @subscription && @subscription.status == "active" do %> - Delete my account -

Your account cannot be deleted because you have an active subscription. If you want to delete your account, please cancel your subscription first.

- <% else %> - <%= link("Delete my account", to: "/me", class: "inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150", method: "delete", data: [confirm: "Deleting your account will also delete all the sites and data that you own. This action cannot be reversed. Are you sure?"]) %> - <% end %> -
diff --git a/lib/plausible_web/templates/auth/user_settings.html.heex b/lib/plausible_web/templates/auth/user_settings.html.heex new file mode 100644 index 000000000..c54352634 --- /dev/null +++ b/lib/plausible_web/templates/auth/user_settings.html.heex @@ -0,0 +1,377 @@ +<%= if !Application.get_env(:plausible, :is_selfhost) do %> +
+
+

Subscription Plan

+ + <%= present_subscription_status(@subscription.status) %> + +
+ +
+ +
+
+
+ + + +

+ <%= if @subscription.next_bill_date && Timex.compare(@subscription.next_bill_date, Timex.today()) >= 0 do %> + Your subscription is cancelled but you have access to your stats until <%= Timex.format!( + @subscription.next_bill_date, + "{Mshort} {D}, {YYYY}" + ) %>. Upgrade below to make sure you don't lose access. + <% else %> + Your subscription is cancelled. Upgrade below to get access to your stats again. + <% end %> +

+
+
+
+ +
+
+

Monthly quota

+ <%= if @subscription do %> +
+ <%= subscription_quota(@subscription) %> pageviews +
+ + <.link + :if={@subscription.status == "active"} + href={Routes.billing_path(@conn, :change_plan_form)} + class="text-sm text-indigo-500 font-medium" + > + Change plan + + + + Change plan + + <% else %> +
Free trial
+ <.link + href={Routes.billing_path(@conn, :upgrade)} + class="text-sm text-indigo-500 font-medium" + > + Upgrade + + <% end %> +
+
+

Next bill amount

+ <%= if @subscription && @subscription.status in ["active", "past_due"] do %> +
+ <%= PlausibleWeb.BillingView.present_currency(@subscription.currency_code) %><%= @subscription.next_bill_amount %> +
+ <%= if @subscription.update_url do %> + <%= link("Update billing info", + to: @subscription.update_url, + class: "text-sm text-indigo-500 font-medium" + ) %> + <% end %> + <% else %> +
---
+ <% end %> +
+
+

Next bill date

+ + <%= if @subscription && @subscription.next_bill_date && @subscription.status in ["active", "past_due"] do %> +
+ <%= Timex.format!(@subscription.next_bill_date, "{Mshort} {D}, {YYYY}") %> +
+
+ (<%= subscription_interval(@subscription) %> billing) +
+ <% else %> +
---
+ <% end %> +
+
+ +
+

Usage & Limits

+

+ Your usage across all of your sites and the limits of your plan +

+ + + + + + +
+ + <%= cond do %> + <% @subscription && @subscription.status in ["active", "past_due", "paused"] && @subscription.cancel_url -> %> +
+ <%= link("Cancel my subscription", + to: @subscription.cancel_url, + class: + "inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150" + ) %> +
+ <% true -> %> +
+ <%= link("Upgrade", + to: "/billing/upgrade", + class: + "inline-block px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:border-indigo-700 focus:ring active:bg-indigo-700 transition ease-in-out duration-150" + ) %> +
+ <% end %> +
+ + <%= case @invoices do %> + <% {:error, :no_invoices} -> %> + <% {:error, :request_failed} -> %> +
+

Invoices

+
+

+ Something went wrong +

+
+ <% {:ok, invoice_list} when is_list(invoice_list) -> %> +
+

Invoices

+
+ + + + + + + + + <%= for invoice <- format_invoices(invoice_list) do %> + + + + + + + + <% end %> +
+ Date + + Amount + + Invoice +
+ <%= invoice.date %> + + <%= invoice.currency <> invoice.amount %> + + <%= link("Link", to: invoice.url, target: "_blank") %> +
+
+ <% end %> +<% end %> + +
+

Dashboard Appearance

+ +
+ + <%= form_for @changeset, "/settings", [class: "max-w-sm"], fn f -> %> +
+ <%= label(f, :theme, "Theme Selection", + class: "block text-sm font-medium leading-5 text-gray-700 dark:text-gray-300" + ) %> + <%= select(f, :theme, Plausible.Themes.options(), + class: + "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" + ) %> +
+ <%= submit("Save", class: "button mt-4") %> + <% end %> +
+ +
+

Account settings

+ +
+ + <%= form_for @changeset, "/settings", [class: "max-w-sm"], fn f -> %> +
+ <%= label(f, :name, class: "block text-sm font-medium text-gray-700 dark:text-gray-300") %> +
+ <%= text_input(f, :name, + class: + "shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800" + ) %> + <%= error_tag(f, :name) %> +
+
+
+ <%= label(f, :email, class: "block text-sm font-medium text-gray-700 dark:text-gray-300") %> +
+ <%= email_input(f, :email, + class: + "shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md" + ) %> + <%= error_tag(f, :email) %> +
+
+ <%= submit("Save changes", class: "button mt-4") %> + <% end %> +
+ +
+

API keys

+ +
+ +
+
+
+ <%= if Enum.any?(@user.api_keys) do %> +
+ + + + + + + + + + <%= for api_key <- @user.api_keys do %> + + + + + + <% end %> + +
+ Name + + Key + + Revoke +
+ <%= api_key.name %> + + <%= api_key.key_prefix %><%= String.duplicate("*", 32 - 6) %> + + <%= button("Revoke", + to: "/settings/api-keys/#{api_key.id}", + class: "text-red-600 hover:text-red-900", + method: :delete, + "data-confirm": + "Are you sure you want to revoke this key? This action cannot be reversed." + ) %> +
+
+ <% end %> + + <%= link("+ New API key", to: "/settings/api-keys/new", class: "button mt-4") %> +
+
+
+
+ +
+
+

Delete account

+
+ +
+ +

+ Deleting your account removes all sites and stats you've collected +

+ + <%= if @subscription && @subscription.status == "active" do %> + + Delete my account + +

+ Your account cannot be deleted because you have an active subscription. If you want to delete your account, please cancel your subscription first. +

+ <% else %> + <%= link("Delete my account", + to: "/me", + class: + "inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150", + method: "delete", + data: [ + confirm: + "Deleting your account will also delete all the sites and data that you own. This action cannot be reversed. Are you sure?" + ] + ) %> + <% end %> +
diff --git a/lib/plausible_web/views/auth_view.ex b/lib/plausible_web/views/auth_view.ex index 02a4d4751..9274f35e3 100644 --- a/lib/plausible_web/views/auth_view.ex +++ b/lib/plausible_web/views/auth_view.ex @@ -12,7 +12,7 @@ defmodule PlausibleWeb.AuthView do def subscription_quota(subscription) do subscription - |> Plans.monthly_pageview_limit() + |> Plausible.Billing.Quota.monthly_pageview_limit() |> PlausibleWeb.StatsView.large_number_format() end diff --git a/lib/workers/check_usage.ex b/lib/workers/check_usage.ex index b69be996d..1caa8f2ce 100644 --- a/lib/workers/check_usage.ex +++ b/lib/workers/check_usage.ex @@ -35,7 +35,7 @@ defmodule Plausible.Workers.CheckUsage do active_subscribers = Repo.all( - from u in Plausible.Auth.User, + from(u in Plausible.Auth.User, join: s in Plausible.Billing.Subscription, on: s.user_id == u.id, left_join: ep in Plausible.Billing.EnterprisePlan, @@ -48,6 +48,7 @@ defmodule Plausible.Workers.CheckUsage do least(day_of_month(s.last_bill_date), day_of_month(last_day_of_month(^yesterday))) == day_of_month(^yesterday), preload: [subscription: s, enterprise_plan: ep] + ) ) for subscriber <- active_subscribers do @@ -63,7 +64,7 @@ defmodule Plausible.Workers.CheckUsage do def check_enterprise_subscriber(subscriber, billing_mod) do pageview_limit = check_pageview_limit(subscriber, billing_mod) - site_limit = check_site_limit(subscriber) + site_limit = check_site_limit_for_enterprise(subscriber) case {pageview_limit, site_limit} do {{:within_limit, _}, {:within_limit, _}} -> @@ -112,25 +113,21 @@ defmodule Plausible.Workers.CheckUsage do end defp check_pageview_limit(subscriber, billing_mod) do - monthly_pageview_limit = - case Plausible.Billing.Plans.monthly_pageview_limit(subscriber.subscription) do - monthly_pageview_limit when is_number(monthly_pageview_limit) -> - monthly_pageview_limit * 1.1 - - nil -> - Sentry.capture_message("Unable to calculate monthly pageview limit", - user: subscriber, - subscription: subscriber.subscription - ) - end + limit = + subscriber.subscription + |> Plausible.Billing.Quota.monthly_pageview_limit() + |> Kernel.*(1.1) + |> ceil() {_, last_cycle} = billing_mod.last_two_billing_cycles(subscriber) {last_last_cycle_usage, last_cycle_usage} = billing_mod.last_two_billing_months_usage(subscriber) - exceeded_last_cycle? = last_cycle_usage >= monthly_pageview_limit - exceeded_last_last_cycle? = last_last_cycle_usage >= monthly_pageview_limit + exceeded_last_cycle? = not Plausible.Billing.Quota.within_limit?(last_cycle_usage, limit) + + exceeded_last_last_cycle? = + not Plausible.Billing.Quota.within_limit?(last_last_cycle_usage, limit) if exceeded_last_last_cycle? && exceeded_last_cycle? do {:over_limit, {last_cycle, last_cycle_usage}} @@ -139,14 +136,14 @@ defmodule Plausible.Workers.CheckUsage do end end - defp check_site_limit(subscriber) do - site_limit = subscriber.enterprise_plan.site_limit - total_sites = Plausible.Sites.owned_sites_count(subscriber) + defp check_site_limit_for_enterprise(subscriber) do + limit = subscriber.enterprise_plan.site_limit + usage = Plausible.Billing.Quota.site_usage(subscriber) - if total_sites >= site_limit do - {:over_limit, {total_sites, site_limit}} + if Plausible.Billing.Quota.within_limit?(usage, limit) do + {:within_limit, {usage, limit}} else - {:within_limit, {total_sites, site_limit}} + {:over_limit, {usage, limit}} end end end diff --git a/test/plausible/billing/billing_test.exs b/test/plausible/billing/billing_test.exs index 37617de7e..e924c7506 100644 --- a/test/plausible/billing/billing_test.exs +++ b/test/plausible/billing/billing_test.exs @@ -3,52 +3,6 @@ defmodule Plausible.BillingTest do use Bamboo.Test, shared: true alias Plausible.Billing - describe "usage" do - test "is 0 with no events" do - user = insert(:user) - - assert Billing.usage(user) == 0 - end - - test "counts the total number of events from all sites the user owns" do - user = insert(:user) - site1 = insert(:site, members: [user]) - site2 = insert(:site, members: [user]) - - populate_stats(site1, [ - build(:pageview), - build(:pageview) - ]) - - populate_stats(site2, [ - build(:pageview), - build(:event, name: "custom events") - ]) - - assert Billing.usage(user) == 4 - end - - test "only counts usage from sites where the user is the owner" do - user = insert(:user) - - insert(:site, - domain: "site-with-no-views.com", - memberships: [ - build(:site_membership, user: user, role: :owner) - ] - ) - - insert(:site, - domain: "test-site.com", - memberships: [ - build(:site_membership, user: user, role: :admin) - ] - ) - - assert Billing.usage(user) == 0 - end - end - describe "last_two_billing_cycles" do test "billing on the 1st" do last_bill_date = ~D[2021-01-01] diff --git a/test/plausible/billing/plans_test.exs b/test/plausible/billing/plans_test.exs index c906c2997..8bbaaa041 100644 --- a/test/plausible/billing/plans_test.exs +++ b/test/plausible/billing/plans_test.exs @@ -32,32 +32,6 @@ defmodule Plausible.Billing.PlansTest do end end - describe "monthly_pageview_limit" do - test "is based on the plan if user is on a standard plan" do - user = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id)) - - assert Plans.monthly_pageview_limit(user.subscription) == 10_000 - end - - test "free_10k has 10k monthly_pageview_limit" do - user = insert(:user, subscription: build(:subscription, paddle_plan_id: "free_10k")) - - assert Plans.monthly_pageview_limit(user.subscription) == 10_000 - end - - test "is based on the enterprise plan if user is on an enterprise plan" do - user = insert(:user) - - enterprise_plan = - insert(:enterprise_plan, user_id: user.id, monthly_pageview_limit: 100_000) - - subscription = - insert(:subscription, user_id: user.id, paddle_plan_id: enterprise_plan.paddle_plan_id) - - assert Plans.monthly_pageview_limit(subscription) == 100_000 - end - end - describe "subscription_interval" do test "is based on the plan if user is on a standard plan" do user = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id)) @@ -153,86 +127,4 @@ defmodule Plausible.Billing.PlansTest do ] == Plans.yearly_product_ids() end end - - describe "site_limit/1" do - test "returns 50 when user is on an old plan" do - user_on_v1 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id)) - user_on_v2 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v2_plan_id)) - user_on_v3 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v3_plan_id)) - - assert 50 == Plans.site_limit(user_on_v1) - assert 50 == Plans.site_limit(user_on_v2) - assert 50 == Plans.site_limit(user_on_v3) - end - - test "returns 50 when user is on free_10k plan" do - user = insert(:user, subscription: build(:subscription, paddle_plan_id: "free_10k")) - assert 50 == Plans.site_limit(user) - end - - test "returns unlimited when user is on an enterprise plan" do - user = insert(:user) - - enterprise_plan = - insert(:enterprise_plan, - user_id: user.id, - monthly_pageview_limit: 100_000, - site_limit: 500 - ) - - _subscription = - insert(:subscription, user_id: user.id, paddle_plan_id: enterprise_plan.paddle_plan_id) - - assert :unlimited == Plans.site_limit(user) - end - - test "returns 50 when user in on trial" do - user = insert(:user, trial_expiry_date: Timex.shift(Timex.now(), days: 7)) - assert 50 == Plans.site_limit(user) - - user = insert(:user, trial_expiry_date: Timex.shift(Timex.now(), days: -7)) - assert 50 == Plans.site_limit(user) - end - - test "returns the subscription limit for enterprise users who have not paid yet" do - user = - insert(:user, - enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"), - subscription: build(:subscription, paddle_plan_id: @v1_plan_id) - ) - - assert 50 == Plans.site_limit(user) - end - - test "returns 50 for enterprise users who have not upgraded yet and are on trial" do - user = - insert(:user, - enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"), - subscription: nil - ) - - assert 50 == Plans.site_limit(user) - end - - test "is unlimited for enterprise customers" do - user = - insert(:user, - enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"), - subscription: build(:subscription, paddle_plan_id: "123321") - ) - - assert :unlimited == Plans.site_limit(user) - end - - test "is unlimited for enterprise customers who are due to change a plan" do - user = - insert(:user, - enterprise_plan: build(:enterprise_plan, paddle_plan_id: "old-paddle-plan-id"), - subscription: build(:subscription, paddle_plan_id: "old-paddle-plan-id") - ) - - insert(:enterprise_plan, user_id: user.id, paddle_plan_id: "new-paddle-plan-id") - assert :unlimited == Plans.site_limit(user) - end - end end diff --git a/test/plausible/billing/quota_test.exs b/test/plausible/billing/quota_test.exs new file mode 100644 index 000000000..89967bfdf --- /dev/null +++ b/test/plausible/billing/quota_test.exs @@ -0,0 +1,196 @@ +defmodule Plausible.Billing.QuotaTest do + use Plausible.DataCase, async: true + alias Plausible.Billing.Quota + + @v1_plan_id "558018" + @v2_plan_id "654177" + @v3_plan_id "749342" + + describe "site_limit/1" do + test "returns 50 when user is on an old plan" do + user_on_v1 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id)) + user_on_v2 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v2_plan_id)) + user_on_v3 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v3_plan_id)) + + assert 50 == Quota.site_limit(user_on_v1) + assert 50 == Quota.site_limit(user_on_v2) + assert 50 == Quota.site_limit(user_on_v3) + end + + test "returns 50 when user is on free_10k plan" do + user = insert(:user, subscription: build(:subscription, paddle_plan_id: "free_10k")) + assert 50 == Quota.site_limit(user) + end + + test "returns unlimited when user is on an enterprise plan" do + user = insert(:user) + + enterprise_plan = + insert(:enterprise_plan, + user_id: user.id, + monthly_pageview_limit: 100_000, + site_limit: 500 + ) + + _subscription = + insert(:subscription, user_id: user.id, paddle_plan_id: enterprise_plan.paddle_plan_id) + + assert :unlimited == Quota.site_limit(user) + end + + test "returns 50 when user in on trial" do + user = insert(:user, trial_expiry_date: Timex.shift(Timex.now(), days: 7)) + assert 50 == Quota.site_limit(user) + + user = insert(:user, trial_expiry_date: Timex.shift(Timex.now(), days: -7)) + assert 50 == Quota.site_limit(user) + end + + test "returns the subscription limit for enterprise users who have not paid yet" do + user = + insert(:user, + enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"), + subscription: build(:subscription, paddle_plan_id: @v1_plan_id) + ) + + assert 50 == Quota.site_limit(user) + end + + test "returns 50 for enterprise users who have not upgraded yet and are on trial" do + user = + insert(:user, + enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"), + subscription: nil + ) + + assert 50 == Quota.site_limit(user) + end + + test "is unlimited for enterprise customers" do + user = + insert(:user, + enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"), + subscription: build(:subscription, paddle_plan_id: "123321") + ) + + assert :unlimited == Quota.site_limit(user) + end + + test "is unlimited for enterprise customers who are due to change a plan" do + user = + insert(:user, + enterprise_plan: build(:enterprise_plan, paddle_plan_id: "old-paddle-plan-id"), + subscription: build(:subscription, paddle_plan_id: "old-paddle-plan-id") + ) + + insert(:enterprise_plan, user_id: user.id, paddle_plan_id: "new-paddle-plan-id") + assert :unlimited == Quota.site_limit(user) + end + end + + test "site_usage/1 returns the amount of sites the user owns" do + user = insert(:user) + insert_list(3, :site, memberships: [build(:site_membership, user: user, role: :owner)]) + insert(:site, memberships: [build(:site_membership, user: user, role: :admin)]) + insert(:site, memberships: [build(:site_membership, user: user, role: :viewer)]) + + assert Quota.site_usage(user) == 3 + end + + describe "within_limit?/2" do + test "returns true when quota is not exceeded" do + assert Quota.within_limit?(3, 5) + end + + test "returns true when limit is :unlimited" do + assert Quota.within_limit?(10_000, :unlimited) + end + + test "returns false when usage is at limit" do + refute Quota.within_limit?(3, 3) + end + + test "returns false when usage exceeds the limit" do + refute Quota.within_limit?(10, 3) + end + end + + describe "monthly_pageview_limit/1" do + test "is based on the plan if user is on a standard plan" do + user = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id)) + + assert Quota.monthly_pageview_limit(user.subscription) == 10_000 + end + + test "free_10k has 10k monthly_pageview_limit" do + user = insert(:user, subscription: build(:subscription, paddle_plan_id: "free_10k")) + + assert Quota.monthly_pageview_limit(user.subscription) == 10_000 + end + + test "is based on the enterprise plan if user is on an enterprise plan" do + user = insert(:user) + + enterprise_plan = + insert(:enterprise_plan, user_id: user.id, monthly_pageview_limit: 100_000) + + subscription = + insert(:subscription, user_id: user.id, paddle_plan_id: enterprise_plan.paddle_plan_id) + + assert Quota.monthly_pageview_limit(subscription) == 100_000 + end + + test "does not limit pageviews when user has a pending enterprise plan" do + user = insert(:user) + subscription = insert(:subscription, user_id: user.id, paddle_plan_id: "pending-enterprise") + + assert Quota.monthly_pageview_limit(subscription) == :unlimited + end + end + + describe "monthly_pageview_usage/1" do + test "is 0 with no events" do + user = insert(:user) + + assert Quota.monthly_pageview_usage(user) == 0 + end + + test "counts the total number of events from all sites the user owns" do + user = insert(:user) + site1 = insert(:site, members: [user]) + site2 = insert(:site, members: [user]) + + populate_stats(site1, [ + build(:pageview), + build(:pageview) + ]) + + populate_stats(site2, [ + build(:pageview), + build(:event, name: "custom events") + ]) + + assert Quota.monthly_pageview_usage(user) == 4 + end + + test "only counts usage from sites where the user is the owner" do + user = insert(:user) + + insert(:site, + domain: "site-with-no-views.com", + memberships: [ + build(:site_membership, user: user, role: :owner) + ] + ) + + insert(:site, + domain: "test-site.com", + memberships: [ + build(:site_membership, user: user, role: :admin) + ] + ) + + assert Quota.monthly_pageview_usage(user) == 0 + end + end +end From dbc3b91a4b4998b19213faf8fa539b2cbaaf5dd7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 24 Aug 2023 14:23:25 -0300 Subject: [PATCH 2/3] Bump @playwright/test from 1.37.0 to 1.37.1 in /tracker (#3275) Bumps [@playwright/test](https://github.com/Microsoft/playwright) from 1.37.0 to 1.37.1. - [Release notes](https://github.com/Microsoft/playwright/releases) - [Commits](https://github.com/Microsoft/playwright/compare/v1.37.0...v1.37.1) --- updated-dependencies: - dependency-name: "@playwright/test" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- tracker/package-lock.json | 16 ++++++++-------- tracker/package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tracker/package-lock.json b/tracker/package-lock.json index 7028ad1a0..e6c94b231 100644 --- a/tracker/package-lock.json +++ b/tracker/package-lock.json @@ -6,7 +6,7 @@ "": { "license": "MIT", "dependencies": { - "@playwright/test": "^1.37.0", + "@playwright/test": "^1.37.1", "express": "^4.18.1", "generatorics": "^1.1.0", "handlebars": "^4.7.8", @@ -151,12 +151,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.37.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.37.0.tgz", - "integrity": "sha512-181WBLk4SRUyH1Q96VZl7BP6HcK0b7lbdeKisn3N/vnjitk+9HbdlFz/L5fey05vxaAhldIDnzo8KUoy8S3mmQ==", + "version": "1.37.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.37.1.tgz", + "integrity": "sha512-bq9zTli3vWJo8S3LwB91U0qDNQDpEXnw7knhxLM0nwDvexQAwx9tO8iKDZSqqneVq+URd/WIoz+BALMqUTgdSg==", "dependencies": { "@types/node": "*", - "playwright-core": "1.37.0" + "playwright-core": "1.37.1" }, "bin": { "playwright": "cli.js" @@ -1394,9 +1394,9 @@ "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" }, "node_modules/playwright-core": { - "version": "1.37.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.37.0.tgz", - "integrity": "sha512-1c46jhTH/myQw6sesrcuHVtLoSNfJv8Pfy9t3rs6subY7kARv0HRw5PpyfPYPpPtQvBOmgbE6K+qgYUpj81LAA==", + "version": "1.37.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.37.1.tgz", + "integrity": "sha512-17EuQxlSIYCmEMwzMqusJ2ztDgJePjrbttaefgdsiqeLWidjYz9BxXaTaZWxH1J95SHGk6tjE+dwgWILJoUZfA==", "bin": { "playwright-core": "cli.js" }, diff --git a/tracker/package.json b/tracker/package.json index e6e4913a0..eb39a6620 100644 --- a/tracker/package.json +++ b/tracker/package.json @@ -6,7 +6,7 @@ }, "license": "MIT", "dependencies": { - "@playwright/test": "^1.37.0", + "@playwright/test": "^1.37.1", "express": "^4.18.1", "generatorics": "^1.1.0", "handlebars": "^4.7.8", From 93a7cd5d49225ec5c1986b83199d40374e74b631 Mon Sep 17 00:00:00 2001 From: hq1 Date: Mon, 28 Aug 2023 10:03:06 +0200 Subject: [PATCH 3/3] Connect to live socket only on specific pages (#3292) * Connect to live socket only on specific pages And disable the "server blip" message on non-dev environments. It's non actionable to our customers. * Simplify meta tags rendering --- lib/plausible_web/controllers/site_controller.ex | 4 +++- lib/plausible_web/live/flash.ex | 3 ++- lib/plausible_web/templates/layout/app.html.eex | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index 2f25fad06..9e929e7f7 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -282,6 +282,7 @@ defmodule PlausibleWeb.SiteController do |> assign(:skip_plausible_tracking, true) |> render("settings_funnels.html", site: site, + connect_live_socket: true, layout: {PlausibleWeb.LayoutView, "site_settings.html"} ) else @@ -295,7 +296,8 @@ defmodule PlausibleWeb.SiteController do |> assign(:skip_plausible_tracking, true) |> render("settings_props.html", site: conn.assigns.site, - layout: {PlausibleWeb.LayoutView, "site_settings.html"} + layout: {PlausibleWeb.LayoutView, "site_settings.html"}, + connect_live_socket: true ) else conn |> Plug.Conn.put_status(401) |> Plug.Conn.halt() diff --git a/lib/plausible_web/live/flash.ex b/lib/plausible_web/live/flash.ex index ee963a667..ed1008f37 100644 --- a/lib/plausible_web/live/flash.ex +++ b/lib/plausible_web/live/flash.ex @@ -24,6 +24,7 @@ defmodule PlausibleWeb.Live.Flash do diff --git a/lib/plausible_web/templates/layout/app.html.eex b/lib/plausible_web/templates/layout/app.html.eex index b58a7a295..f69a98dec 100644 --- a/lib/plausible_web/templates/layout/app.html.eex +++ b/lib/plausible_web/templates/layout/app.html.eex @@ -5,11 +5,11 @@ - <%= if Plausible.Funnels.enabled_for?(@conn.assigns[:current_user]) do %> + <%= if @conn.assigns[:connect_live_socket] do %> - <% end %> + "> <%= assigns[:title] || "Plausible ยท Simple, privacy-friendly alternative to Google Analytics" %>