Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

add a default base_email layout to every email

Robert31c8ebe842fe
diff --git a/lib/plausible_web/email.ex b/lib/plausible_web/email.ex
index 08568f929b..70041a0a7d 100644
--- a/lib/plausible_web/email.ex
+++ b/lib/plausible_web/email.ex
@@ -305,11 +305,21 @@ defmodule PlausibleWeb.Email do
})
end
- defp base_email() do
+ defp base_email(), do: base_email(%{layout: "base_email.html"})
+
+ defp base_email(%{layout: layout}) do
mailer_from = Application.get_env(:plausible, :mailer_email)
new_email()
|> put_param("TrackOpens", false)
|> from(mailer_from)
+ |> maybe_put_layout(layout)
+ end
+
+ defp maybe_put_layout(email, nil), do: email
+
+ defp maybe_put_layout(email, layout) do
+ email
+ |> put_html_layout({PlausibleWeb.LayoutView, layout})
end
end
diff --git a/lib/plausible_web/templates/layout/base_email.html.eex b/lib/plausible_web/templates/layout/base_email.html.eex
new file mode 100644
index 0000000000..c13e1a21b6
--- /dev/null
+++ b/lib/plausible_web/templates/layout/base_email.html.eex
@@ -0,0 +1,24 @@
+<%= case Map.get(assigns, :user) do
+ %{name: name} when is_binary(name) -> "Hey #{String.split(name) |> List.first()},"
+ _any -> "Hey,"
+end %>
+<br /><br />
+
+<%= @inner_content %>
+<br /><br />
+
+Thanks,<br />
+<%= if Application.get_env(:plausible, :is_selfhost) do %>
+Plausible
+<% else %>
+Uku and Marko
+<% end %>
+<br /><br />
+
+--
+<br /><br />
+<%= link(plausible_url(), to: plausible_url()) %><br />
+
+<%= if Map.get(assigns, :unsubscribe, false) do %>
+{{{ pm:unsubscribe }}}
+<% end %>