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
Send welcome email after first site creation
Uku Taht9c4493de6610
diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.exindex 44bbacff03..a62dc0a761 100644--- a/lib/plausible_web/controllers/auth_controller.ex+++ b/lib/plausible_web/controllers/auth_controller.ex@@ -72,9 +72,6 @@ defmodule PlausibleWeb.AuthController docase Auth.verify_email(user, code) do:ok ->- PlausibleWeb.Email.welcome_email(user)- |> Plausible.Mailer.send_email()-redirect(conn, to: "/sites/new"){:error, :incorrect} ->render(conn, "activate.html",diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.exindex 3f07de4b69..2676340fef 100644--- a/lib/plausible_web/controllers/site_controller.ex+++ b/lib/plausible_web/controllers/site_controller.ex@@ -37,6 +37,17 @@ defmodule PlausibleWeb.SiteController do{:ok, %{site: site}} ->Plausible.Slack.notify("#{user.name} created #{site.domain} [email=#{user.email}]")+ is_first_site = !Repo.exists?(+ from sm in Plausible.Site.Membership,+ where: sm.user_id == ^user.id+ and sm.site_id != ^site.id+ )++ if is_first_site do+ PlausibleWeb.Email.welcome_email(user)+ |> Plausible.Mailer.send_email()+ end+conn|> put_session(site.domain <> "_offer_email_report", true)|> redirect(to: "/#{URI.encode_www_form(site.domain)}/snippet")diff --git a/lib/plausible_web/templates/email/welcome_email.html.eex b/lib/plausible_web/templates/email/welcome_email.html.eexindex baca4c8ce6..03232fd75a 100644--- a/lib/plausible_web/templates/email/welcome_email.html.eex+++ b/lib/plausible_web/templates/email/welcome_email.html.eex@@ -1,14 +1,22 @@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!+We are building Plausible to provide a simple and ethical approach to tracking website visitors.+We're super excited to have you on board!<br /><br />-To start collecting stats, you need to <%= link("add a site on Plausible", to: "#{plausible_url()}/sites/new") %>.+Here are five steps to get the most out of your Plausible experience:+<br /><br />+* Serve the script as a <%= link("first party connection from your custom domain", to: "https://docs.plausible.io/custom-domain") %><br />+* <%= link("Enable email reports", to: "https://docs.plausible.io/email-reports/") %> and notifications for <%= link("traffic spikes", to: "https://docs.plausible.io/traffic-spikes/") %><br />+* <%= link("Integrate with Search Console", to: "https://docs.plausible.io/google-search-console-integration/") %> to get keyword phrases people find your site with<br />+* Set up some easy goals including <%= link("404 error pages", to: "https://docs.plausible.io/404-error-pages-tracking") %> and <%= link("outbound link clicks", to: "https://docs.plausible.io/outbound-link-click-tracking/") %><br />+* <%= link("Opt out from counting your own visits", to: "https://docs.plausible.io/excluding/") %><br />+<br /><br />+Then you're ready to start exploring your fast loading, ethical and actionable <%= link("Plausible dashboard", to: "https://plausible.io/sites") %>.<br /><br />Have a question, feedback or need some guidance? Do reply back to this email.<br /><br />Thanks,<br />-Uku Taht+Uku and Marko<br /><br />--<br /><br />diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exsindex 6a1c52b755..8b1e7c1f44 100644--- a/test/plausible_web/controllers/site_controller_test.exs+++ b/test/plausible_web/controllers/site_controller_test.exs@@ -1,6 +1,7 @@defmodule PlausibleWeb.SiteControllerTest douse PlausibleWeb.ConnCaseuse Plausible.Repo+ use Bamboo.Testimport Plausible.TestUtilsdescribe "GET /sites/new" do@@ -45,6 +46,30 @@ defmodule PlausibleWeb.SiteControllerTest doassert Repo.exists?(Plausible.Site, domain: "example.com")end+ test "sends welcome email if this is the user's first site", %{conn: conn} do+ post(conn, "/sites", %{+ "site" => %{+ "domain" => "example.com",+ "timezone" => "Europe/London"+ }+ })++ assert_email_delivered_with(subject: "Welcome to Plausible")+ end++ test "does not send welcome email if user already has a previous site", %{conn: conn, user: user} do+ insert(:site, members: [user])++ post(conn, "/sites", %{+ "site" => %{+ "domain" => "example.com",+ "timezone" => "Europe/London"+ }+ })++ assert_no_emails_delivered()+ end+test "cleans up the url", %{conn: conn} doconn =post(conn, "/sites", %{