diff --git a/queries/analytics/sessions/getSessionMetrics.ts b/queries/analytics/sessions/getSessionMetrics.ts index 5ef387ecf4..f9bc2e942f 100644 --- a/queries/analytics/sessions/getSessionMetrics.ts +++ b/queries/analytics/sessions/getSessionMetrics.ts @@ -21,15 +21,15 @@ async function relationalQuery(websiteId: string, column: string, filters: Query }); return rawQuery( - `select ${column} x, count(*) y - from website_event - inner join session - on session.session_id = website_event.session_id - where website_event.website_id = {{websiteId::uuid}} - and website_event.created_at between {{startDate}} and {{endDate}} - and website_event.event_type = {{eventType}} - ${filterQuery} - ) as t + ` + select ${column} x, count(*) y + from website_event + inner join session + on session.session_id = website_event.session_id + where website_event.website_id = {{websiteId::uuid}} + and website_event.created_at between {{startDate}} and {{endDate}} + and website_event.event_type = {{eventType}} + ${filterQuery} group by 1 order by 2 desc limit 100`, diff --git a/queries/analytics/sessions/getSessionStats.ts b/queries/analytics/sessions/getSessionStats.ts index b8884a44e9..9ed01a5948 100644 --- a/queries/analytics/sessions/getSessionStats.ts +++ b/queries/analytics/sessions/getSessionStats.ts @@ -14,7 +14,7 @@ export async function getSessionStats(...args: [websiteId: string, filters: Quer async function relationalQuery(websiteId: string, filters: QueryFilters) { const { timezone = 'utc', unit = 'day' } = filters; const { getDateQuery, parseFilters, rawQuery } = prisma; - const { filterQuery, params } = await parseFilters(websiteId, { + const { filterQuery, joinSession, params } = await parseFilters(websiteId, { ...filters, eventType: EVENT_TYPE.pageView, }); @@ -25,8 +25,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) { ${getDateQuery('website_event.created_at', unit, timezone)} x, count(distinct website_event.session_id) y from website_event - inner join session - on session.session_id = website_event.session_id + ${joinSession} where website_event.website_id = {{websiteId::uuid}} and website_event.created_at between {{startDate}} and {{endDate}} and event_type = {{eventType}}