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
Add upgrade page for specific plan
Uku Taht4ea60f8f1cdb
diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.exindex e3650e111a..0e53d58ed2 100644--- a/lib/plausible/billing/plans.ex+++ b/lib/plausible/billing/plans.ex@@ -32,6 +32,13 @@ defmodule Plausible.Billing.Plans domonthly_cost: "$150",limit: 20_000_000,cycle: "yearly"+ },+ %{+ product_id: "648089",+ cost: "$4800",+ monthly_cost: "$400",+ limit: 150_000_000,+ cycle: "yearly"}]@@ -54,6 +61,10 @@ defmodule Plausible.Billing.Plans do}end+ def for_product_id(product_id) do+ Enum.find(@all_plans, fn plan -> plan[:product_id] == product_id end)+ end+def suggested_plan_name(usage) doplan = suggested_plan(usage)number_format(plan[:limit]) <> "/mo"diff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.exindex 3496a00592..3ce1ea1283 100644--- a/lib/plausible_web/controllers/billing_controller.ex+++ b/lib/plausible_web/controllers/billing_controller.ex@@ -76,6 +76,23 @@ defmodule PlausibleWeb.BillingController do)end+ def upgrade_to_plan(conn, %{"plan_id" => plan_id}) do+ plan = Plausible.Billing.Plans.for_product_id(plan_id)++ if plan do+ usage = Plausible.Billing.usage(conn.assigns[:current_user])++ render(conn, "upgrade_to_plan.html",+ usage: usage,+ plan: plan,+ user: conn.assigns[:current_user],+ layout: {PlausibleWeb.LayoutView, "focus.html"}+ )+ else+ render_error(conn, 404)+ end+ end+def upgrade_success(conn, _params) dorender(conn, "upgrade_success.html", layout: {PlausibleWeb.LayoutView, "focus.html"})enddiff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.exindex 73d2447ef7..885fcbeb07 100644--- a/lib/plausible_web/router.ex+++ b/lib/plausible_web/router.ex@@ -140,6 +140,7 @@ defmodule PlausibleWeb.Router doget "/billing/change-plan/preview/:plan_id", BillingController, :change_plan_previewpost "/billing/change-plan/:new_plan_id", BillingController, :change_planget "/billing/upgrade", BillingController, :upgrade+ get "/billing/upgrade/:plan_id", BillingController, :upgrade_to_planget "/billing/upgrade-success", BillingController, :upgrade_successget "/sites", SiteController, :indexdiff --git a/lib/plausible_web/templates/billing/upgrade_to_plan.html.eex b/lib/plausible_web/templates/billing/upgrade_to_plan.html.eexnew file mode 100644index 0000000000..14907c7fda--- /dev/null+++ b/lib/plausible_web/templates/billing/upgrade_to_plan.html.eex@@ -0,0 +1,44 @@+<div class="mx-auto mt-6 text-center">+ <h1 class="text-3xl font-black dark:text-gray-100">Upgrade your free trial</h1>+</div>++<div>+ <div class="flex flex-col w-full max-w-4xl px-4 mx-auto mt-4 md:flex-row">+ <div class="flex-1 px-8 py-4 mt-8 mb-4 bg-white rounded shadow-md dark:bg-gray-800">+ <div class="w-full py-4 dark:text-gray-100">+ <span>You've used <b><%= PlausibleWeb.AuthView.delimit_integer(@usage) %></b> billable pageviews in the last 30 days</span>+ </div>++ <div class="w-full py-4 dark:text-gray-100">+ <span>With this link you can upgrade to a plan with <b><%= PlausibleWeb.StatsView.large_number_format(@plan[:limit]) %> monthly pageviews</b></span>. You will be billed <%= @plan[:cost] %> on a <%= @plan[:cycle] %> basis.+ </div>++ <div class="mt-6 text-left">+ <span class="inline-flex w-full rounded-md shadow-sm">+ <button type="button" data-theme="none" data-product="<%= @plan[:product_id] %>" data-email="<%= @conn.assigns[:current_user].email %>" data-disable-logout="true" data-passthrough="<%= @conn.assigns[:current_user].id %>" data-success="/billing/upgrade-success" class="items-center button paddle_button">+ <svg fill="currentColor" viewBox="0 0 20 20" class="inline w-4 h-4 mr-2"><path fill-rule="evenodd" d="M5 9V7a5 5 0 0110 0v2a2 2 0 012 2v5a2 2 0 01-2 2H5a2 2 0 01-2-2v-5a2 2 0 012-2zm8-2v2H7V7a3 3 0 016 0z" clip-rule="evenodd"></path></svg>+ Pay securely via Paddle+ </button>+ </span>+ </div>+ </div>++ <div class="flex-1 pl-8 pt-14">+ <h3 class="text-lg font-medium text-gray-900 leading-6 dark:text-gray-100">+ What happens if I go over my page views limit?+ </h3>+ <div class="mt-2 text-base text-gray-500 leading-6 dark:text-gray-200">+ You will never be charged extra for an occasional traffic spike. There are no surprise fees and your card will never be charged unexpectedly.<br /><br />+ If your page views exceed your plan for two consecutive months, we will contact you to upgrade to a higher plan for the following month. You will have two weeks to make a decision. You can decide to continue with a higher plan or to cancel your account at that point.+ </div>++ </div>+ </div>+</div>++<div class="mt-8 text-center dark:text-gray-100">+ Questions? Contact <%= link("[email protected]", to: "mailto: [email protected]", class: "text-indigo-500") %>+</div>++<script type="text/javascript" src="https://cdn.paddle.com/paddle/paddle.js"></script>+<script>Paddle.Setup({vendor: 49430})</script>diff --git a/lib/plausible_web/views/stats_view.ex b/lib/plausible_web/views/stats_view.exindex fb138bf218..8c4511d1dd 100644--- a/lib/plausible_web/views/stats_view.ex+++ b/lib/plausible_web/views/stats_view.ex@@ -24,7 +24,7 @@ defmodule PlausibleWeb.StatsView do"#{thousands}k"end- n >= 1_000_000 && n < 100_000_000 ->+ n >= 1_000_000 && n < 1_000_000_000 ->millions = trunc(n / 100_000) / 10if millions == trunc(millions) do