Fix excludeBounce query, simplify bounce definition for SPA websites, query routing for performance, add tests

This commit is contained in:
Francis Cao committed 2026-07-30 09:34:35 -07:00
1 parent 0a80d09d0b
commit b3aec54bb3
12 files changed
+410 -150

No files matched your search

+6 -2
View File
@@ -177,13 +177,17 @@ function getExcludeBounceQuery(filters: Record<string, any>) {
}
return `join
(select distinct session_id as exclude_session_id, visit_id as exclude_visit_id
(select session_id as exclude_session_id, visit_id as exclude_visit_id
from website_event_stats_hourly
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = 1
and event_type != 5
group by session_id, visit_id
having sum(views) > 1
or (
sum(views) = 1
and sumIf(length(event_name), event_type = 2) > 0
)
) excludeBounce
on excludeBounce.exclude_session_id = website_event.session_id
and excludeBounce.exclude_visit_id = website_event.visit_id
-1
View File
@@ -1,5 +1,4 @@
export const CURRENT_VERSION = process.env.currentVersion;
export const BOUNCE_THRESHOLD = Math.max(1, Number.parseInt(process.env.BOUNCE_THRESHOLD, 10) || 1);
export const AUTH_TOKEN = 'umami.auth';
export const LOCALE_CONFIG = 'umami.locale';
export const TIMEZONE_CONFIG = 'umami.timezone';
+8 -10
View File
@@ -2,13 +2,7 @@ import { PrismaPg } from '@prisma/adapter-pg';
import { readReplicas } from '@prisma/extension-read-replicas';
import debug from 'debug';
import { PrismaClient } from '@/generated/prisma/client';
import {
DATA_TYPE,
DEFAULT_PAGE_SIZE,
FILTER_COLUMNS,
OPERATORS,
SESSION_COLUMNS,
} from './constants';
import { DATA_TYPE, DEFAULT_PAGE_SIZE, FILTER_COLUMNS, OPERATORS, SESSION_COLUMNS } from './constants';
import { filtersObjectToArray } from './params';
import type { Operator, PropertyFilter, QueryFilters, QueryOptions } from './types';
@@ -249,13 +243,17 @@ function getExcludeBounceQuery(filters: Record<string, any>) {
}
return `join
(select distinct session_id, visit_id
(select session_id, visit_id
from website_event
where website_id = {{websiteId}}
and created_at between {{startDate}} and {{endDate}}
and event_type = 1
and event_type != 5
group by session_id, visit_id
having count(*) > 1
having sum(case when event_type NOT IN (2, 5) then 1 else 0 end) > 1
or (
sum(case when event_type NOT IN (2, 5) then 1 else 0 end) = 1
and sum(case when event_type = 2 then 1 else 0 end) > 0
)
) excludeBounce
on excludeBounce.session_id = website_event.session_id
and excludeBounce.visit_id = website_event.visit_id