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
Email flows (#46)
Uku Tahtee92ed521352
diff --git a/lib/mix/tasks/send_check_stats_emails.ex b/lib/mix/tasks/send_check_stats_emails.exnew file mode 100644index 0000000000..802da282fc--- /dev/null+++ b/lib/mix/tasks/send_check_stats_emails.ex@@ -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+enddiff --git a/lib/mix/tasks/send_feedback_emails.ex b/lib/mix/tasks/send_feedback_emails.exdeleted file mode 100644index b68e1c085e..0000000000--- a/lib/mix/tasks/send_feedback_emails.ex+++ /dev/null@@ -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-enddiff --git a/lib/mix/tasks/send_intro_emails.ex b/lib/mix/tasks/send_intro_emails.exdeleted file mode 100644index ad9901265a..0000000000--- a/lib/mix/tasks/send_intro_emails.ex+++ /dev/null@@ -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-enddiff --git a/lib/mix/tasks/send_site_setup_emails.ex b/lib/mix/tasks/send_site_setup_emails.exnew file mode 100644index 0000000000..b1cbe0b87f--- /dev/null+++ b/lib/mix/tasks/send_site_setup_emails.ex@@ -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+enddiff --git a/lib/mix/tasks/send_trial_notifications.ex b/lib/mix/tasks/send_trial_notifications.exindex 2d423551e2..4f2bbc28d7 100644--- a/lib/mix/tasks/send_trial_notifications.ex+++ b/lib/mix/tasks/send_trial_notifications.ex@@ -24,9 +24,9 @@ defmodule Mix.Tasks.SendTrialNotifications dofor user <- users docase Timex.diff(user.trial_expiry_date, Timex.today(), :days) do- 14 ->+ 7 ->if Plausible.Auth.user_completed_setup?(user) do- send_two_week_reminder(args, user)+ send_one_week_reminder(args, user)end1 ->if Plausible.Auth.user_completed_setup?(user) do@@ -46,12 +46,12 @@ defmodule Mix.Tasks.SendTrialNotifications doendend- defp send_two_week_reminder(["--dry-run"], user) do- Logger.info("DRY RUN: 2-week trial notification email to #{user.name} [inserted=#{user.inserted_at}]")+ defp send_one_week_reminder(["--dry-run"], user) do+ Logger.info("DRY RUN: one week trial notification email to #{user.name} [inserted=#{user.inserted_at}]")end- defp send_two_week_reminder(_, user) do- PlausibleWeb.Email.trial_two_week_reminder(user)+ defp send_one_week_reminder(_, user) do+ PlausibleWeb.Email.trial_one_week_reminder(user)|> Plausible.Mailer.deliver_now()enddiff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.exindex a8815da36f..2487826deb 100644--- a/lib/plausible/billing/billing.ex+++ b/lib/plausible/billing/billing.ex@@ -83,6 +83,8 @@ defmodule Plausible.Billing doendend+ def on_trial?(user), do: trial_days_left(user) >= 0+def trial_days_left(user) doTimex.diff(user.trial_expiry_date, Timex.today(), :days)enddiff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.exindex 029b3956cf..1250e58e9b 100644--- a/lib/plausible_web/controllers/auth_controller.ex+++ b/lib/plausible_web/controllers/auth_controller.ex@@ -33,6 +33,9 @@ defmodule PlausibleWeb.AuthController do{:ok, %{name: name, email: email}} ->case Auth.create_user(name, email) do{:ok, user} ->+ PlausibleWeb.Email.welcome_email(user)+ |> Plausible.Mailer.deliver_now()+conn|> put_session(:current_user_id, user.id)|> redirect(to: "/password")diff --git a/lib/plausible_web/email.ex b/lib/plausible_web/email.exindex b7c3baf619..1f7ed24c17 100644--- a/lib/plausible_web/email.ex+++ b/lib/plausible_web/email.ex@@ -2,22 +2,63 @@ defmodule PlausibleWeb.Email douse Bamboo.Phoenix, view: PlausibleWeb.EmailViewimport Bamboo.PostmarkHelper+ def activation_email(user, link) do+ new_email()+ |> to(user.email)+ |> from("Uku Taht <[email protected]>")+ |> tag("activation-email")+ |> subject("Activate your Plausible free trial")+ |> render("activation_email.html", name: user.name, link: link)+ end+def welcome_email(user) donew_email()|> to(user)+ |> bcc("[email protected]")|> from("Uku Taht <[email protected]>")|> tag("welcome-email")- |> subject("Welcome to Plausible :) Plus, a quick question...")+ |> subject("Welcome to Plausible")|> render("welcome_email.html", user: user)end- def help_email(user) do+ def create_site_email(user) do+ new_email()+ |> to(user)+ |> bcc("[email protected]")+ |> from("Uku Taht <[email protected]>")+ |> 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) donew_email()|> to(user)+ |> bcc("[email protected]")|> from("Uku Taht <[email protected]>")|> tag("help-email")- |> subject("Your Plausible setup")- |> render("help_email.html", user: user)+ |> 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+ new_email()+ |> to(user)+ |> bcc("[email protected]")+ |> from("Uku Taht <[email protected]>")+ |> 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+ new_email()+ |> to(user)+ |> bcc("[email protected]")+ |> from("Uku Taht <[email protected]>")+ |> tag("check-stats-email")+ |> subject("Check your Plausible website stats")+ |> render("check_stats_email.html", user: user)enddef password_reset_email(email, reset_link) do@@ -29,27 +70,20 @@ defmodule PlausibleWeb.Email do|> render("password_reset_email.html", reset_link: reset_link)end- def activation_email(user, link) do- new_email()- |> to(user.email)- |> from("Uku Taht <[email protected]>")- |> tag("activation-email")- |> subject("Plausible activation link")- |> render("activation_email.html", name: user.name, link: link)- end-- def trial_two_week_reminder(user) do+ def trial_one_week_reminder(user) donew_email()|> to(user)+ |> bcc("[email protected]")|> from("Uku Taht <[email protected]>")- |> tag("trial-two-week-reminder")+ |> tag("trial-one-week-reminder")|> subject("14 days left on your Plausible trial")- |> render("trial_two_week_reminder.html", user: user)+ |> render("trial_one_week_reminder.html", user: user)enddef trial_upgrade_email(user, day, pageviews) donew_email()|> to(user)+ |> bcc("[email protected]")|> from("Uku Taht <[email protected]>")|> tag("trial-upgrade-email")|> subject("Your Plausible trial ends #{day}")@@ -59,21 +93,13 @@ defmodule PlausibleWeb.Email dodef trial_over_email(user) donew_email()|> to(user)+ |> bcc("[email protected]")|> from("Uku Taht <[email protected]>")|> tag("trial-over-email")|> subject("Your Plausible trial has ended")|> render("trial_over_email.html", user: user)end- def feedback_survey_email(user) do- new_email()- |> to(user)- |> from("Uku Taht <[email protected]>")- |> tag("feedback-survey-email")- |> subject("Plausible feedback")- |> render("feedback_survey.html", user: user)- end-def feedback(from, text) dofrom = if from == "", do: "[email protected]", else: fromdiff --git a/lib/plausible_web/templates/email/activation_email.html.eex b/lib/plausible_web/templates/email/activation_email.html.eexindex 382107ea52..053d054bef 100644--- a/lib/plausible_web/templates/email/activation_email.html.eex+++ b/lib/plausible_web/templates/email/activation_email.html.eex@@ -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.diff --git a/lib/plausible_web/templates/email/check_stats_email.html.eex b/lib/plausible_web/templates/email/check_stats_email.html.eexnew file mode 100644index 0000000000..1b60ed9a3b--- /dev/null+++ b/lib/plausible_web/templates/email/check_stats_email.html.eex@@ -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.iodiff --git a/lib/plausible_web/templates/email/create_site_email.html.eex b/lib/plausible_web/templates/email/create_site_email.html.eexnew file mode 100644index 0000000000..8b3dc57a34--- /dev/null+++ b/lib/plausible_web/templates/email/create_site_email.html.eex@@ -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.iodiff --git a/lib/plausible_web/templates/email/feedback_survey.html.eex b/lib/plausible_web/templates/email/feedback_survey.html.eexdeleted file mode 100644index 31d06fda19..0000000000--- a/lib/plausible_web/templates/email/feedback_survey.html.eex+++ /dev/null@@ -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.iodiff --git a/lib/plausible_web/templates/email/help_email.html.eex b/lib/plausible_web/templates/email/help_email.html.eexdeleted file mode 100644index 3c855ea099..0000000000--- a/lib/plausible_web/templates/email/help_email.html.eex+++ /dev/null@@ -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.iodiff --git a/lib/plausible_web/templates/email/site_setup_help_email.html.eex b/lib/plausible_web/templates/email/site_setup_help_email.html.eexnew file mode 100644index 0000000000..3a405cbdd6--- /dev/null+++ b/lib/plausible_web/templates/email/site_setup_help_email.html.eex@@ -0,0 +1,18 @@+Hey <%= user_salutation(@user) %>,+<br /><br />+<%= 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.+ <br /><br />+<% end %>+To finish your setup for <%= @site.domain %>, you need to install <%= link("this lightweight line of JavaScript code", to: "https://plausible.io/#{URI.encode_www_form(@site.domain)}/snippet") %> into your site to start collecting visitor statistics.+<br /><br />+This Plausible script is 14 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.+<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.iodiff --git a/lib/plausible_web/templates/email/site_setup_success_email.html.eex b/lib/plausible_web/templates/email/site_setup_success_email.html.eexnew file mode 100644index 0000000000..b3a6eac86c--- /dev/null+++ b/lib/plausible_web/templates/email/site_setup_success_email.html.eex@@ -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.iodiff --git a/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex b/lib/plausible_web/templates/email/trial_one_week_reminder.html.eexnew file mode 100644index 0000000000..c2985cf5cb--- /dev/null+++ b/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex@@ -0,0 +1,13 @@+Hey <%= user_salutation(@user) %>,+<br /><br />+Time flies! Your 30-day free trial of Plausible will end next week.+<br /><br />+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.+<br /><br />+In order to continue receiving valuable website traffic insights at a glance, you’ll need to <%= link("Upgrade your account", to: "https://plausible.io/billing/upgrade") %>.+<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.iodiff --git a/lib/plausible_web/templates/email/trial_over_email.html.eex b/lib/plausible_web/templates/email/trial_over_email.html.eexindex b6ff317a88..eda32dd8c9 100644--- a/lib/plausible_web/templates/email/trial_over_email.html.eex+++ b/lib/plausible_web/templates/email/trial_over_email.html.eex@@ -1,10 +1,10 @@Hey <%= user_salutation(@user) %>,<br /><br />-Your free 30-day trial has come to an end. Upgrade to a paid plan now to access to your stats again.<br /><br />+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. <br /><br />-<%= link("Upgrade now", to: "https://plausible.io/billing/upgrade") %>+<%= link("Upgrade now", to: "https://plausible.io/billing/upgrade") %> <br />-We will keep recording stats for another month to give you time to upgrade. If you still haven't upgraded by then, we will stop recording.+We will keep recording stats for another month to give you time to upgrade.<br /><br />Thanks,<br />diff --git a/lib/plausible_web/templates/email/trial_two_week_reminder.html.eex b/lib/plausible_web/templates/email/trial_two_week_reminder.html.eexdeleted file mode 100644index 7cadb1b1e8..0000000000--- a/lib/plausible_web/templates/email/trial_two_week_reminder.html.eex+++ /dev/null@@ -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.iodiff --git a/lib/plausible_web/templates/email/trial_upgrade_email.html.eex b/lib/plausible_web/templates/email/trial_upgrade_email.html.eexindex 2f5cef7a60..fc0e60d636 100644--- a/lib/plausible_web/templates/email/trial_upgrade_email.html.eex+++ b/lib/plausible_web/templates/email/trial_upgrade_email.html.eex@@ -1,13 +1,13 @@Hey <%= user_salutation(@user) %>,<br /><br />-Your free 30-day trial is ending <%= @day %>, but you can keep using Plausible by upgrading to a paid plan.+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.<br /><br />In the last month, your account has used <%= PlausibleWeb.AuthView.delimit_integer(@pageviews) %> pageviews.Based on that we recommend you select the <%= suggested_plan_name(@pageviews) %> plan which runs at <%= suggested_plan_cost(@pageviews) %>.<br /><br /><%= link("Upgrade now", to: "https://plausible.io/billing/upgrade") %><br /><br />-Have any questions? Just reply to this email to get in touch!+Have a question, feedback or need some guidance? Just reply to this email to get in touch!<br /><br /><br /><br />Thanks,<br />diff --git a/lib/plausible_web/templates/email/welcome_email.html.eex b/lib/plausible_web/templates/email/welcome_email.html.eexindex 67b7182657..875eee0859 100644--- a/lib/plausible_web/templates/email/welcome_email.html.eex+++ b/lib/plausible_web/templates/email/welcome_email.html.eex@@ -1,20 +1,14 @@Hey <%= user_salutation(@user) %>,<br /><br />-I'm building Plausible to provide a simple and ethical approach to tracking website visitors. I'm super excited to-have you on board!+I'm building Plausible to provide a simple and ethical approach to tracking website visitors.+I'm super excited to have you on board!<br /><br />-The hardest part about building this product is getting the word out there. I'm a solo developer without-a marketing budget, trying to make this business work. With your help, I might be able to go full-time soon.+To start collecting stats, you need to <%= link("add a site on Plausible", to: "https://plausible.io/sites/new") %>.<br /><br />-If you could share why you switched to Plausible with your friends, it would really help me out a lot.-Truly, a single tweet or a blog post could make a huge difference for a small project like this.-Would you be up for this?-<br /><br />-PS: Also check out our <a href="https://feedback.plausible.io/">collaborative roadmapping tool</a>. If you have any feature requests, you can raise them there.+Have a question, feedback or need some guidance? Do reply back to this email.<br /><br />Thanks,<br />-Uku Taht,<br />-Founder, Plausible Insights+Uku Taht<br /><br />--<br /><br />diff --git a/priv/repo/migrations/20200320100803_add_setup_emails.exs b/priv/repo/migrations/20200320100803_add_setup_emails.exsnew file mode 100644index 0000000000..c9afb0531e--- /dev/null+++ b/priv/repo/migrations/20200320100803_add_setup_emails.exs@@ -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+enddiff --git a/priv/repo/migrations/20200323083536_add_create_site_emails.exs b/priv/repo/migrations/20200323083536_add_create_site_emails.exsnew file mode 100644index 0000000000..f2d2d333da--- /dev/null+++ b/priv/repo/migrations/20200323083536_add_create_site_emails.exs@@ -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+enddiff --git a/priv/repo/migrations/20200323084954_add_check_stats_emails.exs b/priv/repo/migrations/20200323084954_add_check_stats_emails.exsnew file mode 100644index 0000000000..fa03055e74--- /dev/null+++ b/priv/repo/migrations/20200323084954_add_check_stats_emails.exs@@ -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+enddiff --git a/test/mix/tasks/send_check_stats_emails_test.exs b/test/mix/tasks/send_check_stats_emails_test.exsnew file mode 100644index 0000000000..d88ec2ad73--- /dev/null+++ b/test/mix/tasks/send_check_stats_emails_test.exs@@ -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+enddiff --git a/test/mix/tasks/send_feedback_emails_test.exs b/test/mix/tasks/send_feedback_emails_test.exsdeleted file mode 100644index 6013e9e6da..0000000000--- a/test/mix/tasks/send_feedback_emails_test.exs+++ /dev/null@@ -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-enddiff --git a/test/mix/tasks/send_intro_emails_test.exs b/test/mix/tasks/send_intro_emails_test.exsdeleted file mode 100644index a39b5cc1a0..0000000000--- a/test/mix/tasks/send_intro_emails_test.exs+++ /dev/null@@ -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-enddiff --git a/test/mix/tasks/send_site_setup_emails_test.exs b/test/mix/tasks/send_site_setup_emails_test.exsnew file mode 100644index 0000000000..0bf0de7b10--- /dev/null+++ b/test/mix/tasks/send_site_setup_emails_test.exs@@ -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+enddiff --git a/test/mix/tasks/send_trial_notifications_test.exs b/test/mix/tasks/send_trial_notifications_test.exsindex a924ea1154..a723396994 100644--- a/test/mix/tasks/send_trial_notifications_test.exs+++ b/test/mix/tasks/send_trial_notifications_test.exs@@ -14,14 +14,14 @@ defmodule Mix.Tasks.SendTrialNotificationsTest doenddescribe "with site and pageviews" do- test "sends a reminder 14 days before trial ends (16 days after user signed up)" do- user = insert(:user, trial_expiry_date: Timex.now |> Timex.shift(days: 14))+ test "sends a reminder 7 days before trial ends (16 days after user signed up)" do+ user = insert(:user, trial_expiry_date: Timex.now |> Timex.shift(days: 7))site = insert(:site, members: [user])insert(:pageview, domain: site.domain)Mix.Tasks.SendTrialNotifications.execute()- assert_delivered_email(PlausibleWeb.Email.trial_two_week_reminder(user))+ assert_delivered_email(PlausibleWeb.Email.trial_one_week_reminder(user))endtest "sends an upgrade email the day before the trial ends" do@@ -55,7 +55,7 @@ defmodule Mix.Tasks.SendTrialNotificationsTest doendtest "does not send a notification if user has a subscription" do- user1 = insert(:user, trial_expiry_date: Timex.now |> Timex.shift(days: 14))+ user1 = insert(:user, trial_expiry_date: Timex.now |> Timex.shift(days: 7))site1 = insert(:site, members: [user1])insert(:pageview, domain: site1.domain)user2 = insert(:user, trial_expiry_date: Timex.now |> Timex.shift(days: 1))diff --git a/test/plausible/billing/billing_test.exs b/test/plausible/billing/billing_test.exsindex ff897e2555..f09309a16e 100644--- a/test/plausible/billing/billing_test.exs+++ b/test/plausible/billing/billing_test.exs@@ -33,6 +33,20 @@ defmodule Plausible.BillingTest doendend+ describe "on_trial?" do+ test "is true with >= 0 trial days left" do+ user = insert(:user)++ assert Billing.on_trial?(user)+ end++ test "is false with < 0 trial days left" do+ user = insert(:user, trial_expiry_date: Timex.shift(Timex.now(), days: -1))++ refute Billing.on_trial?(user)+ end+ end+describe "needs_to_upgrade?" dotest "is false for a trial user" douser = insert(:user)diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exsindex 2c4367cb73..8f6bea2543 100644--- a/test/plausible_web/controllers/auth_controller_test.exs+++ b/test/plausible_web/controllers/auth_controller_test.exs@@ -7,7 +7,7 @@ defmodule PlausibleWeb.AuthControllerTest dotest "shows the register form", %{conn: conn} doconn = get(conn, "/register")- assert html_response(conn, 200) =~ "Enter your details to get started"+ assert html_response(conn, 200) =~ "Enter your details"endtest "registering sends an activation link", %{conn: conn} do@@ -16,7 +16,7 @@ defmodule PlausibleWeb.AuthControllerTest doemail: "[email protected]"})- assert_email_delivered_with(subject: "Plausible activation link")+ assert_email_delivered_with(subject: "Activate your Plausible free trial")endtest "user sees success page after registering", %{conn: conn} do@@ -37,6 +37,13 @@ defmodule PlausibleWeb.AuthControllerTest doassert Plausible.Auth.find_user_by(email: "[email protected]")end+ test "sends the welcome email", %{conn: conn} do+ token = Plausible.Auth.Token.sign_activation("Jane Doe", "[email protected]")+ get(conn, "/claim-activation?token=#{token}")++ assert_email_delivered_with(subject: "Welcome to Plausible")+ end+test "redirects new user to create a password", %{conn: conn} dotoken = Plausible.Auth.Token.sign_activation("Jane Doe", "[email protected]")conn = get(conn, "/claim-activation?token=#{token}")