diff --git a/lib/plausible_web/email.ex b/lib/plausible_web/email.ex
index 08568f929..5387f8408 100644
--- a/lib/plausible_web/email.ex
+++ b/lib/plausible_web/email.ex
@@ -19,7 +19,7 @@ defmodule PlausibleWeb.Email do
|> to(user)
|> tag("welcome-email")
|> subject("Welcome to Plausible")
- |> render("welcome_email.html", user: user)
+ |> render("welcome_email.html", user: user, unsubscribe: true)
end
def create_site_email(user) do
@@ -27,7 +27,7 @@ defmodule PlausibleWeb.Email do
|> to(user)
|> tag("create-site-email")
|> subject("Your Plausible setup: Add your website details")
- |> render("create_site_email.html", user: user)
+ |> render("create_site_email.html", user: user, unsubscribe: true)
end
def site_setup_help(user, site) do
@@ -35,7 +35,11 @@ defmodule PlausibleWeb.Email do
|> to(user)
|> tag("help-email")
|> subject("Your Plausible setup: Waiting for the first page views")
- |> render("site_setup_help_email.html", user: user, site: site)
+ |> render("site_setup_help_email.html",
+ user: user,
+ site: site,
+ unsubscribe: true
+ )
end
def site_setup_success(user, site) do
@@ -43,7 +47,11 @@ defmodule PlausibleWeb.Email do
|> to(user)
|> tag("setup-success-email")
|> subject("Plausible is now tracking your website stats")
- |> render("site_setup_success_email.html", user: user, site: site)
+ |> render("site_setup_success_email.html",
+ user: user,
+ site: site,
+ unsubscribe: true
+ )
end
def check_stats_email(user) do
@@ -51,11 +59,11 @@ defmodule PlausibleWeb.Email do
|> to(user)
|> tag("check-stats-email")
|> subject("Check your Plausible website stats")
- |> render("check_stats_email.html", user: user)
+ |> render("check_stats_email.html", user: user, unsubscribe: true)
end
def password_reset_email(email, reset_link) do
- base_email()
+ base_email(%{layout: nil})
|> to(email)
|> tag("password-reset-email")
|> subject("Plausible password reset")
@@ -67,7 +75,7 @@ defmodule PlausibleWeb.Email do
|> to(user)
|> tag("trial-one-week-reminder")
|> subject("Your Plausible trial expires next week")
- |> render("trial_one_week_reminder.html", user: user)
+ |> render("trial_one_week_reminder.html", user: user, unsubscribe: true)
end
def trial_upgrade_email(user, day, {pageviews, custom_events}) do
@@ -82,7 +90,8 @@ defmodule PlausibleWeb.Email do
day: day,
custom_events: custom_events,
usage: pageviews + custom_events,
- suggested_plan: suggested_plan
+ suggested_plan: suggested_plan,
+ unsubscribe: true
)
end
@@ -91,11 +100,11 @@ defmodule PlausibleWeb.Email do
|> to(user)
|> tag("trial-over-email")
|> subject("Your Plausible trial has ended")
- |> render("trial_over_email.html", user: user)
+ |> render("trial_over_email.html", user: user, unsubscribe: true)
end
def weekly_report(email, site, assigns) do
- base_email()
+ base_email(%{layout: nil})
|> to(email)
|> tag("weekly-report")
|> subject("#{assigns[:name]} report for #{site.domain}")
@@ -124,12 +133,13 @@ defmodule PlausibleWeb.Email do
user: user,
usage: usage,
last_cycle: last_cycle,
- suggested_plan: suggested_plan
+ suggested_plan: suggested_plan,
+ unsubscribe: true
})
end
def enterprise_over_limit_internal_email(user, usage, last_cycle, site_usage, site_allowance) do
- base_email()
+ base_email(%{layout: nil})
|> to("enterprise@plausible.io")
|> tag("enterprise-over-limit")
|> subject("#{user.email} has outgrown their enterprise plan")
@@ -188,7 +198,7 @@ defmodule PlausibleWeb.Email do
|> to(user.email)
|> tag("cancelled-email")
|> subject("Your Plausible Analytics subscription has been canceled")
- |> render("cancellation_email.html", name: user.name)
+ |> render("cancellation_email.html", user: user)
end
def new_user_invitation(invitation) do
@@ -230,6 +240,7 @@ defmodule PlausibleWeb.Email do
"[Plausible Analytics] #{invitation.email} accepted your invitation to #{invitation.site.domain}"
)
|> render("invitation_accepted.html",
+ user: invitation.inviter,
invitation: invitation
)
end
@@ -242,6 +253,7 @@ defmodule PlausibleWeb.Email do
"[Plausible Analytics] #{invitation.email} rejected your invitation to #{invitation.site.domain}"
)
|> render("invitation_rejected.html",
+ user: invitation.inviter,
invitation: invitation
)
end
@@ -254,6 +266,7 @@ defmodule PlausibleWeb.Email do
"[Plausible Analytics] #{invitation.email} accepted the ownership transfer of #{invitation.site.domain}"
)
|> render("ownership_transfer_accepted.html",
+ user: invitation.inviter,
invitation: invitation
)
end
@@ -266,6 +279,7 @@ defmodule PlausibleWeb.Email do
"[Plausible Analytics] #{invitation.email} rejected the ownership transfer of #{invitation.site.domain}"
)
|> render("ownership_transfer_rejected.html",
+ user: invitation.inviter,
invitation: invitation
)
end
@@ -276,6 +290,7 @@ defmodule PlausibleWeb.Email do
|> tag("site-member-removed")
|> subject("[Plausible Analytics] Your access to #{membership.site.domain} has been revoked")
|> render("site_member_removed.html",
+ user: membership.user,
membership: membership
)
end
@@ -305,11 +320,21 @@ defmodule PlausibleWeb.Email do
})
end
- defp base_email() do
+ def base_email(), do: base_email(%{layout: "base_email.html"})
+
+ def 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/email/activation_email.html.eex b/lib/plausible_web/templates/email/activation_email.html.eex
index 66367c2f9..6373e81b8 100644
--- a/lib/plausible_web/templates/email/activation_email.html.eex
+++ b/lib/plausible_web/templates/email/activation_email.html.eex
@@ -1,3 +1 @@
-Hey <%= user_salutation(@user) %>,
-
Enter <%= @code %> to verify your email address. This code will expire in 4 hours.
diff --git a/lib/plausible_web/templates/email/cancellation_email.html.eex b/lib/plausible_web/templates/email/cancellation_email.html.eex
index 119e46001..746e314f7 100644
--- a/lib/plausible_web/templates/email/cancellation_email.html.eex
+++ b/lib/plausible_web/templates/email/cancellation_email.html.eex
@@ -1,10 +1,7 @@
-Hi <%= @name %>,
-
-Thanks for being a Plausible Analytics subscriber and I'm sorry to see you go.
+Thanks for being a Plausible Analytics subscriber and we're sorry to see you go.
-I'd love to hear about your experience and how you think we can improve Plausible Analytics for our other subscribers (and for you if you decide to come back). Please reply back to this email with your feedback.
+We'd love to hear about your experience and how you think we can improve Plausible Analytics for our other subscribers (and for you if you decide to come back). Please reply back to this email with your feedback.
If you decide you'd like to continue keeping track of your site traffic while respecting the privacy of your visitors, obviously we'd love to have you back. You can restart your subscription from your account settings.
-Hope to see you around!
-Uku Taht
+Hope to see you around!
diff --git a/lib/plausible_web/templates/email/check_stats_email.html.eex b/lib/plausible_web/templates/email/check_stats_email.html.eex
index 5c746e628..a6432e656 100644
--- a/lib/plausible_web/templates/email/check_stats_email.html.eex
+++ b/lib/plausible_web/templates/email/check_stats_email.html.eex
@@ -1,15 +1,5 @@
-Hey <%= user_salutation(@user) %>,
-
Plausible is tracking your website stats without compromising the user experience and the privacy of your visitors.
<%= link("View your Plausible dashboard now", to: "#{plausible_url()}") %> for the most valuable traffic insights at a glance.
Do reply back to this email if you have any questions or need some guidance.
-
-Thanks,
-Uku Taht
-
---
-
-<%= plausible_url() %>
-{{{ pm:unsubscribe }}}
diff --git a/lib/plausible_web/templates/email/create_site_email.html.eex b/lib/plausible_web/templates/email/create_site_email.html.eex
index e34eafb26..d6c2ca196 100644
--- a/lib/plausible_web/templates/email/create_site_email.html.eex
+++ b/lib/plausible_web/templates/email/create_site_email.html.eex
@@ -1,13 +1,5 @@
-Hey <%= user_salutation(@user) %>,
-
You've activated your free 30-day trial of Plausible, a simple and privacy-friendly website analytics tool.
<%= link("Click here", to: "#{plausible_url()}/sites/new") %> to add your website URL, your timezone and install our one-line JavaScript snippet to start collecting visitor statistics.
Do reply back to this email if you have any questions or need some guidance.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
-{{{ pm:unsubscribe }}}
diff --git a/lib/plausible_web/templates/email/dashboard_locked.html.eex b/lib/plausible_web/templates/email/dashboard_locked.html.eex
index 67b9d867a..b3c870c9f 100644
--- a/lib/plausible_web/templates/email/dashboard_locked.html.eex
+++ b/lib/plausible_web/templates/email/dashboard_locked.html.eex
@@ -1,5 +1,3 @@
-Hey <%= user_salutation(@user) %>,
-
Last week we sent a reminder that your traffic has exceeded your Plausible Analytics subscription tier two months in a row.
Your dashboard is now locked. We're still counting your stats, but you no longer have access to the stats. As you have outgrown your subscription tier, we kindly ask you to upgrade your subscription to accommodate your new traffic levels.
@@ -16,8 +14,3 @@ Based on that we recommend you select the <%= @suggested_plan[:volume] %>/mo pla
The new charge will be prorated to reflect the amount you have already paid and the time until your current subscription is supposed to expire. We will unlock your dashboard immediately after your account has been upgraded to the appropriate tier.
Thanks for understanding and for being a Plausible subscriber!
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/enterprise_over_limit_internal.html.eex b/lib/plausible_web/templates/email/enterprise_over_limit_internal.html.eex
index af82475e0..2ee4f37e4 100644
--- a/lib/plausible_web/templates/email/enterprise_over_limit_internal.html.eex
+++ b/lib/plausible_web/templates/email/enterprise_over_limit_internal.html.eex
@@ -4,6 +4,3 @@ Customer email: <%= @user.email %>
Last billing cycle: <%= date_format(@last_cycle.first) %> to <%= date_format(@last_cycle.last) %>
Pageview Usage: <%= PlausibleWeb.StatsView.large_number_format(@usage) %> billable pageviews
Site usage: <%= @site_usage %> / <%= @site_allowance %> allowed sites
-
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/existing_user_invitation.html.eex b/lib/plausible_web/templates/email/existing_user_invitation.html.eex
index c1bc0354b..3bdd91a18 100644
--- a/lib/plausible_web/templates/email/existing_user_invitation.html.eex
+++ b/lib/plausible_web/templates/email/existing_user_invitation.html.eex
@@ -1,10 +1,3 @@
-Hey,
-
<%= @invitation.inviter.email %> has invited you to the <%= @invitation.site.domain %> site on Plausible Analytics.
<%= link("Click here", to: Routes.site_url(PlausibleWeb.Endpoint, :index)) %> to view and respond to the invitation. The invitation
will expire 48 hours after this email is sent.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/google_analytics_import.html.eex b/lib/plausible_web/templates/email/google_analytics_import.html.eex
index 388db86e5..a99c2f91a 100644
--- a/lib/plausible_web/templates/email/google_analytics_import.html.eex
+++ b/lib/plausible_web/templates/email/google_analytics_import.html.eex
@@ -1,5 +1,3 @@
-Hey <%= user_salutation(@user) %>,
-
<%= if @success do %>
Your Google Analytics import has completed successfully. The Plausible dashboard for <%= @site.domain %> now contains historical imported data from <%= date_format(@site.imported_data.start_date) %> to <%= date_format(@site.imported_data.end_date) %>
@@ -31,14 +29,6 @@ Hey <%= user_salutation(@user) %>,
<%= if !Application.get_env(:plausible, :is_selfhost) do %>
-
- Please reply to this email to let us know if you're still experiencing issues with the import. Thanks!
-
-
- The Plausible Team 💌
+ Please reply to this email to let us know if you're still experiencing issues with the import.
<% end %>
<% end %>
-
---
-
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/invitation_accepted.html.eex b/lib/plausible_web/templates/email/invitation_accepted.html.eex
index f437183d2..5717ce262 100644
--- a/lib/plausible_web/templates/email/invitation_accepted.html.eex
+++ b/lib/plausible_web/templates/email/invitation_accepted.html.eex
@@ -1,9 +1,2 @@
-Hey <%= user_salutation(@invitation.inviter) %>,
-
<%= @invitation.email %> has accepted your invitation to <%= @invitation.site.domain %>.
<%= link("Click here", to: Routes.site_url(PlausibleWeb.Endpoint, :settings_general, @invitation.site.domain)) %> to view site settings.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/invitation_rejected.html.eex b/lib/plausible_web/templates/email/invitation_rejected.html.eex
index ef40174ba..b6c520690 100644
--- a/lib/plausible_web/templates/email/invitation_rejected.html.eex
+++ b/lib/plausible_web/templates/email/invitation_rejected.html.eex
@@ -1,9 +1,2 @@
-Hey <%= user_salutation(@invitation.inviter) %>,
-
<%= @invitation.email %> has rejected your invitation to <%= @invitation.site.domain %>.
<%= link("Click here", to: Routes.site_url(PlausibleWeb.Endpoint, :settings_general, @invitation.site.domain)) %> to view site settings.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/new_user_invitation.html.eex b/lib/plausible_web/templates/email/new_user_invitation.html.eex
index d21a004ab..ffef74616 100644
--- a/lib/plausible_web/templates/email/new_user_invitation.html.eex
+++ b/lib/plausible_web/templates/email/new_user_invitation.html.eex
@@ -1,11 +1,4 @@
-Hey,
-
<%= @invitation.inviter.email %> has invited you to join the <%= @invitation.site.domain %> site on Plausible Analytics.
<%= link("Click here", to: Routes.auth_url(PlausibleWeb.Endpoint, :register_from_invitation_form, @invitation.invitation_id)) %> to create your account. The link is valid for 48 hours after this email is sent.
Plausible is a lightweight and open-source website analytics tool. We hope you like our simple and ethical approach to tracking website visitors.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/over_limit.html.eex b/lib/plausible_web/templates/email/over_limit.html.eex
index f0ebea30d..01fbb54bb 100644
--- a/lib/plausible_web/templates/email/over_limit.html.eex
+++ b/lib/plausible_web/templates/email/over_limit.html.eex
@@ -1,5 +1,3 @@
-Hey <%= user_salutation(@user) %>,
-
Thanks for being a Plausible Analytics subscriber!
This is a notice that your traffic has exceeded your subscription tier two months in a row. Congrats on all that traffic!
@@ -20,9 +18,3 @@ You can upgrade your subscription using our self-serve platform. The new charge
Have questions or need help with anything? Just reply to this email and we'll gladly help.
Thanks again for using our product and for your support!
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
-{{{ pm:unsubscribe }}}
diff --git a/lib/plausible_web/templates/email/ownership_transfer_accepted.html.eex b/lib/plausible_web/templates/email/ownership_transfer_accepted.html.eex
index 1d8dcf53c..c8c274007 100644
--- a/lib/plausible_web/templates/email/ownership_transfer_accepted.html.eex
+++ b/lib/plausible_web/templates/email/ownership_transfer_accepted.html.eex
@@ -1,10 +1,3 @@
-Hey <%= user_salutation(@invitation.inviter) %>,
-
<%= @invitation.email %> has accepted the ownership transfer of <%= @invitation.site.domain %>. They will be responsible for billing of it going
forward and your role has been changed to admin.
<%= link("Click here", to: Routes.site_url(PlausibleWeb.Endpoint, :settings_general, @invitation.site.domain)) %> to view site settings.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/ownership_transfer_rejected.html.eex b/lib/plausible_web/templates/email/ownership_transfer_rejected.html.eex
index b67ca63e0..14deeacb3 100644
--- a/lib/plausible_web/templates/email/ownership_transfer_rejected.html.eex
+++ b/lib/plausible_web/templates/email/ownership_transfer_rejected.html.eex
@@ -1,9 +1,2 @@
-Hey <%= user_salutation(@invitation.inviter) %>,
-
<%= @invitation.email %> has rejected the ownership transfer of <%= @invitation.site.domain %>.
<%= link("Click here", to: Routes.site_url(PlausibleWeb.Endpoint, :settings_general, @invitation.site.domain)) %> to view site settings.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/ownership_transfer_request.html.eex b/lib/plausible_web/templates/email/ownership_transfer_request.html.eex
index 1ba11000a..13ce240f5 100644
--- a/lib/plausible_web/templates/email/ownership_transfer_request.html.eex
+++ b/lib/plausible_web/templates/email/ownership_transfer_request.html.eex
@@ -1,5 +1,3 @@
-Hey,
-
<%= @invitation.inviter.email %> has requested to transfer the ownership of <%= @invitation.site.domain %> site on Plausible Analytics to you.
<%= if @new_owner_account do %>
<%= link("Click here", to: Routes.site_url(PlausibleWeb.Endpoint, :index)) %> to view and respond to the invitation.
@@ -8,8 +6,3 @@ Hey,
Plausible is a lightweight and open-source website analytics tool. We hope you like our simple and ethical approach to tracking website visitors.
<% end %>
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/site_member_removed.html.eex b/lib/plausible_web/templates/email/site_member_removed.html.eex
index 1634b7dcf..eacdb5dff 100644
--- a/lib/plausible_web/templates/email/site_member_removed.html.eex
+++ b/lib/plausible_web/templates/email/site_member_removed.html.eex
@@ -1,10 +1,3 @@
-Hey <%= user_salutation(@membership.user) %>,
-
An administrator of <%= @membership.site.domain %> has removed you as a member. You won't be able to see the stats anymore.
<%= link("Click here", to: Routes.site_url(PlausibleWeb.Endpoint, :index)) %> to view your sites.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/site_setup_help_email.html.eex b/lib/plausible_web/templates/email/site_setup_help_email.html.eex
index 0f4b2b0a3..a49b55912 100644
--- a/lib/plausible_web/templates/email/site_setup_help_email.html.eex
+++ b/lib/plausible_web/templates/email/site_setup_help_email.html.eex
@@ -1,5 +1,3 @@
-Hey <%= user_salutation(@user) %>,
-
<%= if Plausible.Billing.on_trial?(@user) do %>
You signed up for a free 30-day trial of Plausible, a simple and privacy-friendly website analytics tool.
@@ -9,9 +7,3 @@ To finish your setup for <%= @site.domain %>, you need to install <%= link("this
This Plausible script is 45 times smaller than Google Analytics script so you’ll have a fast loading site while getting all the important traffic insights on one single page.
Do reply back to this email if you have any questions or need some guidance.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
-{{{ pm:unsubscribe }}}
diff --git a/lib/plausible_web/templates/email/site_setup_success_email.html.eex b/lib/plausible_web/templates/email/site_setup_success_email.html.eex
index 0bf6b8654..fed91eabc 100644
--- a/lib/plausible_web/templates/email/site_setup_success_email.html.eex
+++ b/lib/plausible_web/templates/email/site_setup_success_email.html.eex
@@ -1,5 +1,3 @@
-Hey <%= user_salutation(@user) %>,
-
Congrats! The Plausible script has been installed correctly on <%= link(@site.domain, to: "https://#{@site.domain}") %>. Your website traffic is now being tracked without compromising the user experience and the privacy of your visitors.
<%= link("Check your stats", to: "#{plausible_url()}/#{URI.encode_www_form(@site.domain)}") %>
@@ -11,9 +9,3 @@ Congrats! The Plausible script has been installed correctly on <%= link(@site.do
PS: You can import your historical Google Analytics (Universal Analytics) stats into your Plausible dashboard. <%= link("Learn how our GA importer works", to: "https://plausible.io/docs/google-analytics-import") %>.
Do reply back to this email if you have any questions.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
-{{{ pm:unsubscribe }}}
diff --git a/lib/plausible_web/templates/email/spike_notification.html.eex b/lib/plausible_web/templates/email/spike_notification.html.eex
index 47a9f27a8..1b7b031d8 100644
--- a/lib/plausible_web/templates/email/spike_notification.html.eex
+++ b/lib/plausible_web/templates/email/spike_notification.html.eex
@@ -10,9 +10,8 @@ There are currently <%= @current_visitors %> visitors on <%= link(@site.domain,
<%= if @link do %>
-View dashboard: @link
+View dashboard: <%= link(@link, to: @link) %>
<% end %>
---
-
-<%= plausible_url() %>
+
+Congrats on the spike in traffic!
diff --git a/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex b/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex
index b28a4015a..740880955 100644
--- a/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex
+++ b/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex
@@ -1,15 +1,7 @@
-Hey <%= user_salutation(@user) %>,
-
Time flies! Your 30-day free trial of Plausible will end next week.
-Over the last three weeks, I hope you got to experience the potential benefits of having website stats in a simple dashboard while respecting the privacy of your visitors, not annoying them with the cookie and privacy notices and still having a fast loading site.
+Over the last three weeks, We hope you got to experience the potential benefits of having website stats in a simple dashboard while respecting the privacy of your visitors, not annoying them with the cookie and privacy notices and still having a fast loading site.
In order to continue receiving valuable website traffic insights at a glance, you’ll need to <%= link("Upgrade your account", to: "#{plausible_url()}/billing/upgrade") %>.
-If you have any questions or feedback for me, feel free to reply to this email.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
-{{{ pm:unsubscribe }}}
+If you have any questions or feedback for us, feel free to reply to this email.
diff --git a/lib/plausible_web/templates/email/trial_over_email.html.eex b/lib/plausible_web/templates/email/trial_over_email.html.eex
index 03148de0b..7c8981b8f 100644
--- a/lib/plausible_web/templates/email/trial_over_email.html.eex
+++ b/lib/plausible_web/templates/email/trial_over_email.html.eex
@@ -1,15 +1,6 @@
-Hey <%= user_salutation(@user) %>,
-
Your free Plausible trial has now expired. Upgrade your account to continue receiving valuable website traffic insights at a glance while respecting the privacy of your visitors and still having a fast loading site.
<%= link("Upgrade now", to: "#{plausible_url()}/billing/upgrade") %>
We will keep recording stats for another month to give you time to upgrade.
-
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
-{{{ pm:unsubscribe }}}
diff --git a/lib/plausible_web/templates/email/trial_upgrade_email.html.eex b/lib/plausible_web/templates/email/trial_upgrade_email.html.eex
index 1c1dd960f..5f6ce642b 100644
--- a/lib/plausible_web/templates/email/trial_upgrade_email.html.eex
+++ b/lib/plausible_web/templates/email/trial_upgrade_email.html.eex
@@ -1,5 +1,3 @@
-Hey <%= user_salutation(@user) %>,
-
Thanks for exploring Plausible, a simple and privacy-friendly alternative to Google Analytics. Your free 30-day trial is ending <%= @day %>, but you can keep using Plausible by upgrading to a paid plan.
In the last month, your account has used <%= PlausibleWeb.AuthView.delimit_integer(@usage) %> billable pageviews<%= if @custom_events > 0, do: " and custom events in total", else: "" %>.
@@ -12,9 +10,3 @@ Have a question, feedback or need some guidance? Just reply to this email to get
<% else %>
This is more than our standard plans, so please reply back to this email to get a quote for your volume.
<% end %>
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
-{{{ pm:unsubscribe }}}
diff --git a/lib/plausible_web/templates/email/welcome_email.html.eex b/lib/plausible_web/templates/email/welcome_email.html.eex
index 044290e2d..785d7c71d 100644
--- a/lib/plausible_web/templates/email/welcome_email.html.eex
+++ b/lib/plausible_web/templates/email/welcome_email.html.eex
@@ -1,5 +1,3 @@
-Hey <%= user_salutation(@user) %>,
-
We are building Plausible to provide a simple and ethical approach to tracking website visitors.
We're super excited to have you on board!
@@ -15,11 +13,3 @@ Here's how to get the most out of your Plausible experience:
Then you're ready to start exploring your fast loading, ethical and actionable <%= link("Plausible dashboard", to: "https://plausible.io/sites") %>.
Have a question, feedback or need some guidance? Do reply back to this email.
-
-Thanks,
-Uku and Marko
-
---
-
-<%= plausible_url() %>
-{{{ pm:unsubscribe }}}
diff --git a/lib/plausible_web/templates/email/yearly_expiration_notification.html.eex b/lib/plausible_web/templates/email/yearly_expiration_notification.html.eex
index d3103dc35..6a4009c10 100644
--- a/lib/plausible_web/templates/email/yearly_expiration_notification.html.eex
+++ b/lib/plausible_web/templates/email/yearly_expiration_notification.html.eex
@@ -1,5 +1,3 @@
-Hey <%= user_salutation(@user) %>,
-
Time flies! This is a reminder that your annual subscription for Plausible Analytics will expire on <%= @date %>.
You need to renew your subscription on <%= link("account settings page", to: "#{plausible_url()}/billing/upgrade") %> if you want to continue using Plausible to count your website stats in a privacy-friendly way.
@@ -7,8 +5,3 @@ You need to renew your subscription on <%= link("account settings page", to: "#{
If you don't want to continue your subscription, there's no action required. You will lose access to the stats on <%= @date %>.
Have a question, feedback or need some guidance? Just reply to this email to get in touch!
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
diff --git a/lib/plausible_web/templates/email/yearly_renewal_notification.html.eex b/lib/plausible_web/templates/email/yearly_renewal_notification.html.eex
index b08c45efd..879e52491 100644
--- a/lib/plausible_web/templates/email/yearly_renewal_notification.html.eex
+++ b/lib/plausible_web/templates/email/yearly_renewal_notification.html.eex
@@ -1,5 +1,3 @@
-Hey <%= user_salutation(@user) %>,
-
Time flies! This is a reminder that your annual subscription for Plausible Analytics is due to renew on <%= @date %>. We will automatically charge <%= PlausibleWeb.BillingView.present_currency(@currency) %><%= @next_bill_amount %> from your preferred billing method.
There's no action required if you're happy to continue using Plausible to count your website stats in a privacy-friendly way.
@@ -7,8 +5,3 @@ There's no action required if you're happy to continue using Plausible to count
If you don't want to continue your subscription, you can cancel it on your <%= link("account settings page", to: "#{plausible_url()}/settings") %>.
Have a question, feedback or need some guidance? Do reply back to this email.
-
-Thanks,
-Uku and Marko
---
-<%= plausible_url() %>
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 000000000..5fd940ad9
--- /dev/null
+++ b/lib/plausible_web/templates/layout/base_email.html.eex
@@ -0,0 +1,17 @@
+<%= PlausibleWeb.EmailView.greet_recipient(assigns) %>
+
+
+<%= @inner_content %>
+
+
+Regards,
+The Plausible Team 💌
+
+
+--
+
+<%= link(plausible_url(), to: plausible_url()) %>
+
+<%= if Map.get(assigns, :unsubscribe, false) do %>
+{{{ pm:unsubscribe }}}
+<% end %>
diff --git a/lib/plausible_web/views/email_view.ex b/lib/plausible_web/views/email_view.ex
index ac45f7472..ccff31964 100644
--- a/lib/plausible_web/views/email_view.ex
+++ b/lib/plausible_web/views/email_view.ex
@@ -9,14 +9,12 @@ defmodule PlausibleWeb.EmailView do
PlausibleWeb.Endpoint.host()
end
- def user_salutation(user) do
- if user.name do
- String.split(user.name) |> List.first()
- else
- ""
- end
+ def greet_recipient(%{user: %{name: name}}) when is_binary(name) do
+ "Hey #{String.split(name) |> List.first()},"
end
+ def greet_recipient(_), do: "Hey,"
+
def date_format(date) do
Timex.format!(date, "{D} {Mshort} {YYYY}")
end
diff --git a/lib/workers/spike_notifier.ex b/lib/workers/spike_notifier.ex
index ddd0331b1..4e0b0c410 100644
--- a/lib/workers/spike_notifier.ex
+++ b/lib/workers/spike_notifier.ex
@@ -31,7 +31,7 @@ defmodule Plausible.Workers.SpikeNotifier do
:ok
end
- def notify(notification, current_visitors, sources) do
+ defp notify(notification, current_visitors, sources) do
for recipient <- notification.recipients do
send_notification(recipient, notification.site, current_visitors, sources)
end
@@ -45,7 +45,7 @@ defmodule Plausible.Workers.SpikeNotifier do
site = Repo.preload(site, :members)
dashboard_link =
- if Enum.member?(site.members, recipient) do
+ if Enum.any?(site.members, &(&1.email == recipient)) do
PlausibleWeb.Endpoint.url() <> "/" <> URI.encode_www_form(site.domain)
end
diff --git a/test/plausible_web/email_test.exs b/test/plausible_web/email_test.exs
new file mode 100644
index 000000000..578d8c386
--- /dev/null
+++ b/test/plausible_web/email_test.exs
@@ -0,0 +1,68 @@
+defmodule PlausibleWeb.EmailTest do
+ alias PlausibleWeb.Email
+ use ExUnit.Case, async: true
+ import Plausible.Factory
+
+ describe "base_email layout" do
+ test "greets user by first name if user in template assigns" do
+ email =
+ Email.base_email()
+ |> Email.render("activation_email.html", %{
+ user: build(:user, name: "John Doe"),
+ code: "123"
+ })
+
+ assert email.html_body =~ "Hey John,"
+ end
+
+ test "greets impersonally when user not in template assigns" do
+ email =
+ Email.base_email()
+ |> Email.render("password_reset_email.html", %{
+ reset_link: "imaginary"
+ })
+
+ assert email.html_body =~ "Hey,"
+ end
+
+ test "renders plausible link" do
+ email =
+ Email.base_email()
+ |> Email.render("cancellation_email.html")
+
+ assert email.html_body =~ plausible_link()
+ end
+
+ test "does not render unsubscribe placeholder by default" do
+ email =
+ Email.base_email()
+ |> Email.render("welcome_email.html")
+
+ refute email.html_body =~ "{{{ pm:unsubscribe }}}"
+ end
+
+ test "renders unsubscribe placeholder if told" do
+ email =
+ Email.base_email()
+ |> Email.render("welcome_email.html", %{unsubscribe: true})
+
+ assert email.html_body =~ "{{{ pm:unsubscribe }}}"
+ end
+
+ test "can be disabled with a nil layout" do
+ email =
+ Email.base_email(%{layout: nil})
+ |> Email.render("welcome_email.html", %{
+ user: build(:user, name: "John Doe")
+ })
+
+ refute email.html_body =~ "Hey John,"
+ refute email.html_body =~ plausible_link()
+ end
+ end
+
+ def plausible_link() do
+ plausible_url = PlausibleWeb.EmailView.plausible_url()
+ "#{plausible_url}"
+ end
+end
diff --git a/test/plausible_web/views/email_view_test.exs b/test/plausible_web/views/email_view_test.exs
deleted file mode 100644
index 37521055d..000000000
--- a/test/plausible_web/views/email_view_test.exs
+++ /dev/null
@@ -1,16 +0,0 @@
-defmodule PlausibleWeb.EmailViewTest do
- use PlausibleWeb.ConnCase, async: true
- alias PlausibleWeb.EmailView
-
- describe "user salutation" do
- test "picks first name if full name has two parts" do
- user1 = %Plausible.Auth.User{name: "Jane"}
- user2 = %Plausible.Auth.User{name: "Jane Doe"}
- user3 = %Plausible.Auth.User{name: "Jane Alice Doe"}
-
- assert EmailView.user_salutation(user1) == "Jane"
- assert EmailView.user_salutation(user2) == "Jane"
- assert EmailView.user_salutation(user3) == "Jane"
- end
- end
-end
diff --git a/test/workers/spike_notifier_test.exs b/test/workers/spike_notifier_test.exs
index 5dbea18e0..dea8f6fc9 100644
--- a/test/workers/spike_notifier_test.exs
+++ b/test/workers/spike_notifier_test.exs
@@ -85,4 +85,18 @@ defmodule Plausible.Workers.SpikeNotifierTest do
assert_no_emails_delivered()
end
+
+ test "adds a dashboard link if recipient has access to the site" do
+ user = insert(:user, email: "robert@example.com")
+ site = insert(:site, domain: "example.com", members: [user])
+ insert(:spike_notification, site: site, threshold: 10, recipients: ["robert@example.com"])
+
+ clickhouse_stub =
+ stub(Plausible.Stats.Clickhouse, :current_visitors, fn _site, _query -> 10 end)
+ |> stub(:top_sources, fn _site, _query, _limit, _page, _show_noref -> [] end)
+
+ SpikeNotifier.perform(nil, clickhouse_stub)
+
+ assert_email_delivered_with(html_body: ~r/View dashboard: