mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
fix cohort query for retention report, add filters to weekly traffic route
This commit is contained in:
parent
27c342811e
commit
9d49eaebac
2 changed files with 16 additions and 12 deletions
|
|
@ -2,7 +2,7 @@ import { z } from 'zod';
|
||||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||||
import { unauthorized, json } from '@/lib/response';
|
import { unauthorized, json } from '@/lib/response';
|
||||||
import { canViewWebsite } from '@/permissions';
|
import { canViewWebsite } from '@/permissions';
|
||||||
import { pagingParams, timezoneParam } from '@/lib/schema';
|
import { filterParams, pagingParams, timezoneParam } from '@/lib/schema';
|
||||||
import { getWeeklyTraffic } from '@/queries';
|
import { getWeeklyTraffic } from '@/queries';
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
|
|
@ -13,6 +13,7 @@ export async function GET(
|
||||||
startAt: z.coerce.number().int(),
|
startAt: z.coerce.number().int(),
|
||||||
endAt: z.coerce.number().int(),
|
endAt: z.coerce.number().int(),
|
||||||
timezone: timezoneParam,
|
timezone: timezoneParam,
|
||||||
|
...filterParams,
|
||||||
...pagingParams,
|
...pagingParams,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,11 +46,16 @@ async function relationalQuery(
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
`
|
`
|
||||||
WITH cohort_items AS (
|
WITH cohort_items AS (
|
||||||
select session_id,
|
select
|
||||||
${getDateSQL('created_at', unit)} as cohort_date
|
min(${getDateSQL('website_event.created_at', unit, timezone)}) as cohort_date,
|
||||||
from session
|
website_event.session_id
|
||||||
where website_id = {{websiteId::uuid}}
|
from website_event
|
||||||
and created_at between {{startDate}} and {{endDate}}
|
${cohortQuery}
|
||||||
|
${joinSessionQuery}
|
||||||
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
|
${filterQuery}
|
||||||
|
group by website_event.session_id
|
||||||
),
|
),
|
||||||
user_activities AS (
|
user_activities AS (
|
||||||
select distinct
|
select distinct
|
||||||
|
|
@ -59,11 +64,9 @@ async function relationalQuery(
|
||||||
from website_event
|
from website_event
|
||||||
join cohort_items
|
join cohort_items
|
||||||
on website_event.session_id = cohort_items.session_id
|
on website_event.session_id = cohort_items.session_id
|
||||||
${cohortQuery}
|
|
||||||
${joinSessionQuery}
|
|
||||||
where website_id = {{websiteId::uuid}}
|
where website_id = {{websiteId::uuid}}
|
||||||
and created_at between {{startDate}} and {{endDate}}
|
and created_at between {{startDate}} and {{endDate}}
|
||||||
${filterQuery}
|
|
||||||
),
|
),
|
||||||
cohort_size as (
|
cohort_size as (
|
||||||
select cohort_date,
|
select cohort_date,
|
||||||
|
|
@ -121,8 +124,10 @@ async function clickhouseQuery(
|
||||||
min(${getDateSQL('created_at', unit, timezone)}) as cohort_date,
|
min(${getDateSQL('created_at', unit, timezone)}) as cohort_date,
|
||||||
session_id
|
session_id
|
||||||
from website_event
|
from website_event
|
||||||
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
${filterQuery}
|
||||||
group by session_id
|
group by session_id
|
||||||
),
|
),
|
||||||
user_activities AS (
|
user_activities AS (
|
||||||
|
|
@ -132,10 +137,8 @@ async function clickhouseQuery(
|
||||||
from website_event
|
from website_event
|
||||||
join cohort_items
|
join cohort_items
|
||||||
on website_event.session_id = cohort_items.session_id
|
on website_event.session_id = cohort_items.session_id
|
||||||
${cohortQuery}
|
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
${filterQuery}
|
|
||||||
),
|
),
|
||||||
cohort_size as (
|
cohort_size as (
|
||||||
select cohort_date,
|
select cohort_date,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue