exclude performance events from non-performance metrics/lists

This commit is contained in:
Francis Cao
2026-05-07 14:17:03 -07:00
parent 88ccf5348e
commit 17e7a4a63a
16 changed files with 55 additions and 8 deletions
@@ -1,4 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { QueryFilters } from '@/lib/types';
@@ -55,6 +56,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
join session on session.session_id = website_event.session_id
and session.website_id = website_event.website_id
where website_event.website_id = {{websiteId::uuid}}
and website_event.event_type != ${EVENT_TYPE.performance}
${dateQuery}
${filterQuery}
${searchQuery}
@@ -107,6 +109,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
from website_event
${cohortQuery}
where website_id = {websiteId:UUID}
and event_type != ${EVENT_TYPE.performance}
${dateQuery}
${filterQuery}
${searchQuery}
+3
View File
@@ -1,4 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { QueryFilters } from '@/lib/types';
@@ -38,6 +39,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
on session.session_id = website_event.session_id
and session.website_id = website_event.website_id
where website_event.website_id = {{websiteId::uuid}}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${dateQuery}
order by website_event.created_at desc
@@ -71,6 +73,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters): Promis
from website_event
${cohortQuery}
where website_id = {websiteId:UUID}
and event_type != ${EVENT_TYPE.performance}
${filterQuery}
${dateQuery}
order by createdAt desc
@@ -1,4 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { QueryFilters } from '@/lib/types';
@@ -64,6 +65,7 @@ async function relationalQuery(websiteId: string, currency: string, filters: Que
and upper(currency) = {{currency}}
) rev on rev.session_id = website_event.session_id
where website_event.website_id = {{websiteId::uuid}}
and website_event.event_type != ${EVENT_TYPE.performance}
${dateQuery}
${filterQuery}
${searchQuery}
@@ -126,6 +128,7 @@ async function clickhouseQuery(websiteId: string, currency: string, filters: Que
from website_event
${cohortQuery}
where website_id = {websiteId:UUID}
and event_type != ${EVENT_TYPE.performance}
${dateQuery}
${filterQuery}
${searchQuery}
@@ -1,4 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { QueryFilters } from '@/lib/types';
@@ -37,6 +38,7 @@ async function relationalQuery(websiteId: string, sessionId: string, filters: Qu
from website_event
where website_id = {{websiteId::uuid}}
and session_id = {{sessionId::uuid}}
and event_type != ${EVENT_TYPE.performance}
and created_at between {{startDate}} and {{endDate}}
order by created_at desc
limit 500
@@ -70,6 +72,7 @@ async function clickhouseQuery(websiteId: string, sessionId: string, filters: Qu
from website_event
where website_id = {websiteId:UUID}
and session_id = {sessionId:UUID}
and event_type != ${EVENT_TYPE.performance}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
order by created_at desc
limit 500
@@ -1,5 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { DATA_TYPE } from '@/lib/constants';
import { DATA_TYPE, EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { PropertyFilter, PropertyLeaderboardRow, QueryFilters } from '@/lib/types';
@@ -39,6 +39,7 @@ async function relationalQuery(
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
),
@@ -57,6 +58,7 @@ async function relationalQuery(
and filtered_sessions.website_id = website_event.website_id
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
group by website_event.session_id, website_event.visit_id
),
session_stats as (
@@ -119,6 +121,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
),
@@ -135,6 +138,7 @@ async function clickhouseQuery(
join filtered_sessions on filtered_sessions.session_id = website_event.session_id
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
group by website_event.session_id, website_event.visit_id
),
session_stats as (
@@ -1,5 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { DATA_TYPE } from '@/lib/constants';
import { DATA_TYPE, EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { EventDataSeriesPoint, PropertyFilter, QueryFilters } from '@/lib/types';
@@ -50,6 +50,7 @@ async function relationalQuery(
cross join lateral jsonb_array_elements_text(coalesce(session_data.string_value, '[]')::jsonb) as array_item(value)
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {{propertyName}}
and session_data.data_type = ${DATA_TYPE.array}
${filterQuery}
@@ -86,6 +87,7 @@ async function clickhouseQuery(
and session_data.website_id = {websiteId:UUID}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {propertyName:String}
and session_data.data_type = ${DATA_TYPE.array}
${filterQuery}
@@ -1,5 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { DATA_TYPE } from '@/lib/constants';
import { DATA_TYPE, EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { EventDataDateSeriesPoint, PropertyFilter, QueryFilters } from '@/lib/types';
@@ -48,6 +48,7 @@ async function relationalQuery(
and session_data.website_id = website_event.website_id
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {{propertyName}}
and session_data.data_type = ${DATA_TYPE.date}
${filterQuery}
@@ -83,6 +84,7 @@ async function clickhouseQuery(
and session_data.website_id = {websiteId:UUID}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {propertyName:String}
and session_data.data_type = ${DATA_TYPE.date}
${filterQuery}
@@ -1,4 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { PropertyFilter, QueryFilters } from '@/lib/types';
@@ -51,6 +52,7 @@ async function relationalQuery(
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
)
@@ -98,6 +100,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
)
@@ -1,4 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { EventDataNumericStats, PropertyFilter, QueryFilters } from '@/lib/types';
@@ -43,6 +44,7 @@ async function relationalQuery(
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
)
@@ -84,6 +86,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
)
@@ -1,4 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { PageResult, PropertyFilter, QueryFilters, SessionDataPivotRow } from '@/lib/types';
@@ -48,6 +49,7 @@ async function relationalQuery(
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
),
@@ -141,6 +143,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
),
@@ -1,4 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { PropertyFilter, QueryFilters } from '@/lib/types';
@@ -47,6 +48,7 @@ async function relationalQuery(
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
),
@@ -98,6 +100,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
${pfSQL}
),
@@ -1,5 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { DATA_TYPE } from '@/lib/constants';
import { DATA_TYPE, EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { EventDataSeriesPoint, PropertyFilter, QueryFilters } from '@/lib/types';
@@ -49,6 +49,7 @@ async function relationalQuery(
and session_data.website_id = website_event.website_id
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {{propertyName}}
and session_data.data_type in (${DATA_TYPE.string}, ${DATA_TYPE.boolean})
${filterQuery}
@@ -85,6 +86,7 @@ async function clickhouseQuery(
and session_data.website_id = {websiteId:UUID}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {propertyName:String}
and session_data.data_type in (${DATA_TYPE.string}, ${DATA_TYPE.boolean})
${filterQuery}
@@ -1,5 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { DATA_TYPE } from '@/lib/constants';
import { DATA_TYPE, EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { QueryFilters } from '@/lib/types';
@@ -41,6 +41,7 @@ async function relationalQuery(
cross join lateral jsonb_array_elements_text(coalesce(session_data.string_value, '[]')::jsonb) as array_item(value)
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {{propertyName}}
and session_data.data_type = ${DATA_TYPE.array}
${filterQuery}
@@ -70,6 +71,7 @@ async function relationalQuery(
and session_data.website_id = website_event.website_id
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {{propertyName}}
${dataType ? `and session_data.data_type = ${dataType}` : ''}
${filterQuery}
@@ -103,6 +105,7 @@ async function clickhouseQuery(
and session_data.website_id = {websiteId:UUID}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {propertyName:String}
and session_data.data_type = ${DATA_TYPE.array}
${filterQuery}
@@ -129,6 +132,7 @@ async function clickhouseQuery(
and session_data.website_id = {websiteId:UUID}
where website_event.website_id = {websiteId:UUID}
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and website_event.event_type != ${EVENT_TYPE.performance}
and session_data.data_key = {propertyName:String}
${dataType ? `and session_data.data_type = ${dataType}` : ''}
${filterQuery}
@@ -1,4 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
@@ -54,6 +55,7 @@ async function relationalQuery(websiteId: string, sessionId: string) {
join website_event on website_event.session_id = session.session_id
where session.website_id = {{websiteId::uuid}}
and session.session_id = {{sessionId::uuid}}
and website_event.event_type != ${EVENT_TYPE.performance}
group by session.session_id, session.distinct_id, visit_id, session.website_id, session.browser, session.os, session.device, session.screen, session.language, session.country, session.region, session.city) t
group by id, distinct_id, website_id, browser, os, device, screen, language, country, region, city;
`,
@@ -104,6 +106,7 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
from website_event_stats_hourly
where website_id = {websiteId:UUID}
and session_id = {sessionId:UUID}
and event_type != ${EVENT_TYPE.performance}
group by session_id, distinct_id, visit_id, website_id, browser, os, device, screen, language, country, region, city) t
group by id, websiteId, distinctId, browser, os, device, screen, language, country, region, city;
`,
@@ -1,5 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_COLUMNS } from '@/lib/constants';
import { EVENT_COLUMNS, EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { QueryFilters } from '@/lib/types';
@@ -36,7 +36,7 @@ async function relationalQuery(
return rawQuery(
`
select
count(*) as "pageviews",
sum(case when website_event.event_type = 1 then 1 else 0 end) as "pageviews",
count(distinct website_event.session_id) as "visitors",
count(distinct website_event.visit_id) as "visits",
count(distinct session.country) as "countries",
@@ -47,6 +47,7 @@ async function relationalQuery(
and website_event.website_id = session.website_id
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != ${EVENT_TYPE.performance}
${filterQuery}
`,
queryParams,
@@ -75,6 +76,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type != ${EVENT_TYPE.performance}
${filterQuery}
`;
} else {
@@ -89,6 +91,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type != ${EVENT_TYPE.performance}
${filterQuery}
`;
}
@@ -1,5 +1,5 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_COLUMNS } from '@/lib/constants';
import { EVENT_COLUMNS, EVENT_TYPE } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import type { QueryFilters } from '@/lib/types';
@@ -55,6 +55,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
join session on session.session_id = website_event.session_id
and session.website_id = website_event.website_id
where website_event.website_id = {{websiteId::uuid}}
and website_event.event_type != ${EVENT_TYPE.performance}
${dateQuery}
${filterQuery}
${searchQuery}
@@ -118,6 +119,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
from website_event
${cohortQuery}
where website_id = {websiteId:UUID}
and event_type != ${EVENT_TYPE.performance}
${dateQuery}
${filterQuery}
${searchQuery}
@@ -147,6 +149,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
from website_event_stats_hourly as website_event
${cohortQuery}
where website_id = {websiteId:UUID}
and event_type != ${EVENT_TYPE.performance}
${dateQuery}
${filterQuery}
${searchQuery}