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