diff --git a/src/app/api/websites/[websiteId]/sessions/weekly/route.ts b/src/app/api/websites/[websiteId]/sessions/weekly/route.ts index 395b4555a..50a9f926c 100644 --- a/src/app/api/websites/[websiteId]/sessions/weekly/route.ts +++ b/src/app/api/websites/[websiteId]/sessions/weekly/route.ts @@ -2,7 +2,7 @@ import { z } from 'zod'; import { getQueryFilters, parseRequest } from '@/lib/request'; import { unauthorized, json } from '@/lib/response'; import { canViewWebsite } from '@/permissions'; -import { pagingParams, timezoneParam } from '@/lib/schema'; +import { filterParams, pagingParams, timezoneParam } from '@/lib/schema'; import { getWeeklyTraffic } from '@/queries'; export async function GET( @@ -13,6 +13,7 @@ export async function GET( startAt: z.coerce.number().int(), endAt: z.coerce.number().int(), timezone: timezoneParam, + ...filterParams, ...pagingParams, }); diff --git a/src/components/metrics/PageviewsChart.tsx b/src/components/metrics/PageviewsChart.tsx index 59c3ad050..8e713bb0e 100644 --- a/src/components/metrics/PageviewsChart.tsx +++ b/src/components/metrics/PageviewsChart.tsx @@ -31,7 +31,7 @@ export function PageviewsChart({ data, unit, minDate, maxDate, ...props }: Pagev __id: new Date().getTime(), datasets: [ { - type: data.compare ? 'line' : 'bar', + type: 'bar', label: formatMessage(labels.visitors), data: generateTimeSeries(data.sessions, minDate, maxDate, unit, dateLocale), borderWidth: 1, @@ -41,7 +41,7 @@ export function PageviewsChart({ data, unit, minDate, maxDate, ...props }: Pagev order: 3, }, { - type: data.compare ? 'line' : 'bar', + type: 'bar', label: formatMessage(labels.views), data: generateTimeSeries(data.pageviews, minDate, maxDate, unit, dateLocale), barPercentage: 0.9, diff --git a/src/lib/date.ts b/src/lib/date.ts index cc4223135..6a967477e 100644 --- a/src/lib/date.ts +++ b/src/lib/date.ts @@ -325,7 +325,7 @@ export function formatDate( } export function generateTimeSeries( - data: { x: string; y: number }[], + data: { x: string; y: number; d?: string }[], minDate: Date, maxDate: Date, unit: string, @@ -345,12 +345,12 @@ export function generateTimeSeries( current = add(current, 1); } - const lookup = new Map(data.map(({ x, y }) => [formatDate(x, fmt, locale), { x, y }])); + const lookup = new Map(data.map(({ x, y, d }) => [formatDate(x, fmt, locale), { x, y, d }])); return timeseries.map(t => { - const { x, y } = lookup.get(t) || {}; + const { x, y, d } = lookup.get(t) || {}; - return { x: t, d: x, y: y ?? null }; + return { x: t, d: d ?? x, y: y ?? null }; }); } diff --git a/src/queries/sql/reports/getRetention.ts b/src/queries/sql/reports/getRetention.ts index 67c373f83..15984cd36 100644 --- a/src/queries/sql/reports/getRetention.ts +++ b/src/queries/sql/reports/getRetention.ts @@ -46,11 +46,16 @@ async function relationalQuery( return rawQuery( ` WITH cohort_items AS ( - select session_id, - ${getDateSQL('created_at', unit)} as cohort_date - from session - where website_id = {{websiteId::uuid}} - and created_at between {{startDate}} and {{endDate}} + select + min(${getDateSQL('website_event.created_at', unit, timezone)}) as cohort_date, + website_event.session_id + from website_event + ${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 ( select distinct @@ -59,11 +64,9 @@ async function relationalQuery( from website_event join cohort_items on website_event.session_id = cohort_items.session_id - ${cohortQuery} - ${joinSessionQuery} where website_id = {{websiteId::uuid}} and created_at between {{startDate}} and {{endDate}} - ${filterQuery} + ), cohort_size as ( select cohort_date, @@ -121,8 +124,10 @@ async function clickhouseQuery( min(${getDateSQL('created_at', unit, timezone)}) as cohort_date, session_id from website_event + ${cohortQuery} 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 ), user_activities AS ( @@ -132,10 +137,8 @@ async function clickhouseQuery( from website_event join cohort_items on website_event.session_id = cohort_items.session_id - ${cohortQuery} where website_id = {websiteId:UUID} and created_at between {startDate:DateTime64} and {endDate:DateTime64} - ${filterQuery} ), cohort_size as ( select cohort_date,