Email flows (#46)
* Update activation email * Update trial upgrade emails * Remove feedback emails * Remove feedback email test * Update welcome email (and send it earlier) * Site setup emails * Add create site emails for trialers * Add check stats email * Remove dead code * Adjust site setup emails for users who are not on trial * BCC myself on all new emails * Use old phrasing in the welcome emailpull/44/head
parent
e3373724c7
commit
ee92ed5213
@ -0,0 +1,46 @@
|
||||
defmodule Mix.Tasks.SendCheckStatsEmails do
|
||||
use Mix.Task
|
||||
use Plausible.Repo
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
This is scheduled to run every 6 hours.
|
||||
"""
|
||||
|
||||
def run(args) do
|
||||
Application.ensure_all_started(:plausible)
|
||||
execute(args)
|
||||
end
|
||||
|
||||
def execute(args \\ []) do
|
||||
q =
|
||||
from(u in Plausible.Auth.User,
|
||||
left_join: ce in "check_stats_emails", on: ce.user_id == u.id,
|
||||
where: is_nil(ce.id),
|
||||
where:
|
||||
u.inserted_at > fragment("(now() at time zone 'utc') - '14 days'::interval") and
|
||||
u.inserted_at < fragment("(now() at time zone 'utc') - '7 days'::interval") and
|
||||
u.last_seen < fragment("(now() at time zone 'utc') - '7 days'::interval")
|
||||
)
|
||||
|
||||
for user <- Repo.all(q) do
|
||||
if Plausible.Auth.user_completed_setup?(user) do
|
||||
send_check_stats_email(args, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp send_check_stats_email(["--dry-run"], user) do
|
||||
Logger.info("DRY RUN: check stats email to #{user.name}")
|
||||
end
|
||||
|
||||
defp send_check_stats_email(_, user) do
|
||||
PlausibleWeb.Email.check_stats_email(user)
|
||||
|> Plausible.Mailer.deliver_now()
|
||||
|
||||
Repo.insert_all("check_stats_emails", [%{
|
||||
user_id: user.id,
|
||||
timestamp: NaiveDateTime.utc_now()
|
||||
}])
|
||||
end
|
||||
end
|
||||
@ -1,48 +0,0 @@
|
||||
defmodule Mix.Tasks.SendFeedbackEmails do
|
||||
use Mix.Task
|
||||
use Plausible.Repo
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
This is scheduled to run every 6 hours.
|
||||
"""
|
||||
|
||||
def run(args) do
|
||||
Application.ensure_all_started(:plausible)
|
||||
execute(args)
|
||||
end
|
||||
|
||||
def execute(args \\ []) do
|
||||
q =
|
||||
from(u in Plausible.Auth.User,
|
||||
left_join: fe in "feedback_emails", on: fe.user_id == u.id,
|
||||
where: is_nil(fe.id),
|
||||
where: u.inserted_at < fragment("(now() at time zone 'utc') - '30 days'::interval"),
|
||||
where: u.last_seen > fragment("now() at time zone 'utc' - '7 days'::interval")
|
||||
)
|
||||
|
||||
for user <- Repo.all(q) do
|
||||
if Plausible.Auth.user_completed_setup?(user) do
|
||||
send_feedback_email(args, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp send_feedback_email(["--dry-run"], user) do
|
||||
Logger.info("DRY RUN: feedback survey email to #{user.name}")
|
||||
end
|
||||
|
||||
defp send_feedback_email(_, user) do
|
||||
PlausibleWeb.Email.feedback_survey_email(user)
|
||||
|> Plausible.Mailer.deliver_now()
|
||||
|
||||
feedback_email_sent(user)
|
||||
end
|
||||
|
||||
defp feedback_email_sent(user) do
|
||||
Repo.insert_all("feedback_emails", [%{
|
||||
user_id: user.id,
|
||||
timestamp: NaiveDateTime.utc_now()
|
||||
}])
|
||||
end
|
||||
end
|
||||
@ -1,64 +0,0 @@
|
||||
defmodule Mix.Tasks.SendIntroEmails do
|
||||
use Mix.Task
|
||||
use Plausible.Repo
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
This is scheduled to run every 6 hours.
|
||||
"""
|
||||
|
||||
def run(args) do
|
||||
Application.ensure_all_started(:plausible)
|
||||
execute(args)
|
||||
end
|
||||
|
||||
def execute(args \\ []) do
|
||||
q =
|
||||
from(u in Plausible.Auth.User,
|
||||
left_join: ie in "intro_emails", on: ie.user_id == u.id,
|
||||
where: is_nil(ie.id),
|
||||
where:
|
||||
u.inserted_at > fragment("(now() at time zone 'utc') - '24 hours'::interval") and
|
||||
u.inserted_at < fragment("(now() at time zone 'utc') - '6 hours'::interval")
|
||||
)
|
||||
|
||||
for user <- Repo.all(q) do
|
||||
if Plausible.Auth.user_completed_setup?(user) do
|
||||
Logger.info("#{user.name} has completed the setup. Sending welcome email.")
|
||||
send_welcome_email(args, user)
|
||||
else
|
||||
Logger.info("#{user.name} has not completed the setup. Sending help email.")
|
||||
send_help_email(args, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp send_welcome_email(["--dry-run"], user) do
|
||||
Logger.info("DRY RUN: welcome email to #{user.name}")
|
||||
end
|
||||
|
||||
defp send_welcome_email(_, user) do
|
||||
PlausibleWeb.Email.welcome_email(user)
|
||||
|> Plausible.Mailer.deliver_now()
|
||||
|
||||
intro_email_sent(user)
|
||||
end
|
||||
|
||||
defp send_help_email(["--dry-run"], user) do
|
||||
Logger.info("DRY RUN: help email to #{user.name}")
|
||||
end
|
||||
|
||||
defp send_help_email(_, user) do
|
||||
PlausibleWeb.Email.help_email(user)
|
||||
|> Plausible.Mailer.deliver_now()
|
||||
|
||||
intro_email_sent(user)
|
||||
end
|
||||
|
||||
defp intro_email_sent(user) do
|
||||
Repo.insert_all("intro_emails", [%{
|
||||
user_id: user.id,
|
||||
timestamp: NaiveDateTime.utc_now()
|
||||
}])
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,117 @@
|
||||
defmodule Mix.Tasks.SendSiteSetupEmails do
|
||||
use Mix.Task
|
||||
use Plausible.Repo
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
This is scheduled to run every 6 hours.
|
||||
"""
|
||||
|
||||
def run(args) do
|
||||
Application.ensure_all_started(:plausible)
|
||||
execute(args)
|
||||
end
|
||||
|
||||
def execute(args \\ []) do
|
||||
send_create_site_emails(args)
|
||||
send_setup_help_emails(args)
|
||||
send_setup_success_emails(args)
|
||||
end
|
||||
|
||||
defp send_create_site_emails(args) do
|
||||
q =
|
||||
from(s in Plausible.Auth.User,
|
||||
left_join: se in "create_site_emails", on: se.user_id == s.id,
|
||||
where: is_nil(se.id),
|
||||
where: s.inserted_at > fragment("(now() at time zone 'utc') - '72 hours'::interval") and s.inserted_at < fragment("(now() at time zone 'utc') - '48 hours'::interval"),
|
||||
preload: :sites
|
||||
)
|
||||
|
||||
for user <- Repo.all(q) do
|
||||
if Enum.count(user.sites) == 0 do
|
||||
send_create_site_email(args, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp send_setup_help_emails(args) do
|
||||
q =
|
||||
from(s in Plausible.Site,
|
||||
left_join: se in "setup_help_emails", on: se.site_id == s.id,
|
||||
where: is_nil(se.id),
|
||||
where: s.inserted_at > fragment("(now() at time zone 'utc') - '72 hours'::interval"),
|
||||
preload: :members
|
||||
)
|
||||
|
||||
for site <- Repo.all(q) do
|
||||
owner = List.first(site.members)
|
||||
|
||||
setup_completed = Plausible.Sites.has_pageviews?(site)
|
||||
hours_passed = Timex.diff(Timex.now(), site.inserted_at, :hours)
|
||||
|
||||
if !setup_completed && hours_passed > 47 do
|
||||
send_setup_help_email(args, owner, site)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp send_setup_success_emails(args) do
|
||||
q =
|
||||
from(s in Plausible.Site,
|
||||
left_join: se in "setup_success_emails", on: se.site_id == s.id,
|
||||
where: is_nil(se.id),
|
||||
where: s.inserted_at > fragment("(now() at time zone 'utc') - '72 hours'::interval"),
|
||||
preload: :members
|
||||
)
|
||||
|
||||
for site <- Repo.all(q) do
|
||||
owner = List.first(site.members)
|
||||
|
||||
if Plausible.Sites.has_pageviews?(site) do
|
||||
send_setup_success_email(args, owner, site)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp send_create_site_email(["--dry-run"], user) do
|
||||
Logger.info("DRY RUN: create site email for #{user.name}")
|
||||
end
|
||||
|
||||
defp send_create_site_email(_, user) do
|
||||
PlausibleWeb.Email.create_site_email(user)
|
||||
|> Plausible.Mailer.deliver_now()
|
||||
|
||||
Repo.insert_all("create_site_emails", [%{
|
||||
user_id: user.id,
|
||||
timestamp: NaiveDateTime.utc_now()
|
||||
}])
|
||||
end
|
||||
|
||||
defp send_setup_success_email(["--dry-run"], _, site) do
|
||||
Logger.info("DRY RUN: setup success email for #{site.domain}")
|
||||
end
|
||||
|
||||
defp send_setup_success_email(_, user, site) do
|
||||
PlausibleWeb.Email.site_setup_success(user, site)
|
||||
|> Plausible.Mailer.deliver_now()
|
||||
|
||||
Repo.insert_all("setup_success_emails", [%{
|
||||
site_id: site.id,
|
||||
timestamp: NaiveDateTime.utc_now()
|
||||
}])
|
||||
end
|
||||
|
||||
defp send_setup_help_email(["--dry-run"], _, site) do
|
||||
Logger.info("DRY RUN: setup help email for #{site.domain}")
|
||||
end
|
||||
|
||||
defp send_setup_help_email(_, user, site) do
|
||||
PlausibleWeb.Email.site_setup_help(user, site)
|
||||
|> Plausible.Mailer.deliver_now()
|
||||
|
||||
Repo.insert_all("setup_help_emails", [%{
|
||||
site_id: site.id,
|
||||
timestamp: NaiveDateTime.utc_now()
|
||||
}])
|
||||
end
|
||||
end
|
||||
@ -1,5 +1,5 @@
|
||||
Hi <%= @name %>,
|
||||
<br /><br />
|
||||
Thank you for signing up to Plausible. <a href="<%= @link %>">Click here</a> to activate your account.
|
||||
Thank you for signing up for the free trial of Plausible, a simple and privacy-friendly alternative to Google Analytics.
|
||||
<br /><br />
|
||||
This link will expire in 24 hours. If you don't use it by then, you can request another activation link.
|
||||
<a href="<%= @link %>">Click here</a> to activate your trial account. This link will expire in 24 hours.
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
Hey <%= user_salutation(@user) %>,
|
||||
<br /><br />
|
||||
Plausible is tracking your website stats without compromising the user experience and the privacy of your visitors.
|
||||
<br /><br />
|
||||
<%= link("View your Plausible dashboard now", to: "https://plausible.io/") %> for the most valuable traffic insights at a glance.
|
||||
<br /><br />
|
||||
Do reply back to this email if you have any questions or need some guidance.
|
||||
<br /></br>
|
||||
Thanks,<br />
|
||||
Uku Taht
|
||||
<br /><br />
|
||||
--
|
||||
<br /><br />
|
||||
https://plausible.io
|
||||
@ -0,0 +1,14 @@
|
||||
Hey <%= user_salutation(@user) %>,
|
||||
<br /><br />
|
||||
You've activated your free 30-day trial of Plausible, a simple and privacy-friendly website analytics tool.
|
||||
<br /><br />
|
||||
<%= link("Click here", to: "https://plausible.io/sites/new") %> to add your website URL, your timezone and install our one-line JavaScript snippet to start collecting visitor statistics.
|
||||
<br /><br />
|
||||
Do reply back to this email if you have any questions or need some guidance.
|
||||
<br /></br>
|
||||
Thanks,<br />
|
||||
Uku Taht
|
||||
<br /><br />
|
||||
--
|
||||
<br /><br />
|
||||
https://plausible.io
|
||||
@ -1,17 +0,0 @@
|
||||
Hey <%= user_salutation(@user) %>,
|
||||
<br /><br />
|
||||
Big thanks for giving Plausible a try at such an early stage.
|
||||
<br /><br />
|
||||
Now that you've had some time to use the product, I'd love to know how it's working for you. I've created a Typeform with 4 quick questions about your experience; it would help a lot if you could fill it out.
|
||||
<br /><br />
|
||||
<%= link("Take the survey", to: "https://plausible.typeform.com/to/szHj56") %>
|
||||
<br /><br />
|
||||
I will use your response to help prioritise the roadmap for the next months. You can request features and let me know about any annoyances/bugs you've encountered. Be completely honest, I can take it :)
|
||||
<br /><br />
|
||||
Thanks,<br />
|
||||
Uku Taht<br />
|
||||
Founder, Plausible Insights
|
||||
<br /><br />
|
||||
--
|
||||
<br /><br />
|
||||
https://plausible.io
|
||||
@ -1,13 +0,0 @@
|
||||
Hey <%= user_salutation(@user) %>,
|
||||
<br /><br />
|
||||
I saw that you signed up for Plausible but the setup isn't working completely. Is there anything I can do to help?
|
||||
<br /><br />
|
||||
If you have any questions let me know.
|
||||
<br /><br />
|
||||
Thanks,<br />
|
||||
Uku Taht<br />
|
||||
Founder, Plausible Insights
|
||||
<br /><br />
|
||||
--
|
||||
<br /><br />
|
||||
https://plausible.io
|
||||
@ -0,0 +1,20 @@
|
||||
Hey <%= user_salutation(@user) %>,
|
||||
<br /><br />
|
||||
Congrats! The Plausible script has been installed correctly on <%= @site.domain %>. Your website traffic is now being tracked without compromising the user experience and the privacy of your visitors.
|
||||
<br /><br />
|
||||
<%= link("Check your stats", to: "https://plausible.io/#{URI.encode_www_form(@site.domain)}") %>
|
||||
<br /><br />
|
||||
<%= if Plausible.Billing.on_trial?(@user) do %>
|
||||
You're on a 30-day unlimited-use free trial with no obligations so do take your time to explore your simple and privacy-friendly website analytics dashboard.
|
||||
<br /><br />
|
||||
<% end %>
|
||||
PS: Plausible is fully open-source and our public roadmap is defined by the community. <%= link("Leave your feedback", to: "https://feedback.plausible.io") %> and have your say on metrics and features we should be adding next.
|
||||
<br /><br />
|
||||
Do reply back to this email if you have any questions.
|
||||
<br /></br>
|
||||
Thanks,<br />
|
||||
Uku Taht
|
||||
<br /><br />
|
||||
--
|
||||
<br /><br />
|
||||
https://plausible.io
|
||||
@ -1,13 +0,0 @@
|
||||
Hey <%= user_salutation(@user) %>,
|
||||
<br /><br />
|
||||
Thank you so much for trying out Plausible!
|
||||
<br /><br />
|
||||
This is your friendly reminder that you have <b>14 days left</b> on your Plausible free trial.
|
||||
<br /><br />
|
||||
I will contact you towards the end of the trial with instructions to upgrade from your free trial to a paid plan.
|
||||
<br /><br />
|
||||
If you have any questions or feedback for me, feel free to reply to this email.
|
||||
<br /><br />
|
||||
Thanks,<br />
|
||||
Uku Taht<br />
|
||||
https://plausible.io
|
||||
@ -0,0 +1,15 @@
|
||||
defmodule Plausible.Repo.Migrations.AddSetupEmails do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:setup_help_emails) do
|
||||
add :site_id, references(:sites), null: false, on_delete: :delete_all
|
||||
add :timestamp, :naive_datetime
|
||||
end
|
||||
|
||||
create table(:setup_success_emails) do
|
||||
add :site_id, references(:sites), null: false, on_delete: :delete_all
|
||||
add :timestamp, :naive_datetime
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,10 @@
|
||||
defmodule Plausible.Repo.Migrations.AddCreateSiteEmails do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:create_site_emails) do
|
||||
add :user_id, references(:users), null: false, on_delete: :delete_all
|
||||
add :timestamp, :naive_datetime
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,10 @@
|
||||
defmodule Plausible.Repo.Migrations.AddCheckStatsEmails do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:check_stats_emails) do
|
||||
add :user_id, references(:users), null: false, on_delete: :delete_all
|
||||
add :timestamp, :naive_datetime
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,43 @@
|
||||
defmodule Mix.Tasks.SendCheckStatsEmailsTest do
|
||||
use Plausible.DataCase
|
||||
use Bamboo.Test
|
||||
|
||||
test "does not send an email before a week has passed" do
|
||||
user = insert(:user, inserted_at: days_ago(6), last_seen: days_ago(6))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
Mix.Tasks.SendCheckStatsEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
|
||||
test "does not send an email if the user has logged in recently" do
|
||||
user = insert(:user, inserted_at: days_ago(9), last_seen: days_ago(6))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
Mix.Tasks.SendCheckStatsEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
|
||||
test "sends an email after a week of signup if the user hasn't logged in" do
|
||||
user = insert(:user, inserted_at: days_ago(8), last_seen: days_ago(8))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
Mix.Tasks.SendCheckStatsEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Check your Plausible website stats"
|
||||
)
|
||||
end
|
||||
|
||||
defp days_ago(days) do
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|> Timex.shift(days: -days)
|
||||
end
|
||||
end
|
||||
@ -1,65 +0,0 @@
|
||||
defmodule Mix.Tasks.SendFeedbackEmailsTest do
|
||||
use Plausible.DataCase
|
||||
use Bamboo.Test
|
||||
alias Mix.Tasks.SendFeedbackEmails
|
||||
|
||||
describe "when user does not have an active site" do
|
||||
test "does not send an email ever" do
|
||||
insert(:user, inserted_at: days_ago(15))
|
||||
|
||||
SendFeedbackEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
end
|
||||
|
||||
describe "when user has an active site" do
|
||||
test "sends an email if the user is more than 30 days old and logged on in the last week" do
|
||||
user = insert(:user, inserted_at: days_ago(31), last_seen: days_ago(1))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
SendFeedbackEmails.execute()
|
||||
|
||||
assert_email_delivered_with(subject: "Plausible feedback")
|
||||
end
|
||||
|
||||
test "sends the email only once" do
|
||||
user = insert(:user, inserted_at: days_ago(31), last_seen: days_ago(1))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
SendFeedbackEmails.execute()
|
||||
assert_email_delivered_with(subject: "Plausible feedback")
|
||||
|
||||
SendFeedbackEmails.execute()
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
|
||||
test "does not send if user has not logged in recently" do
|
||||
user = insert(:user, inserted_at: days_ago(31), last_seen: days_ago(15))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
SendFeedbackEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
|
||||
test "does not send if user is less than a month old" do
|
||||
user = insert(:user, inserted_at: days_ago(15), last_seen: days_ago(1))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
SendFeedbackEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
end
|
||||
|
||||
defp days_ago(days) do
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|> Timex.shift(days: -days)
|
||||
end
|
||||
end
|
||||
@ -1,122 +0,0 @@
|
||||
defmodule Mix.Tasks.SendIntroEmailsTest do
|
||||
use Plausible.DataCase
|
||||
use Bamboo.Test
|
||||
|
||||
describe "when user has not managed to set up a site" do
|
||||
test "does not send an email 5 hours after signup" do
|
||||
_user = insert(:user, inserted_at: hours_ago(5))
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
|
||||
test "sends a setup help email 6 hours after signup" do
|
||||
user = insert(:user, inserted_at: hours_ago(6))
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Your Plausible setup"
|
||||
)
|
||||
end
|
||||
|
||||
test "sends a setup help email 23 hours after signup" do
|
||||
user = insert(:user, inserted_at: hours_ago(23))
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Your Plausible setup"
|
||||
)
|
||||
end
|
||||
|
||||
test "does not send an email 24 hours after signup" do
|
||||
_user = insert(:user, inserted_at: hours_ago(24))
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
end
|
||||
|
||||
describe "when user has managed to set up their first site" do
|
||||
test "does not send an email 5 hours after signup" do
|
||||
_user = insert(:user, inserted_at: hours_ago(5))
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
|
||||
test "sends a setup help email 6 hours after signup if the user has created a site but has not received a pageview yet" do
|
||||
user = insert(:user, inserted_at: hours_ago(6))
|
||||
insert(:site, members: [user])
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Your Plausible setup"
|
||||
)
|
||||
end
|
||||
|
||||
test "sends a welcome email 6 hours after signup if the user has created a site and has received a pageview" do
|
||||
user = insert(:user, inserted_at: hours_ago(6))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Welcome to Plausible :) Plus, a quick question..."
|
||||
)
|
||||
end
|
||||
|
||||
test "sends a welcome email 23 hours after signup" do
|
||||
user = insert(:user, inserted_at: hours_ago(23))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Welcome to Plausible :) Plus, a quick question..."
|
||||
)
|
||||
end
|
||||
|
||||
test "does not send a welcome email 24 hours after signup" do
|
||||
user = insert(:user, inserted_at: hours_ago(24))
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
end
|
||||
|
||||
test "does not send two intro emails to the same person" do
|
||||
user = insert(:user, inserted_at: hours_ago(12))
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
Mix.Tasks.SendIntroEmails.execute()
|
||||
|
||||
assert_delivered_email(PlausibleWeb.Email.help_email(user))
|
||||
refute_delivered_email(PlausibleWeb.Email.welcome_email(user))
|
||||
end
|
||||
|
||||
defp hours_ago(hours) do
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|> Timex.shift(hours: -hours)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,98 @@
|
||||
defmodule Mix.Tasks.SendSiteSetupEmailsTest do
|
||||
use Plausible.DataCase
|
||||
use Bamboo.Test
|
||||
|
||||
describe "when user has not managed to set up the site" do
|
||||
test "does not send an email 47 hours after site creation" do
|
||||
user = insert(:user)
|
||||
insert(:site, members: [user], inserted_at: hours_ago(47))
|
||||
|
||||
Mix.Tasks.SendSiteSetupEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
|
||||
test "sends a setup help email 48 hours after site has been created" do
|
||||
user = insert(:user)
|
||||
insert(:site, members: [user], inserted_at: hours_ago(49))
|
||||
|
||||
Mix.Tasks.SendSiteSetupEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Your Plausible setup: Waiting for the first page views"
|
||||
)
|
||||
end
|
||||
|
||||
test "does not send an email more than 72 hours after signup" do
|
||||
user = insert(:user)
|
||||
insert(:site, members: [user], inserted_at: hours_ago(73))
|
||||
|
||||
Mix.Tasks.SendSiteSetupEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
end
|
||||
|
||||
describe "when user has managed to set up their site" do
|
||||
test "sends the setup completed email as soon as possible" do
|
||||
user = insert(:user)
|
||||
site = insert(:site, members: [user])
|
||||
insert(:pageview, domain: site.domain)
|
||||
|
||||
Mix.Tasks.SendSiteSetupEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Plausible is now tracking your website stats"
|
||||
)
|
||||
end
|
||||
|
||||
test "sends the setup completed email after the help email has been sent" do
|
||||
user = insert(:user)
|
||||
site = insert(:site, members: [user], inserted_at: hours_ago(49))
|
||||
|
||||
Mix.Tasks.SendSiteSetupEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Your Plausible setup: Waiting for the first page views"
|
||||
)
|
||||
|
||||
insert(:pageview, domain: site.domain)
|
||||
Mix.Tasks.SendSiteSetupEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Plausible is now tracking your website stats"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "trial user who has not set up a website" do
|
||||
test "does not send an email before 48h have passed" do
|
||||
insert(:user, inserted_at: hours_ago(47))
|
||||
|
||||
Mix.Tasks.SendSiteSetupEmails.execute()
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
|
||||
test "sends the create site email after 48h" do
|
||||
user = insert(:user, inserted_at: hours_ago(49))
|
||||
|
||||
Mix.Tasks.SendSiteSetupEmails.execute()
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [{user.name, user.email}],
|
||||
subject: "Your Plausible setup: Add your website details"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
defp hours_ago(hours) do
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|> Timex.shift(hours: -hours)
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue