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
Offer new sites to set up weekly reports
Uku Taht12b91ab2422d
diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.exindex 0233177277..30b8b84ccc 100644--- a/lib/plausible_web/controllers/site_controller.ex+++ b/lib/plausible_web/controllers/site_controller.ex@@ -18,7 +18,9 @@ defmodule PlausibleWeb.SiteController do{:ok, %{site: site}} ->Plausible.Tracking.event(conn, "New Site: Create", %{domain: site.domain})Plausible.Slack.notify("#{user.name} created #{site.domain}")- redirect(conn, to: "/#{site.domain}/snippet")+ conn+ |> put_session(site.domain <> "_offer_email_report", true)+ |> redirect(to: "/#{site.domain}/snippet"){:error, :site, changeset, _} ->render(conn, "new.html", changeset: changeset)end@@ -40,8 +42,8 @@ defmodule PlausibleWeb.SiteController do!google_site["error"]end- report_changeset = Repo.get_by(Plausible.Site.EmailSettings, site_id: site.id)- |> Plausible.Site.EmailSettings.changeset(%{})+ report = Repo.get_by(Plausible.Site.EmailSettings, site_id: site.id)+ report_changeset = report && Plausible.Site.EmailSettings.changeset(report, %{})changeset = Plausible.Site.changeset(site, %{})@@ -123,7 +125,10 @@ defmodule PlausibleWeb.SiteController dodef enable_email_report(conn, %{"website" => website}) dosite = Sites.get_for_user!(conn.assigns[:current_user].id, website)- Plausible.Site.EmailSettings.changeset(%Plausible.Site.EmailSettings{}, %{site_id: site.id})+ Plausible.Site.EmailSettings.changeset(%Plausible.Site.EmailSettings{}, %{+ site_id: site.id,+ email: conn.assigns[:current_user].email+ })|> Repo.insert!conndiff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.exindex 278700fa9b..e6ac5b1636 100644--- a/lib/plausible_web/controllers/stats_controller.ex+++ b/lib/plausible_web/controllers/stats_controller.ex@@ -18,6 +18,7 @@ defmodule PlausibleWeb.StatsController doelseif Plausible.Sites.has_pageviews?(site) dodemo = site.domain == "plausible.io"+ offer_email_report = get_session(conn, site.domain <> "_offer_email_report")Plausible.Tracking.event(conn, "Site Analytics: Open", %{demo: demo})@@ -27,12 +28,14 @@ defmodule PlausibleWeb.StatsController doconn|> assign(:skip_plausible_tracking, !demo)+ |> put_session(site.domain <> "_offer_email_report", nil)|> render("stats.html",site: site,query: query,current_visitors: current_visitors,- title: "Plausible · " <> site.domain- )+ title: "Plausible · " <> site.domain,+ offer_email_report: offer_email_report+ )elseconn|> assign(:skip_plausible_tracking, true)diff --git a/lib/plausible_web/templates/site/settings.html.eex b/lib/plausible_web/templates/site/settings.html.eexindex a5eea93fc1..40ea88adff 100644--- a/lib/plausible_web/templates/site/settings.html.eex+++ b/lib/plausible_web/templates/site/settings.html.eex@@ -94,7 +94,7 @@<% end %></div>-<div class="max-w-md mx-auto bg-white shadow-md rounded rounded-t-none border-t-2 border-indigo-lightest px-8 pt-6 pb-8 mt-10" id="google-auth">+<div class="max-w-md mx-auto bg-white shadow-md rounded rounded-t-none border-t-2 border-indigo-lightest px-8 pt-6 pb-8 mt-10" id="email-reports"><div><h2>Email reports</h2></div>diff --git a/lib/plausible_web/templates/stats/stats.html.eex b/lib/plausible_web/templates/stats/stats.html.eexindex 2f7ecee265..53d3104fbf 100644--- a/lib/plausible_web/templates/stats/stats.html.eex+++ b/lib/plausible_web/templates/stats/stats.html.eex@@ -1,5 +1,10 @@-<div class="pt-12"></div><div class="container pb-32" data-site-domain="<%= @site.domain %>">+ <%= if @offer_email_report do %>+ <div class="text-center bg-blue-lighter text-blue-darkest text-sm font-bold px-4 w-full rounded transition" style="top: 91px" role="alert">+ <%= link("Click here to enable weekly email reports →", to: "/#{@site.domain}/settings#email-reports", class: "py-2 block") %>+ </div>+ <% end %>+ <div class="pt-12"></div><div class="w-full sm:flex justify-between items-center"><div class="w-full sm:flex items-center"><h2 class="text-center sm:text-left sm:mr-8">Analytics for <%= link(@site.domain, to: "//" <> @site.domain, target: "_blank") %></h2>