diff --git a/lib/mix/tasks/send_check_stats_emails.ex b/lib/mix/tasks/send_check_stats_emails.ex new file mode 100644 index 000000000..802da282f --- /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 +end diff --git a/lib/mix/tasks/send_feedback_emails.ex b/lib/mix/tasks/send_feedback_emails.ex deleted file mode 100644 index b68e1c085..000000000 --- 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 -end diff --git a/lib/mix/tasks/send_intro_emails.ex b/lib/mix/tasks/send_intro_emails.ex deleted file mode 100644 index ad9901265..000000000 --- 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 -end diff --git a/lib/mix/tasks/send_site_setup_emails.ex b/lib/mix/tasks/send_site_setup_emails.ex new file mode 100644 index 000000000..b1cbe0b87 --- /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 +end diff --git a/lib/mix/tasks/send_trial_notifications.ex b/lib/mix/tasks/send_trial_notifications.ex index 2d423551e..4f2bbc28d 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 do for user <- users do case 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) end 1 -> if Plausible.Auth.user_completed_setup?(user) do @@ -46,12 +46,12 @@ defmodule Mix.Tasks.SendTrialNotifications do end end - 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() end diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex index a8815da36..2487826de 100644 --- a/lib/plausible/billing/billing.ex +++ b/lib/plausible/billing/billing.ex @@ -83,6 +83,8 @@ defmodule Plausible.Billing do end end + def on_trial?(user), do: trial_days_left(user) >= 0 + def trial_days_left(user) do Timex.diff(user.trial_expiry_date, Timex.today(), :days) end diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 029b3956c..1250e58e9 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.ex index b7c3baf61..1f7ed24c1 100644 --- a/lib/plausible_web/email.ex +++ b/lib/plausible_web/email.ex @@ -2,22 +2,63 @@ defmodule PlausibleWeb.Email do use Bamboo.Phoenix, view: PlausibleWeb.EmailView import Bamboo.PostmarkHelper + def activation_email(user, link) do + new_email() + |> to(user.email) + |> from("Uku Taht ") + |> tag("activation-email") + |> subject("Activate your Plausible free trial") + |> render("activation_email.html", name: user.name, link: link) + end + def welcome_email(user) do new_email() |> to(user) + |> bcc("uku@plausible.io") |> from("Uku Taht ") |> 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("uku@plausible.io") + |> from("Uku Taht ") + |> 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 new_email() |> to(user) + |> bcc("uku@plausible.io") |> from("Uku Taht ") |> 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("uku@plausible.io") + |> from("Uku Taht ") + |> 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("uku@plausible.io") + |> from("Uku Taht ") + |> tag("check-stats-email") + |> subject("Check your Plausible website stats") + |> render("check_stats_email.html", user: user) end def 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 ") - |> 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) do new_email() |> to(user) + |> bcc("uku@plausible.io") |> from("Uku Taht ") - |> 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) end def trial_upgrade_email(user, day, pageviews) do new_email() |> to(user) + |> bcc("uku@plausible.io") |> from("Uku Taht ") |> tag("trial-upgrade-email") |> subject("Your Plausible trial ends #{day}") @@ -59,21 +93,13 @@ defmodule PlausibleWeb.Email do def trial_over_email(user) do new_email() |> to(user) + |> bcc("uku@plausible.io") |> from("Uku Taht ") |> 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 ") - |> tag("feedback-survey-email") - |> subject("Plausible feedback") - |> render("feedback_survey.html", user: user) - end - def feedback(from, text) do from = if from == "", do: "anonymous@plausible.io", else: from diff --git a/lib/plausible_web/templates/email/activation_email.html.eex b/lib/plausible_web/templates/email/activation_email.html.eex index 382107ea5..053d054be 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 %>,

-Thank you for signing up to Plausible. Click here to activate your account. +Thank you for signing up for the free trial of Plausible, a simple and privacy-friendly alternative to Google Analytics.

