mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +03:00
Add UTM tags to login links from email reports
This commit is contained in:
parent
8ba21d2470
commit
091fc423f9
@ -609,7 +609,7 @@ body {
|
||||
<!--<![endif]-->
|
||||
<div align="center" class="button-container" style="padding-top:10px;padding-right:10px;padding-bottom:10px;padding-left:10px;">
|
||||
<%= 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;">
|
||||
<!--[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="<%= @login_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;">Login to view your dashboard</span>
|
||||
</span></a>
|
||||
<!--[if mso]></center></v:textbox></v:roundrect></td></tr></table><![endif]-->
|
||||
|
@ -46,6 +46,12 @@ defmodule Plausible.Workers.SendEmailReport do
|
||||
:ok
|
||||
end
|
||||
|
||||
defp gen_login_link("Weekly"),
|
||||
do: PlausibleWeb.Endpoint.url() <> "/login?utm_medium=email&utm_source=weekly-report"
|
||||
|
||||
defp gen_login_link(_),
|
||||
do: PlausibleWeb.Endpoint.url() <> "/login?utm_medium=email&utm_source=monthly-report"
|
||||
|
||||
defp send_report(email, site, name, unsubscribe_link, query) do
|
||||
{pageviews, unique_visitors} = Stats.pageviews_and_visitors(site, query)
|
||||
|
||||
@ -58,7 +64,7 @@ defmodule Plausible.Workers.SendEmailReport do
|
||||
referrers = Stats.top_sources(site, query, 5, 1, [])
|
||||
pages = Stats.top_pages(site, query, 5, 1, [])
|
||||
user = Plausible.Auth.find_user_by(email: email)
|
||||
login_link = user && Plausible.Sites.is_owner?(user.id, site)
|
||||
login_link = user && Plausible.Sites.is_owner?(user.id, site) && gen_login_link(name)
|
||||
|
||||
template =
|
||||
PlausibleWeb.Email.weekly_report(email, site,
|
||||
@ -73,7 +79,8 @@ defmodule Plausible.Workers.SendEmailReport do
|
||||
login_link: login_link,
|
||||
pages: pages,
|
||||
query: query,
|
||||
name: name
|
||||
name: name,
|
||||
login_link: login_link
|
||||
)
|
||||
|
||||
try do
|
||||
|
@ -25,6 +25,19 @@ defmodule Plausible.Workers.SendEmailReportTest do
|
||||
to: [nil: "user2@email.com"]
|
||||
)
|
||||
end
|
||||
|
||||
test "includes correct login link in email" do
|
||||
user = insert(:user)
|
||||
site = insert(:site, domain: "test-site.com", timezone: "US/Eastern", members: [user])
|
||||
insert(:weekly_report, site: site, recipients: [user.email])
|
||||
|
||||
perform(%{"site_id" => site.id, "interval" => "weekly"})
|
||||
|
||||
user_email = user.email
|
||||
assert_delivered_email_matches(%{to: [{_, ^user_email}], html_body: html_body})
|
||||
|
||||
assert html_body =~ "/login?utm_medium=email&utm_source=weekly-report"
|
||||
end
|
||||
end
|
||||
|
||||
describe "monthly_reports" do
|
||||
@ -50,5 +63,18 @@ defmodule Plausible.Workers.SendEmailReportTest do
|
||||
to: [nil: "user2@email.com"]
|
||||
)
|
||||
end
|
||||
|
||||
test "includes correct login link in email" do
|
||||
user = insert(:user)
|
||||
site = insert(:site, domain: "test-site.com", timezone: "US/Eastern", members: [user])
|
||||
insert(:monthly_report, site: site, recipients: [user.email])
|
||||
|
||||
perform(%{"site_id" => site.id, "interval" => "monthly"})
|
||||
|
||||
user_email = user.email
|
||||
assert_delivered_email_matches(%{to: [{_, ^user_email}], html_body: html_body})
|
||||
|
||||
assert html_body =~ "/login?utm_medium=email&utm_source=monthly-report"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user