add entry/exit pages panel to analytics dashboard
All checks were successful
deploy / deploy (push) Successful in 1m28s
All checks were successful
deploy / deploy (push) Successful in 1m28s
ROW_NUMBER() window function picks first/last pageview per session. Both tables live in the pages tab and support the pathname filter. 6 new tests, 1061 total. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -302,6 +302,68 @@ defmodule Berrypod.Analytics do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Top entry pages — the first page visited per session, by session count.
|
||||
"""
|
||||
def entry_pages(date_range, opts \\ []) do
|
||||
limit = Keyword.get(opts, :limit, 10)
|
||||
filters = Keyword.get(opts, :filters, %{})
|
||||
|
||||
inner =
|
||||
base_query(date_range, filters)
|
||||
|> where([e], e.name == "pageview")
|
||||
|> select([e], %{
|
||||
session_hash: e.session_hash,
|
||||
pathname: e.pathname,
|
||||
rn:
|
||||
fragment(
|
||||
"ROW_NUMBER() OVER (PARTITION BY ? ORDER BY ? ASC)",
|
||||
e.session_hash,
|
||||
e.inserted_at
|
||||
)
|
||||
})
|
||||
|
||||
from(s in subquery(inner),
|
||||
where: s.rn == 1,
|
||||
group_by: s.pathname,
|
||||
select: %{pathname: s.pathname, sessions: count()},
|
||||
order_by: [desc: count()],
|
||||
limit: ^limit
|
||||
)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Top exit pages — the last page visited per session, by session count.
|
||||
"""
|
||||
def exit_pages(date_range, opts \\ []) do
|
||||
limit = Keyword.get(opts, :limit, 10)
|
||||
filters = Keyword.get(opts, :filters, %{})
|
||||
|
||||
inner =
|
||||
base_query(date_range, filters)
|
||||
|> where([e], e.name == "pageview")
|
||||
|> select([e], %{
|
||||
session_hash: e.session_hash,
|
||||
pathname: e.pathname,
|
||||
rn:
|
||||
fragment(
|
||||
"ROW_NUMBER() OVER (PARTITION BY ? ORDER BY ? DESC)",
|
||||
e.session_hash,
|
||||
e.inserted_at
|
||||
)
|
||||
})
|
||||
|
||||
from(s in subquery(inner),
|
||||
where: s.rn == 1,
|
||||
group_by: s.pathname,
|
||||
select: %{pathname: s.pathname, sessions: count()},
|
||||
order_by: [desc: count()],
|
||||
limit: ^limit
|
||||
)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes events older than the given datetime. Used by the retention worker.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user