-This link will expire in 24 hours. If you don't use it by then, you can request another activation link. +Click here 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.eex new file mode 100644 index 000000000..1b60ed9a3 --- /dev/null +++ b/lib/plausible_web/templates/email/check_stats_email.html.eex @@ -0,0 +1,14 @@ +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: "https://plausible.io/") %> 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 +

+-- +

+https://plausible.io diff --git a/lib/plausible_web/templates/email/create_site_email.html.eex b/lib/plausible_web/templates/email/create_site_email.html.eex new file mode 100644 index 000000000..8b3dc57a3 --- /dev/null +++ b/lib/plausible_web/templates/email/create_site_email.html.eex @@ -0,0 +1,14 @@ +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: "https://plausible.io/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 Taht +

+-- +

+https://plausible.io diff --git a/lib/plausible_web/templates/email/feedback_survey.html.eex b/lib/plausible_web/templates/email/feedback_survey.html.eex deleted file mode 100644 index 31d06fda1..000000000 --- a/lib/plausible_web/templates/email/feedback_survey.html.eex +++ /dev/null @@ -1,17 +0,0 @@ -Hey <%= user_salutation(@user) %>, -

-Big thanks for giving Plausible a try at such an early stage. -

-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. -

-<%= link("Take the survey", to: "https://plausible.typeform.com/to/szHj56") %> -

-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 :) -

-Thanks,
-Uku Taht
-Founder, Plausible Insights -

--- -

-https://plausible.io diff --git a/lib/plausible_web/templates/email/help_email.html.eex b/lib/plausible_web/templates/email/help_email.html.eex deleted file mode 100644 index 3c855ea09..000000000 --- a/lib/plausible_web/templates/email/help_email.html.eex +++ /dev/null @@ -1,13 +0,0 @@ -Hey <%= user_salutation(@user) %>, -

-I saw that you signed up for Plausible but the setup isn't working completely. Is there anything I can do to help? -

-If you have any questions let me know. -

-Thanks,
-Uku Taht
-Founder, Plausible Insights -

--- -

-https://plausible.io 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 new file mode 100644 index 000000000..3a405cbdd --- /dev/null +++ b/lib/plausible_web/templates/email/site_setup_help_email.html.eex @@ -0,0 +1,18 @@ +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. +

+<% 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. +

+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. +

+Do reply back to this email if you have any questions or need some guidance. +

+Thanks,
+Uku Taht +

+-- +

+https://plausible.io 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 new file mode 100644 index 000000000..b3a6eac86 --- /dev/null +++ b/lib/plausible_web/templates/email/site_setup_success_email.html.eex @@ -0,0 +1,20 @@ +Hey <%= user_salutation(@user) %>, +

+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. +

+<%= link("Check your stats", to: "https://plausible.io/#{URI.encode_www_form(@site.domain)}") %> +

+<%= 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. +

+<% 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. +

+Do reply back to this email if you have any questions. +

+Thanks,
+Uku Taht +

+-- +

+https://plausible.io 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 new file mode 100644 index 000000000..c2985cf5c --- /dev/null +++ b/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex @@ -0,0 +1,13 @@ +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. +

+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") %>. +

+If you have any questions or feedback for me, feel free to reply to this email. +

+Thanks,
+Uku Taht
+https://plausible.io 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 b6ff317a8..eda32dd8c 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) %>,

-Your free 30-day trial has come to an end. Upgrade to a paid plan now to access to your stats again.

+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: "https://plausible.io/billing/upgrade") %> +<%= link("Upgrade now", to: "https://plausible.io/billing/upgrade") %>
-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.

Thanks,
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.eex deleted file mode 100644 index 7cadb1b1e..000000000 --- a/lib/plausible_web/templates/email/trial_two_week_reminder.html.eex +++ /dev/null @@ -1,13 +0,0 @@ -Hey <%= user_salutation(@user) %>, -

-Thank you so much for trying out Plausible! -

-This is your friendly reminder that you have 14 days left on your Plausible free trial. -

-I will contact you towards the end of the trial with instructions to upgrade from your free trial to a paid plan. -

