mirror of
https://github.com/plausible/analytics.git
synced 2024-12-26 11:02:52 +03:00
Minor rework
This commit is contained in:
parent
7f33a159bc
commit
9264797265
@ -32,7 +32,6 @@ defmodule Plausible.Funnels do
|
||||
where: f.site_id == ^site_id,
|
||||
select: %{name: f.name, id: f.id}
|
||||
)
|
||||
|> IO.inspect(label: :listing_funnels)
|
||||
end
|
||||
|
||||
def get(%Plausible.Site{id: site_id}, by) do
|
||||
@ -72,11 +71,11 @@ defmodule Plausible.Funnels do
|
||||
select: {f.step, count(1)},
|
||||
group_by: f.step
|
||||
|
||||
funnel_result =
|
||||
ClickhouseRepo.all(query)
|
||||
steps =
|
||||
query
|
||||
|> ClickhouseRepo.all()
|
||||
|> Enum.into(%{})
|
||||
|
||||
steps = update_step_defaults(funnel, funnel_result)
|
||||
|> backfill_steps(funnel)
|
||||
|
||||
%{
|
||||
name: funnel.name,
|
||||
@ -123,23 +122,20 @@ defmodule Plausible.Funnels do
|
||||
)
|
||||
end
|
||||
|
||||
defp update_step_defaults(funnel, funnel_result) do
|
||||
defp backfill_steps(funnel_result, funnel) do
|
||||
max_step = Enum.max_by(funnel.steps, & &1.step_order).step_order
|
||||
|
||||
funnel.steps
|
||||
funnel
|
||||
|> Map.fetch!(:steps)
|
||||
|> Enum.map(fn step ->
|
||||
label = Plausible.Goal.display_name(step.goal)
|
||||
|
||||
visitors_total =
|
||||
Enum.reduce(step.step_order..max_step, 0, fn step_order, acc ->
|
||||
visitors = Map.get(funnel_result, step_order, 0)
|
||||
|
||||
acc + visitors
|
||||
acc + Map.get(funnel_result, step_order, 0)
|
||||
end)
|
||||
|
||||
%{
|
||||
visitors: visitors_total,
|
||||
label: label
|
||||
label: Plausible.Goal.display_name(step.goal)
|
||||
}
|
||||
end)
|
||||
end
|
||||
|
@ -258,10 +258,7 @@ defmodule PlausibleWeb.SiteController do
|
||||
sanitized_params =
|
||||
["step_1", "step_2", "step_3", "step_4", "step_5"]
|
||||
|> Enum.map(¶ms[&1])
|
||||
|> Enum.filter(fn
|
||||
"" -> false
|
||||
goal_id -> true
|
||||
end)
|
||||
|> Enum.reject(fn v == "")
|
||||
|> Enum.map(fn goal_id -> %{id: String.to_integer(goal_id)} end)
|
||||
|> IO.inspect(label: :params)
|
||||
|
||||
|
@ -293,6 +293,7 @@ defmodule PlausibleWeb.StatsController do
|
||||
|> render("stats.html",
|
||||
site: shared_link.site,
|
||||
has_goals: Sites.has_goals?(shared_link.site),
|
||||
funnels: nil,
|
||||
stats_start_date: shared_link.site.stats_start_date,
|
||||
native_stats_start_date: NaiveDateTime.to_date(shared_link.site.native_stats_start_at),
|
||||
title: "Plausible · " <> shared_link.site.domain,
|
||||
|
@ -57,7 +57,7 @@ defmodule Plausible.FunnelsTest do
|
||||
end
|
||||
|
||||
test "a goal can only appear once in a funnel", %{goals: [g1 | _], site: site} do
|
||||
{:error, changeset} =
|
||||
{:error, _changeset} =
|
||||
Funnels.create(
|
||||
site,
|
||||
"Lorem ipsum",
|
||||
|
Loading…
Reference in New Issue
Block a user