diff --git a/src/app/api/websites/[websiteId]/sessions/weekly/route.ts b/src/app/api/websites/[websiteId]/sessions/weekly/route.ts index 50a9f926c..395b4555a 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 { filterParams, pagingParams, timezoneParam } from '@/lib/schema'; +import { pagingParams, timezoneParam } from '@/lib/schema'; import { getWeeklyTraffic } from '@/queries'; export async function GET( @@ -13,7 +13,6 @@ 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 8e713bb0e..59c3ad050 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: 'bar', + type: data.compare ? 'line' : '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: 'bar', + type: data.compare ? 'line' : '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 6a967477e..cc4223135 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; d?: string }[], + data: { x: string; y: number }[], 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, d }) => [formatDate(x, fmt, locale), { x, y, d }])); + const lookup = new Map(data.map(({ x, y }) => [formatDate(x, fmt, locale), { x, y }])); return timeseries.map(t => { - const { x, y, d } = lookup.get(t) || {}; + const { x, y } = lookup.get(t) || {}; - return { x: t, d: d ?? x, y: y ?? null }; + return { x: t, d: x, y: y ?? null }; }); } diff --git a/src/queries/sql/reports/getRetention.ts b/src/queries/sql/reports/getRetention.ts index 15984cd36..67c373f83 100644 --- a/src/queries/sql/reports/getRetention.ts +++ b/src/queries/sql/reports/getRetention.ts @@ -46,16 +46,11 @@ async function relationalQuery( return rawQuery( ` WITH cohort_items AS ( - 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 + select session_id, + ${getDateSQL('created_at', unit)} as cohort_date + from session + where website_id = {{websiteId::uuid}} + and created_at between {{startDate}} and {{endDate}} ), user_activities AS ( select distinct @@ -64,9 +59,11 @@ 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, @@ -124,10 +121,8 @@ 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} - ${filterQuery} + and created_at between {startDate:DateTime64} and {endDate:DateTime64} group by session_id ), user_activities AS ( @@ -137,8 +132,10 @@ 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,