-If you have any questions or feedback for me, feel free to reply to this email. -

-Thanks,
-Uku Taht
-https://plausible.io 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 2f5cef7a6..fc0e60d63 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) %>,

-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.

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) %>.

<%= link("Upgrade now", to: "https://plausible.io/billing/upgrade") %>

-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!



Thanks,
diff --git a/lib/plausible_web/templates/email/welcome_email.html.eex b/lib/plausible_web/templates/email/welcome_email.html.eex index 67b718265..875eee085 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) %>,

-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!

-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") %>.

-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? -

-PS: Also check out our collaborative roadmapping tool. 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.

Thanks,
-Uku Taht,
-Founder, Plausible Insights +Uku Taht

--

diff --git a/priv/repo/migrations/20200320100803_add_setup_emails.exs b/priv/repo/migrations/20200320100803_add_setup_emails.exs new file mode 100644 index 000000000..c9afb0531 --- /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 +end diff --git a/priv/repo/migrations/20200323083536_add_create_site_emails.exs b/priv/repo/migrations/20200323083536_add_create_site_emails.exs new file mode 100644 index 000000000..f2d2d333d --- /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 +end diff --git a/priv/repo/migrations/20200323084954_add_check_stats_emails.exs b/priv/repo/migrations/20200323084954_add_check_stats_emails.exs new file mode 100644 index 000000000..fa03055e7 --- /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 +end diff --git a/test/mix/tasks/send_check_stats_emails_test.exs b/test/mix/tasks/send_check_stats_emails_test.exs new file mode 100644 index 000000000..d88ec2ad7 --- /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 +end diff --git a/test/mix/tasks/send_feedback_emails_test.exs b/test/mix/tasks/send_feedback_emails_test.exs deleted file mode 100644 index 6013e9e6d..000000000 --- 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 -end diff --git a/test/mix/tasks/send_intro_emails_test.exs b/test/mix/tasks/send_intro_emails_test.exs deleted file mode 100644 index a39b5cc1a..000000000 --- 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 -end diff --git a/test/mix/tasks/send_site_setup_emails_test.exs b/test/mix/tasks/send_site_setup_emails_test.exs new file mode 100644 index 000000000..0bf0de7b1 --- /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 +end diff --git a/test/mix/tasks/send_trial_notifications_test.exs b/test/mix/tasks/send_trial_notifications_test.exs index a924ea115..a72339699 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 do end describe "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)) end test "sends an upgrade email the day before the trial ends" do @@ -55,7 +55,7 @@ defmodule Mix.Tasks.SendTrialNotificationsTest do end test "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.exs index ff897e255..f09309a16 100644 --- a/test/plausible/billing/billing_test.exs +++ b/test/plausible/billing/billing_test.exs @@ -33,6 +33,20 @@ defmodule Plausible.BillingTest do end end + 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?" do test "is false for a trial user" do user = insert(:user) diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exs index 2c4367cb7..8f6bea254 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 do test "shows the register form", %{conn: conn} do conn = get(conn, "/register") - assert html_response(conn, 200) =~ "Enter your details to get started" + assert html_response(conn, 200) =~ "Enter your details" end test "registering sends an activation link", %{conn: conn} do @@ -16,7 +16,7 @@ defmodule PlausibleWeb.AuthControllerTest do email: "user@example.com" }) - assert_email_delivered_with(subject: "Plausible activation link") + assert_email_delivered_with(subject: "Activate your Plausible free trial") end test "user sees success page after registering", %{conn: conn} do @@ -37,6 +37,13 @@ defmodule PlausibleWeb.AuthControllerTest do assert Plausible.Auth.find_user_by(email: "user@example.com") end + test "sends the welcome email", %{conn: conn} do + token = Plausible.Auth.Token.sign_activation("Jane Doe", "user@example.com") + 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} do token = Plausible.Auth.Token.sign_activation("Jane Doe", "user@example.com") conn = get(conn, "/claim-activation?token=#{token}")