Fix billing usage section

This commit is contained in:
Uku Taht 2021-03-17 15:03:41 +02:00
parent e8cb4ddefb
commit 06177b84e6
2 changed files with 7 additions and 8 deletions

View File

@ -183,8 +183,8 @@ defmodule Plausible.Billing do
Enum.reduce(user.sites, {0, 0}, fn site, {pageviews, custom_events} ->
usage = Plausible.Stats.Clickhouse.usage(site)
{pageviews + Map.get(usage, :pageviews, 0),
custom_events + Map.get(usage, :custom_events, 0)}
{pageviews + Map.get(usage, "pageviews", 0),
custom_events + Map.get(usage, "custom_events", 0)}
end)
end

View File

@ -181,13 +181,12 @@ defmodule Plausible.Stats.Clickhouse do
from e in "events",
where: e.domain == ^site.domain,
where: e.timestamp >= ^first_datetime and e.timestamp < ^last_datetime,
group_by: e.name,
select: {e.name, fragment("count(*)")}
group_by: fragment("name"),
select: {
fragment("if(? = 'pageview', 'pageviews', 'custom_events') as name", e.name),
fragment("count(*)")
}
)
|> Enum.map(fn {ev_name, count} ->
ev_name = if ev_name == "pageview", do: :pageviews, else: :custom_events
{ev_name, count}
end)
|> Enum.into(%{})
end