mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 16:45:35 +01:00
align CH / postgres funnel queries
This commit is contained in:
parent
711ad2bbcf
commit
5a0908964c
3 changed files with 54 additions and 37 deletions
|
|
@ -121,24 +121,47 @@ function getFilterQuery(filters = {}, params = {}) {
|
|||
return query.join('\n');
|
||||
}
|
||||
|
||||
function getFunnelQuery(urls: string[]): {
|
||||
columnsQuery: string;
|
||||
conditionQuery: string;
|
||||
function getFunnelQuery(
|
||||
urls: string[],
|
||||
windowMinutes: number,
|
||||
): {
|
||||
levelQuery: string;
|
||||
sumQuery: string;
|
||||
urlFilterQuery: string;
|
||||
urlParams: { [key: string]: string };
|
||||
} {
|
||||
return urls.reduce(
|
||||
(pv, cv, i) => {
|
||||
pv.columnsQuery += `\n,url_path = {url${i}:String}${
|
||||
i > 0 && urls[i - 1] ? ` AND referrer_path = {url${i - 1}:String}` : ''
|
||||
}`;
|
||||
pv.conditionQuery += `${i > 0 ? ',' : ''} {url${i}:String}`;
|
||||
const levelNumber = i + 1;
|
||||
const startSum = i > 0 ? 'union all ' : '';
|
||||
const startFilter = i > 0 ? ', ' : '';
|
||||
|
||||
if (levelNumber >= 2) {
|
||||
pv.levelQuery += `\n
|
||||
, level${levelNumber} AS (
|
||||
select distinct y.session_id as session_id,
|
||||
y.url_path as url_path,
|
||||
y.referrer_path as referrer_path,
|
||||
y.created_at as created_at
|
||||
from level${i} x
|
||||
join level0 y
|
||||
on x.session_id = y.session_id
|
||||
where y.created_at between x.created_at and x.created_at + interval ${windowMinutes} minute
|
||||
and y.referrer_path = {url${i - 1}:String}
|
||||
and y.url_path = {url${i}:String}
|
||||
)`;
|
||||
}
|
||||
|
||||
pv.sumQuery += `\n${startSum}select ${levelNumber} as level, count(distinct(session_id)) as count from level${levelNumber}`;
|
||||
pv.urlFilterQuery += `${startFilter}{url${i}:String} `;
|
||||
pv.urlParams[`url${i}`] = cv;
|
||||
|
||||
return pv;
|
||||
},
|
||||
{
|
||||
columnsQuery: '',
|
||||
conditionQuery: '',
|
||||
levelQuery: '',
|
||||
sumQuery: '',
|
||||
urlFilterQuery: '',
|
||||
urlParams: {},
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ function getFunnelQuery(
|
|||
if (levelNumber >= 2) {
|
||||
pv.levelQuery += `\n
|
||||
, level${levelNumber} AS (
|
||||
select distinct l.session_id, we.created_at
|
||||
select distinct we.session_id, we.created_at
|
||||
from level${i} l
|
||||
join website_event we
|
||||
on l.session_id = we.session_id
|
||||
|
|
@ -161,7 +161,7 @@ function getFunnelQuery(
|
|||
and ${getAddMinutesQuery(`l.created_at `, windowMinutes)}
|
||||
and we.referrer_path = $${i + initParamLength}
|
||||
and we.url_path = $${levelNumber + initParamLength}
|
||||
and we.created_at between $2 and $3
|
||||
and we.created_at <= $3
|
||||
and we.website_id = $1${toUuid()}
|
||||
)`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue