Skip to content

Commit

Permalink
Fixed session queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Aug 4, 2023
1 parent c0ef8da commit 2559263
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 9 additions & 9 deletions queries/analytics/sessions/getSessionMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
5 changes: 2 additions & 3 deletions queries/analytics/sessions/getSessionStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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}}
Expand Down

0 comments on commit 2559263

Please sign in to comment.