mirror of
https://github.com/plausible/analytics.git
synced 2024-11-23 03:04:43 +03:00
Remove dead code
This commit is contained in:
parent
4d0bc61ffd
commit
01706b7590
File diff suppressed because it is too large
Load Diff
28
lib/plausible/stats/compare.ex
Normal file
28
lib/plausible/stats/compare.ex
Normal file
@ -0,0 +1,28 @@
|
||||
defmodule Plausible.Stats.Compare do
|
||||
def calculate_change("bounce_rate", old_stats, new_stats) do
|
||||
old_count = old_stats["bounce_rate"]["value"]
|
||||
new_count = new_stats["bounce_rate"]["value"]
|
||||
|
||||
if old_count > 0, do: new_count - old_count
|
||||
end
|
||||
|
||||
def calculate_change(metric, old_stats, new_stats) do
|
||||
old_count = old_stats[metric]["value"]
|
||||
new_count = new_stats[metric]["value"]
|
||||
|
||||
percent_change(old_count, new_count)
|
||||
end
|
||||
|
||||
defp percent_change(old_count, new_count) do
|
||||
cond do
|
||||
old_count == 0 and new_count > 0 ->
|
||||
100
|
||||
|
||||
old_count == 0 and new_count == 0 ->
|
||||
0
|
||||
|
||||
true ->
|
||||
round((new_count - old_count) / old_count * 100)
|
||||
end
|
||||
end
|
||||
end
|
@ -265,7 +265,7 @@ body {
|
||||
<!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 5px; padding-left: 5px; padding-top: 0px; padding-bottom: 5px; font-family: Arial, sans-serif"><![endif]-->
|
||||
<div style="color:#555555;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;line-height:120%;padding-top:0px;padding-right:5px;padding-bottom:5px;padding-left:5px;">
|
||||
<div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 14px; color: #555555;">
|
||||
<p style="font-size: 12px; line-height: 14px; text-align: left; margin: 0;"><strong><span style="font-size: 20px; line-height: 24px;"><%= PlausibleWeb.StatsView.large_number_format(@pageviews) %></span></strong></p>
|
||||
<p style="font-size: 12px; line-height: 14px; text-align: left; margin: 0;"><strong><span id="pageviews" style="font-size: 20px; line-height: 24px;"><%= PlausibleWeb.StatsView.large_number_format(@pageviews) %></span></strong></p>
|
||||
</div>
|
||||
</div>
|
||||
<!--[if mso]></td></tr></table><![endif]-->
|
||||
@ -307,7 +307,7 @@ body {
|
||||
<!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 5px; padding-left: 5px; padding-top: 0px; padding-bottom: 5px; font-family: Arial, sans-serif"><![endif]-->
|
||||
<div style="color:#555555;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;line-height:120%;padding-top:0px;padding-right:5px;padding-bottom:5px;padding-left:5px;">
|
||||
<div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 14px; color: #555555;">
|
||||
<p style="font-size: 12px; line-height: 14px; text-align: left; margin: 0;"><strong><span style="font-size: 20px; line-height: 24px;"><%= @bounce_rate %>%</span></strong></p>
|
||||
<p style="font-size: 12px; line-height: 14px; text-align: left; margin: 0;"><strong><span id="bounce_rate" style="font-size: 20px; line-height: 24px;"><%= @bounce_rate %>%</span></strong></p>
|
||||
</div>
|
||||
</div>
|
||||
<!--[if mso]></td></tr></table><![endif]-->
|
||||
@ -420,8 +420,8 @@ body {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%= for referrer <- @referrers do %>
|
||||
<div style="background-color:transparent;">
|
||||
<%= for source <- @sources do %>
|
||||
<div class="referrer" style="background-color:transparent;">
|
||||
<div class="block-grid mixed-two-up" style="Margin: 0 auto; min-width: 320px; max-width: 480px; overflow-wrap: break-word; word-wrap: break-word; word-break: break-word; background-color: transparent;">
|
||||
<div style="border-collapse: collapse;display: table;width: 100%;background-color:transparent;">
|
||||
<!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color:transparent;"><tr><td align="center"><table cellpadding="0" cellspacing="0" border="0" style="width:480px"><tr class="layout-full-width" style="background-color:transparent"><![endif]-->
|
||||
@ -434,7 +434,7 @@ body {
|
||||
<!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px; font-family: Arial, sans-serif"><![endif]-->
|
||||
<div style="color:#555555;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;line-height:120%;padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px;">
|
||||
<div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 14px; color: #555555;">
|
||||
<p style="font-size: 14px; line-height: 16px; margin: 0;"><%= referrer[:name] %></p>
|
||||
<p id="referrer-name" style="font-size: 14px; line-height: 16px; margin: 0;"><%= source["source"] %></p>
|
||||
</div>
|
||||
</div>
|
||||
<!--[if mso]></td></tr></table><![endif]-->
|
||||
@ -453,7 +453,7 @@ body {
|
||||
<!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px; font-family: Arial, sans-serif"><![endif]-->
|
||||
<div style="color:#555555;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;line-height:120%;padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px;">
|
||||
<div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 14px; color: #555555;">
|
||||
<p style="font-size: 12px; line-height: 16px; text-align: right; margin: 0;"><span style="font-size: 14px;"><%= PlausibleWeb.StatsView.large_number_format(referrer[:count]) %></span></p>
|
||||
<p style="font-size: 12px; line-height: 16px; text-align: right; margin: 0;"><span id="referrer-count" style="font-size: 14px;"><%= PlausibleWeb.StatsView.large_number_format(source["visitors"]) %></span></p>
|
||||
</div>
|
||||
</div>
|
||||
<!--[if mso]></td></tr></table><![endif]-->
|
||||
@ -550,7 +550,7 @@ body {
|
||||
</div>
|
||||
</div>
|
||||
<%= for page <- @pages do %>
|
||||
<div style="background-color:transparent;">
|
||||
<div class="page" style="background-color:transparent;">
|
||||
<div class="block-grid mixed-two-up" style="Margin: 0 auto; min-width: 320px; max-width: 480px; overflow-wrap: break-word; word-wrap: break-word; word-break: break-word; background-color: transparent;">
|
||||
<div style="border-collapse: collapse;display: table;width: 100%;background-color:transparent;">
|
||||
<!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color:transparent;"><tr><td align="center"><table cellpadding="0" cellspacing="0" border="0" style="width:480px"><tr class="layout-full-width" style="background-color:transparent"><![endif]-->
|
||||
@ -563,7 +563,7 @@ body {
|
||||
<!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px; font-family: Arial, sans-serif"><![endif]-->
|
||||
<div style="color:#555555;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;line-height:120%;padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px;">
|
||||
<div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 14px; color: #555555;">
|
||||
<p style="font-size: 14px; line-height: 16px; margin: 0;"><%= page[:name] %></p>
|
||||
<p id="page-name" style="font-size: 14px; line-height: 16px; margin: 0;"><%= page["page"] %></p>
|
||||
</div>
|
||||
</div>
|
||||
<!--[if mso]></td></tr></table><![endif]-->
|
||||
@ -582,7 +582,7 @@ body {
|
||||
<!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-right: 5px; padding-left: 5px; padding-top: 5px; padding-bottom: 5px; font-family: Arial, sans-serif"><![endif]-->
|
||||
<div style="color:#555555;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;line-height:120%;padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px;">
|
||||
<div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 14px; color: #555555;">
|
||||
<p style="font-size: 12px; line-height: 16px; text-align: right; margin: 0;"><span style="font-size: 14px;"><%= PlausibleWeb.StatsView.large_number_format(page[:count]) %></span></p>
|
||||
<p style="font-size: 12px; line-height: 16px; text-align: right; margin: 0;"><span id="page-count" style="font-size: 14px;"><%= PlausibleWeb.StatsView.large_number_format(page["visitors"]) %></span></p>
|
||||
</div>
|
||||
</div>
|
||||
<!--[if mso]></td></tr></table><![endif]-->
|
||||
|
@ -2,7 +2,7 @@ defmodule Plausible.Workers.SendEmailReport do
|
||||
use Plausible.Repo
|
||||
use Oban.Worker, queue: :send_email_reports, max_attempts: 1
|
||||
alias Plausible.Stats.Query
|
||||
alias Plausible.Stats.Clickhouse, as: Stats
|
||||
alias Plausible.Stats
|
||||
|
||||
@impl Oban.Worker
|
||||
def perform(%Oban.Job{args: %{"interval" => "weekly", "site_id" => site_id}}) do
|
||||
@ -49,28 +49,29 @@ defmodule Plausible.Workers.SendEmailReport do
|
||||
end
|
||||
|
||||
defp send_report(email, site, name, unsubscribe_link, query) do
|
||||
{pageviews, unique_visitors} = Stats.pageviews_and_visitors(site, query)
|
||||
prev_query = Query.shift_back(query, site)
|
||||
curr_period = Stats.aggregate(site, query, ["pageviews", "visitors", "bounce_rate"])
|
||||
prev_period = Stats.aggregate(site, prev_query, ["pageviews", "visitors", "bounce_rate"])
|
||||
|
||||
{change_pageviews, change_visitors} =
|
||||
Stats.compare_pageviews_and_visitors(site, query, {pageviews, unique_visitors})
|
||||
change_pageviews = Stats.Compare.calculate_change("pageviews", prev_period, curr_period)
|
||||
change_visitors = Stats.Compare.calculate_change("visitors", prev_period, curr_period)
|
||||
change_bounce_rate = Stats.Compare.calculate_change("bounce_rate", prev_period, curr_period)
|
||||
|
||||
bounce_rate = Stats.bounce_rate(site, query)
|
||||
prev_bounce_rate = Stats.bounce_rate(site, Query.shift_back(query, site))
|
||||
change_bounce_rate = if prev_bounce_rate > 0, do: bounce_rate - prev_bounce_rate
|
||||
referrers = Stats.top_sources(site, query, 5, 1, [])
|
||||
pages = Stats.top_pages(site, query, 5, 1, [])
|
||||
source_query = Query.put_filter(query, "visit:source", {:is_not, "Direct / None"})
|
||||
sources = Stats.breakdown(site, source_query, "visit:source", ["visitors"], {5, 1})
|
||||
pages = Stats.breakdown(site, query, "event:page", ["visitors"], {5, 1})
|
||||
user = Plausible.Auth.find_user_by(email: email)
|
||||
login_link = user && Plausible.Sites.is_member?(user.id, site)
|
||||
|
||||
template =
|
||||
PlausibleWeb.Email.weekly_report(email, site,
|
||||
unique_visitors: unique_visitors,
|
||||
unique_visitors: curr_period["visitors"]["value"],
|
||||
change_visitors: change_visitors,
|
||||
pageviews: pageviews,
|
||||
pageviews: curr_period["pageviews"]["value"],
|
||||
change_pageviews: change_pageviews,
|
||||
bounce_rate: bounce_rate,
|
||||
bounce_rate: curr_period["bounce_rate"]["value"],
|
||||
change_bounce_rate: change_bounce_rate,
|
||||
referrers: referrers,
|
||||
sources: sources,
|
||||
unsubscribe_link: unsubscribe_link,
|
||||
login_link: login_link,
|
||||
pages: pages,
|
||||
|
3
mix.exs
3
mix.exs
@ -101,7 +101,8 @@ defmodule Plausible.MixProject do
|
||||
{:opentelemetry_exporter, "1.0.0-rc.3"},
|
||||
{:opentelemetry_phoenix, "1.0.0-rc.5"},
|
||||
{:opentelemetry_ecto, "1.0.0-rc.3"},
|
||||
{:opentelemetry_oban, "~> 0.2.0-rc.2"}
|
||||
{:opentelemetry_oban, "~> 0.2.0-rc.2"},
|
||||
{:floki, "~> 0.32.0", only: :test}
|
||||
]
|
||||
end
|
||||
|
||||
|
2
mix.lock
2
mix.lock
@ -37,6 +37,7 @@
|
||||
"ex_machina": {:hex, :ex_machina, "2.7.0", "b792cc3127fd0680fecdb6299235b4727a4944a09ff0fa904cc639272cd92dc7", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "419aa7a39bde11894c87a615c4ecaa52d8f107bbdd81d810465186f783245bf8"},
|
||||
"excoveralls": {:hex, :excoveralls, "0.14.4", "295498f1ae47bdc6dce59af9a585c381e1aefc63298d48172efaaa90c3d251db", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e3ab02f2df4c1c7a519728a6f0a747e71d7d6e846020aae338173619217931c1"},
|
||||
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
|
||||
"floki": {:hex, :floki, "0.32.0", "f915dc15258bc997d49be1f5ef7d3992f8834d6f5695270acad17b41f5bcc8e2", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "1c5a91cae1fd8931c26a4826b5e2372c284813904c8bacb468b5de39c7ececbd"},
|
||||
"gen_smtp": {:hex, :gen_smtp, "1.1.1", "bf9303c31735100631b1d708d629e4c65944319d1143b5c9952054f4a1311d85", [:rebar3], [{:hut, "1.3.0", [hex: :hut, repo: "hexpm", optional: false]}, {:ranch, ">= 1.7.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "51bc50cc017efd4a4248cbc39ea30fb60efa7d4a49688986fafad84434ff9ab7"},
|
||||
"geolix": {:hex, :geolix, "1.1.0", "8b0fe847fef486d9e8b7c21eae6cbc2d998fb249e61d3f4f136f8016b9c1c833", [:mix], [{:poolboy, "~> 1.0", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "980854f2aef30c288dc79e86c5267806d704c4525fde1b75de9a92f67fb16300"},
|
||||
"geolix_adapter_mmdb2": {:hex, :geolix_adapter_mmdb2, "0.5.0", "5912723d9538ecddc6b29b1d8041b917b735a78fd3c122bfea8c44aa782e3369", [:mix], [{:geolix, "~> 1.1", [hex: :geolix, repo: "hexpm", optional: false]}, {:mmdb2_decoder, "~> 3.0", [hex: :mmdb2_decoder, repo: "hexpm", optional: false]}], "hexpm", "cb1485b6a0a2d3e541949207428a245718dbf1258453a0df0e5fdd925bcecd3e"},
|
||||
@ -46,6 +47,7 @@
|
||||
"hackney": {:hex, :hackney, "1.18.0", "c4443d960bb9fba6d01161d01cd81173089686717d9490e5d3606644c48d121f", [:rebar3], [{:certifi, "~>2.8.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "9afcda620704d720db8c6a3123e9848d09c87586dc1c10479c42627b905b5c5e"},
|
||||
"hammer": {:hex, :hammer, "6.0.0", "72ec6fff10e9d63856968988a22ee04c4d6d5248071ddccfbda50aa6c455c1d7", [:mix], [{:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "d8e1ec2e534c4aae508b906759e077c3c1eb3e2b9425235d4b7bbab0b016210a"},
|
||||
"hpack": {:hex, :hpack_erl, "0.2.3", "17670f83ff984ae6cd74b1c456edde906d27ff013740ee4d9efaa4f1bf999633", [:rebar3], [], "hexpm", "06f580167c4b8b8a6429040df36cc93bba6d571faeaec1b28816523379cbb23a"},
|
||||
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
|
||||
"httpoison": {:hex, :httpoison, "1.8.0", "6b85dea15820b7804ef607ff78406ab449dd78bed923a49c7160e1886e987a3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "28089eaa98cf90c66265b6b5ad87c59a3729bea2e74e9d08f9b51eb9729b3c3a"},
|
||||
"hut": {:hex, :hut, "1.3.0", "71f2f054e657c03f959cf1acc43f436ea87580696528ca2a55c8afb1b06c85e7", [:"erlang.mk", :rebar, :rebar3], [], "hexpm", "7e15d28555d8a1f2b5a3a931ec120af0753e4853a4c66053db354f35bf9ab563"},
|
||||
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
|
||||
|
@ -60,6 +60,51 @@ defmodule Plausible.Workers.SendEmailReportTest do
|
||||
assert html_body =~
|
||||
~s(<span id="visitors" style="line-height: 24px; font-size: 20px;">2</span>)
|
||||
end
|
||||
|
||||
test "includes the correct stats" do
|
||||
site = insert(:site, domain: "test-site.com")
|
||||
insert(:weekly_report, site: site, recipients: ["user@email.com"])
|
||||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
|
||||
populate_stats(site, [
|
||||
build(:pageview,
|
||||
referrer_source: "Google",
|
||||
user_id: 123,
|
||||
timestamp: Timex.shift(now, days: -7)
|
||||
),
|
||||
build(:pageview, user_id: 123, timestamp: Timex.shift(now, days: -7)),
|
||||
build(:pageview, timestamp: Timex.shift(now, days: -7))
|
||||
])
|
||||
|
||||
perform_job(SendEmailReport, %{"site_id" => site.id, "interval" => "weekly"})
|
||||
|
||||
assert_delivered_email_matches(%{
|
||||
to: [nil: "user@email.com"],
|
||||
html_body: html_body
|
||||
})
|
||||
|
||||
{:ok, document} = Floki.parse_document(html_body)
|
||||
|
||||
visitors = Floki.find(document, "#visitors") |> Floki.text()
|
||||
assert visitors == "2"
|
||||
|
||||
pageviews = Floki.find(document, "#pageviews") |> Floki.text()
|
||||
assert pageviews == "3"
|
||||
|
||||
referrer = Floki.find(document, ".referrer") |> List.first()
|
||||
referrer_name = referrer |> Floki.find("#referrer-name") |> Floki.text()
|
||||
referrer_count = referrer |> Floki.find("#referrer-count") |> Floki.text()
|
||||
|
||||
assert referrer_name == "Google"
|
||||
assert referrer_count == "1"
|
||||
|
||||
page = Floki.find(document, ".page") |> List.first()
|
||||
page_name = page |> Floki.find("#page-name") |> Floki.text()
|
||||
page_count = page |> Floki.find("#page-count") |> Floki.text()
|
||||
|
||||
assert page_name == "/"
|
||||
assert page_count == "2"
|
||||
end
|
||||
end
|
||||
|
||||
describe "monthly_reports" do
|
||||
|
Loading…
Reference in New Issue
Block a user