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
Show trial timing in navbar
Uku Tahta20b5592f7c5
diff --git a/lib/plausible/auth/user.ex b/lib/plausible/auth/user.exindex b75887a056..c14294fd19 100644--- a/lib/plausible/auth/user.ex+++ b/lib/plausible/auth/user.ex@@ -18,6 +18,7 @@ defmodule Plausible.Auth.User dohas_many :site_memberships, Plausible.Site.Membershiphas_many :sites, through: [:site_memberships, :site]has_one :google_auth, Plausible.Site.GoogleAuth+ has_one :subscription, Plausible.Billing.Subscriptiontimestamps()enddiff --git a/lib/plausible_web/auth_plug.ex b/lib/plausible_web/auth_plug.exindex 7885b13ea6..9261ea9990 100644--- a/lib/plausible_web/auth_plug.ex+++ b/lib/plausible_web/auth_plug.ex@@ -1,5 +1,6 @@defmodule PlausibleWeb.AuthPlug doimport Plug.Conn+ use Plausible.Repodef init(options) dooptions@@ -9,7 +10,8 @@ defmodule PlausibleWeb.AuthPlug docase get_session(conn, :current_user_id) donil -> connid ->- user = Plausible.Auth.find_user_by(id: id)+ user = Repo.get_by(Plausible.Auth.User, id: id)+ |> Repo.preload(:subscription)if user doassign(conn, :current_user, user)elsediff --git a/lib/plausible_web/templates/layout/app.html.eex b/lib/plausible_web/templates/layout/app.html.eexindex e715c19a4a..915a483d46 100644--- a/lib/plausible_web/templates/layout/app.html.eex+++ b/lib/plausible_web/templates/layout/app.html.eex@@ -21,9 +21,15 @@<%= cond do %><% @conn.assigns[:current_user] -> %><ul class="list-reset flex">- <li class="mr-6 hidden sm:block">- <%= link("Give feedback", to: "/feedback", class: "font-bold rounded py-2 px-3 hover:bg-grey-lighter", style: "line-height: 34px;") %>- </li>+ <%= if @conn.assigns[:current_user].subscription == nil do %>+ <li class="mr-6 hidden sm:block">+ <%= link(trial_notificaton(@conn.assigns[:current_user]), to: "/settings", class: "font-bold text-orange-darkest rounded py-2 px-3 bg-orange-lighter", style: "line-height: 34px;") %>+ </li>+ <% else %>+ <li class="mr-6 hidden sm:block">+ <%= link("Give feedback", to: "/feedback", class: "font-bold rounded py-2 px-3 hover:bg-grey-lighter", style: "line-height: 34px;") %>+ </li>+ <% end %><li><div class="relative font-bold rounded hover:bg-grey-lighter"><div data-dropdown-trigger class="flex items-center hover:bg-grey-lighter rounded p-2 cursor-pointer">diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.exindex 7e7699b110..a62957b502 100644--- a/lib/plausible_web/views/layout_view.ex+++ b/lib/plausible_web/views/layout_view.ex@@ -1,3 +1,16 @@defmodule PlausibleWeb.LayoutView douse PlausibleWeb, :view++ def trial_notificaton(user) do+ case Plausible.Billing.trial_days_left(user) do+ days when days > 1 ->+ "#{days} trial days left"+ days when days == 1 ->+ "Trial ends tomorrow"+ days when days == 0 ->+ "Trial ends today"+ days when days < 0 ->+ "Trial over, upgrade now"+ end+ endend