2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.Email do
|
|
|
|
use Bamboo.Phoenix, view: PlausibleWeb.EmailView
|
|
|
|
import Bamboo.PostmarkHelper
|
|
|
|
|
2020-05-26 16:09:34 +03:00
|
|
|
def mailer_email_from do
|
|
|
|
Application.get_env(:plausible, :mailer_email)
|
|
|
|
end
|
|
|
|
|
2020-12-15 12:30:45 +03:00
|
|
|
def activation_email(user, code) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2020-12-15 12:30:45 +03:00
|
|
|
|> to(user)
|
2020-03-23 12:34:25 +03:00
|
|
|
|> tag("activation-email")
|
2020-12-15 12:30:45 +03:00
|
|
|
|> subject("#{code} is your Plausible email verification code")
|
|
|
|
|> render("activation_email.html", user: user, code: code)
|
2020-03-23 12:34:25 +03:00
|
|
|
end
|
2020-12-29 16:17:27 +03:00
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
def welcome_email(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("welcome-email")
|
2020-03-23 12:34:25 +03:00
|
|
|
|> subject("Welcome to Plausible")
|
2019-09-02 14:29:19 +03:00
|
|
|
|> render("welcome_email.html", user: user)
|
|
|
|
end
|
|
|
|
|
2020-03-23 12:34:25 +03:00
|
|
|
def create_site_email(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2020-03-23 12:34:25 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("create-site-email")
|
|
|
|
|> subject("Your Plausible setup: Add your website details")
|
|
|
|
|> render("create_site_email.html", user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def site_setup_help(user, site) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("help-email")
|
2020-03-23 12:34:25 +03:00
|
|
|
|> subject("Your Plausible setup: Waiting for the first page views")
|
|
|
|
|> render("site_setup_help_email.html", user: user, site: site)
|
|
|
|
end
|
|
|
|
|
|
|
|
def site_setup_success(user, site) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2020-03-23 12:34:25 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("setup-success-email")
|
|
|
|
|> subject("Plausible is now tracking your website stats")
|
|
|
|
|> render("site_setup_success_email.html", user: user, site: site)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_stats_email(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2020-03-23 12:34:25 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("check-stats-email")
|
|
|
|
|> subject("Check your Plausible website stats")
|
|
|
|
|> render("check_stats_email.html", user: user)
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def password_reset_email(email, reset_link) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(email)
|
|
|
|
|> tag("password-reset-email")
|
|
|
|
|> subject("Plausible password reset")
|
|
|
|
|> render("password_reset_email.html", reset_link: reset_link)
|
|
|
|
end
|
|
|
|
|
2020-03-23 12:34:25 +03:00
|
|
|
def trial_one_week_reminder(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
2020-03-23 12:34:25 +03:00
|
|
|
|> tag("trial-one-week-reminder")
|
2020-03-24 16:29:44 +03:00
|
|
|
|> subject("Your Plausible trial expires next week")
|
2020-03-23 12:34:25 +03:00
|
|
|
|> render("trial_one_week_reminder.html", user: user)
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
2021-01-15 17:28:57 +03:00
|
|
|
def trial_upgrade_email(user, day, {pageviews, custom_events}) do
|
2021-05-06 11:46:22 +03:00
|
|
|
suggested_plan = Plausible.Billing.Plans.suggested_plan(user, pageviews + custom_events)
|
|
|
|
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("trial-upgrade-email")
|
|
|
|
|> subject("Your Plausible trial ends #{day}")
|
2021-01-15 17:28:57 +03:00
|
|
|
|> render("trial_upgrade_email.html",
|
|
|
|
user: user,
|
|
|
|
day: day,
|
|
|
|
custom_events: custom_events,
|
2021-05-06 11:46:22 +03:00
|
|
|
usage: pageviews + custom_events,
|
|
|
|
suggested_plan: suggested_plan
|
2021-01-15 17:28:57 +03:00
|
|
|
)
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def trial_over_email(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("trial-over-email")
|
|
|
|
|> subject("Your Plausible trial has ended")
|
|
|
|
|> render("trial_over_email.html", user: user)
|
|
|
|
end
|
|
|
|
|
2019-09-05 19:11:07 +03:00
|
|
|
def weekly_report(email, site, assigns) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-05 19:11:07 +03:00
|
|
|
|> to(email)
|
|
|
|
|> tag("weekly-report")
|
2020-01-22 12:16:53 +03:00
|
|
|
|> subject("#{assigns[:name]} report for #{site.domain}")
|
2019-09-05 19:11:07 +03:00
|
|
|
|> render("weekly_report.html", Keyword.put(assigns, :site, site))
|
|
|
|
end
|
2020-05-11 14:27:20 +03:00
|
|
|
|
2020-12-11 12:50:44 +03:00
|
|
|
def spike_notification(email, site, current_visitors, sources, dashboard_link) do
|
2020-12-09 12:00:14 +03:00
|
|
|
base_email()
|
|
|
|
|> to(email)
|
|
|
|
|> tag("spike-notification")
|
|
|
|
|> subject("Traffic spike on #{site.domain}")
|
2020-12-29 16:17:27 +03:00
|
|
|
|> render("spike_notification.html", %{
|
|
|
|
site: site,
|
|
|
|
current_visitors: current_visitors,
|
|
|
|
sources: sources,
|
|
|
|
link: dashboard_link
|
|
|
|
})
|
2020-12-09 12:00:14 +03:00
|
|
|
end
|
|
|
|
|
2021-05-06 11:46:22 +03:00
|
|
|
def over_limit_email(user, usage, last_cycle, suggested_plan) do
|
2021-02-12 11:17:53 +03:00
|
|
|
base_email()
|
2021-03-01 11:11:49 +03:00
|
|
|
|> to(user)
|
2021-02-12 11:17:53 +03:00
|
|
|
|> tag("over-limit")
|
2021-10-20 17:49:11 +03:00
|
|
|
|> subject("You have outgrown your Plausible subscription tier")
|
2021-02-12 11:17:53 +03:00
|
|
|
|> render("over_limit.html", %{
|
|
|
|
user: user,
|
2021-02-18 16:46:58 +03:00
|
|
|
usage: usage,
|
2021-05-06 11:46:22 +03:00
|
|
|
last_cycle: last_cycle,
|
|
|
|
suggested_plan: suggested_plan
|
2021-02-12 11:17:53 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2021-10-20 17:49:11 +03:00
|
|
|
def enterprise_over_limit_email(user, usage, last_cycle) do
|
|
|
|
base_email()
|
|
|
|
|> to("enterprise@plausible.io")
|
|
|
|
|> tag("enterprise-over-limit")
|
|
|
|
|> subject("#{user.email} has outgrown their enterprise plan")
|
|
|
|
|> render("enterprise_over_limit.html", %{
|
|
|
|
user: user,
|
|
|
|
usage: usage,
|
|
|
|
last_cycle: last_cycle
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2021-04-21 15:57:38 +03:00
|
|
|
def yearly_renewal_notification(user) do
|
|
|
|
date = Timex.format!(user.subscription.next_bill_date, "{Mfull} {D}, {YYYY}")
|
|
|
|
|
|
|
|
base_email()
|
|
|
|
|> to(user)
|
|
|
|
|> tag("yearly-renewal")
|
|
|
|
|> subject("Your Plausible subscription is up for renewal")
|
|
|
|
|> render("yearly_renewal_notification.html", %{
|
|
|
|
user: user,
|
|
|
|
date: date,
|
2021-05-13 12:42:01 +03:00
|
|
|
next_bill_amount: user.subscription.next_bill_amount,
|
|
|
|
currency: user.subscription.currency_code
|
2021-04-21 15:57:38 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def yearly_expiration_notification(user) do
|
|
|
|
date = Timex.format!(user.subscription.next_bill_date, "{Mfull} {D}, {YYYY}")
|
|
|
|
|
|
|
|
base_email()
|
|
|
|
|> to(user)
|
|
|
|
|> tag("yearly-expiration")
|
|
|
|
|> subject("Your Plausible subscription is about to expire")
|
|
|
|
|> render("yearly_expiration_notification.html", %{
|
|
|
|
user: user,
|
2021-05-13 12:42:01 +03:00
|
|
|
date: date
|
2021-04-21 15:57:38 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2020-09-18 15:35:21 +03:00
|
|
|
def cancellation_email(user) do
|
|
|
|
base_email()
|
|
|
|
|> to(user.email)
|
|
|
|
|> tag("cancelled-email")
|
|
|
|
|> subject("Your Plausible Analytics subscription has been canceled")
|
|
|
|
|> render("cancellation_email.html", name: user.name)
|
|
|
|
end
|
|
|
|
|
2021-06-16 15:00:07 +03:00
|
|
|
def new_user_invitation(invitation) do
|
|
|
|
base_email()
|
|
|
|
|> to(invitation.email)
|
|
|
|
|> tag("new-user-invitation")
|
|
|
|
|> subject("[Plausible Analytics] You've been invited to #{invitation.site.domain}")
|
|
|
|
|> render("new_user_invitation.html",
|
|
|
|
invitation: invitation
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def existing_user_invitation(invitation) do
|
|
|
|
base_email()
|
|
|
|
|> to(invitation.email)
|
|
|
|
|> tag("existing-user-invitation")
|
|
|
|
|> subject("[Plausible Analytics] You've been invited to #{invitation.site.domain}")
|
|
|
|
|> render("existing_user_invitation.html",
|
|
|
|
invitation: invitation
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ownership_transfer_request(invitation, new_owner_account) do
|
|
|
|
base_email()
|
|
|
|
|> to(invitation.email)
|
|
|
|
|> tag("ownership-transfer-request")
|
|
|
|
|> subject("[Plausible Analytics] Request to transfer ownership of #{invitation.site.domain}")
|
|
|
|
|> render("ownership_transfer_request.html",
|
|
|
|
invitation: invitation,
|
|
|
|
new_owner_account: new_owner_account
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def invitation_accepted(invitation) do
|
|
|
|
base_email()
|
|
|
|
|> to(invitation.inviter.email)
|
|
|
|
|> tag("invitation-accepted")
|
|
|
|
|> subject(
|
2021-09-09 11:17:24 +03:00
|
|
|
"[Plausible Analytics] #{invitation.email} accepted your invitation to #{invitation.site.domain}"
|
2021-06-16 15:00:07 +03:00
|
|
|
)
|
|
|
|
|> render("invitation_accepted.html",
|
|
|
|
invitation: invitation
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def invitation_rejected(invitation) do
|
|
|
|
base_email()
|
|
|
|
|> to(invitation.inviter.email)
|
|
|
|
|> tag("invitation-rejected")
|
|
|
|
|> subject(
|
2021-09-09 11:17:24 +03:00
|
|
|
"[Plausible Analytics] #{invitation.email} rejected your invitation to #{invitation.site.domain}"
|
2021-06-16 15:00:07 +03:00
|
|
|
)
|
|
|
|
|> render("invitation_rejected.html",
|
|
|
|
invitation: invitation
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ownership_transfer_accepted(invitation) do
|
|
|
|
base_email()
|
|
|
|
|> to(invitation.inviter.email)
|
|
|
|
|> tag("ownership-transfer-accepted")
|
|
|
|
|> subject(
|
2021-09-09 11:17:24 +03:00
|
|
|
"[Plausible Analytics] #{invitation.email} accepted the ownership transfer of #{invitation.site.domain}"
|
2021-06-16 15:00:07 +03:00
|
|
|
)
|
|
|
|
|> render("ownership_transfer_accepted.html",
|
|
|
|
invitation: invitation
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ownership_transfer_rejected(invitation) do
|
|
|
|
base_email()
|
|
|
|
|> to(invitation.inviter.email)
|
|
|
|
|> tag("ownership-transfer-rejected")
|
|
|
|
|> subject(
|
2021-09-09 11:17:24 +03:00
|
|
|
"[Plausible Analytics] #{invitation.email} rejected the ownership transfer of #{invitation.site.domain}"
|
2021-06-16 15:00:07 +03:00
|
|
|
)
|
|
|
|
|> render("ownership_transfer_rejected.html",
|
|
|
|
invitation: invitation
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def site_member_removed(membership) do
|
|
|
|
base_email()
|
|
|
|
|> to(membership.user.email)
|
|
|
|
|> tag("site-member-removed")
|
|
|
|
|> subject("[Plausible Analytics] Your access to #{membership.site.domain} has been revoked")
|
|
|
|
|> render("site_member_removed.html",
|
|
|
|
membership: membership
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-05-11 14:27:20 +03:00
|
|
|
defp base_email() do
|
2020-09-18 15:35:21 +03:00
|
|
|
mailer_from = Application.get_env(:plausible, :mailer_email)
|
|
|
|
|
2020-05-11 14:27:20 +03:00
|
|
|
new_email()
|
|
|
|
|> put_param("TrackOpens", false)
|
2020-09-18 15:35:21 +03:00
|
|
|
|> from(mailer_from)
|
2020-05-11 14:27:20 +03:00
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|