Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Fix email login link

Uku Taht6b53b4fbb5a6
diff --git a/lib/mix/tasks/send_email_reports.ex b/lib/mix/tasks/send_email_reports.ex
index ef5edb1c21..a11d310077 100644
--- a/lib/mix/tasks/send_email_reports.ex
+++ b/lib/mix/tasks/send_email_reports.ex
@@ -75,6 +75,8 @@ defmodule Mix.Tasks.SendEmailReports do
change_bounce_rate = if prev_bounce_rate > 0, do: bounce_rate - prev_bounce_rate
referrers = Stats.top_referrers(site, query)
pages = Stats.top_pages(site, query)
+ user = Plausible.Auth.find_user_by(email: email)
+ login_link = user && Plausible.Sites.is_owner?(user.id, site)
PlausibleWeb.Email.weekly_report(email, site,
unique_visitors: unique_visitors,
@@ -85,7 +87,7 @@ defmodule Mix.Tasks.SendEmailReports do
change_bounce_rate: change_bounce_rate,
referrers: referrers,
unsubscribe_link: unsubscribe_link,
- view_link: view_link(site, query),
+ login_link: login_link,
pages: pages,
query: query,
name: name
@@ -113,13 +115,4 @@ defmodule Mix.Tasks.SendEmailReports do
timestamp: Timex.now()
}])
end
-
- defp view_link(site, %Plausible.Stats.Query{period: "7d"}) do
- PlausibleWeb.Endpoint.url() <> "/#{URI.encode_www_form(site.domain)}?period=7d"
- end
-
- defp view_link(site, %Plausible.Stats.Query{period: "month", date_range: range}) do
- month = Timex.format!(range.first, "{ISOdate}")
- PlausibleWeb.Endpoint.url() <> "/#{URI.encode_www_form(site.domain)}?period=month&date=#{month}"
- end
end
diff --git a/lib/plausible_web/templates/email/weekly_report.html.eex b/lib/plausible_web/templates/email/weekly_report.html.eex
index d9dfdb1220..be6ae610b3 100644
--- a/lib/plausible_web/templates/email/weekly_report.html.eex
+++ b/lib/plausible_web/templates/email/weekly_report.html.eex
@@ -608,10 +608,12 @@ body {
<div style="border-top:0px solid transparent; border-left:0px solid transparent; border-bottom:0px solid transparent; border-right:0px solid transparent; padding-top:20px; padding-bottom:20px; padding-right: 0px; padding-left: 0px;">
<!--<![endif]-->
<div align="center" class="button-container" style="padding-top:10px;padding-right:10px;padding-bottom:10px;padding-left:10px;">
- <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-spacing: 0; border-collapse: collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;"><tr><td style="padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px" align="center"><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://plausible.io/plausible.io" style="height:31.5pt; width:189.75pt; v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#5661b3"><w:anchorlock/><v:textbox inset="0,0,0,0"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]--><a href="<%= @view_link %>" style="-webkit-text-size-adjust: none; text-decoration: none; display: inline-block; color: #ffffff; background-color: #5661b3; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; width: auto; width: auto; border-top: 1px solid #5661b3; border-right: 1px solid #5661b3; border-bottom: 1px solid #5661b3; border-left: 1px solid #5661b3; padding-top: 5px; padding-bottom: 5px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; text-align: center; mso-border-alt: none; word-break: keep-all;" target="_blank"><span style="padding-left:20px;padding-right:20px;font-size:16px;display:inline-block;">
- <span style="font-size: 16px; line-height: 32px;">View on Plausible</span>
- </span></a>
- <!--[if mso]></center></v:textbox></v:roundrect></td></tr></table><![endif]-->
+ <%= if @login_link do %>
+ <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-spacing: 0; border-collapse: collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;"><tr><td style="padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px" align="center"><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://plausible.io/plausible.io" style="height:31.5pt; width:189.75pt; v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#5661b3"><w:anchorlock/><v:textbox inset="0,0,0,0"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]--><a href="https://plausible.io/login" style="-webkit-text-size-adjust: none; text-decoration: none; display: inline-block; color: #ffffff; background-color: #5661b3; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; width: auto; width: auto; border-top: 1px solid #5661b3; border-right: 1px solid #5661b3; border-bottom: 1px solid #5661b3; border-left: 1px solid #5661b3; padding-top: 5px; padding-bottom: 5px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; text-align: center; mso-border-alt: none; word-break: keep-all;" target="_blank"><span style="padding-left:20px;padding-right:20px;font-size:16px;display:inline-block;">
+ <span style="font-size: 16px; line-height: 32px;">Login to view your dashboard</span>
+ </span></a>
+ <!--[if mso]></center></v:textbox></v:roundrect></td></tr></table><![endif]-->
+ <% end %>
</div>
<!--[if (!mso)&(!IE)]><!-->
</div>