diff --git a/docker-compose.yml b/docker-compose.yml index 348c294ca..bc8d8da08 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,7 @@ services: environment: DATABASE_URL: postgresql://umami:umami@db:5432/umami APP_SECRET: replace-me-with-a-random-string + # BOUNCE_THRESHOLD: 2 # OPTIONAL: set the minimum amount custom events to trigger a bounce depends_on: db: condition: service_healthy diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 89e250e73..b3bf04505 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -1,4 +1,8 @@ export const CURRENT_VERSION = process.env.currentVersion; +export const BOUNCE_THRESHOLD = Math.max( + 1, + Number.parseInt(process.env.BOUNCE_THRESHOLD || '1', 10) || 1, +); export const AUTH_TOKEN = 'umami.auth'; export const LOCALE_CONFIG = 'umami.locale'; export const TIMEZONE_CONFIG = 'umami.timezone'; diff --git a/src/queries/sql/events/getWebsiteEvents.ts b/src/queries/sql/events/getWebsiteEvents.ts index d7a8ecb63..d5f3376a5 100644 --- a/src/queries/sql/events/getWebsiteEvents.ts +++ b/src/queries/sql/events/getWebsiteEvents.ts @@ -22,8 +22,8 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) { }); const searchQuery = search - ? `and ((event_name ilike {{search}} and event_type = 2) - or (url_path ilike {{search}} and event_type = 1))` + ? `and ((event_name ilike {{search}} and event_type = ${EVENT_TYPE.customEvent}) + or (url_path ilike {{search}} and event_type = ${EVENT_TYPE.pageView}))` : ''; return pagedRawQuery( @@ -77,8 +77,8 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) { }); const searchQuery = search - ? `and ((positionCaseInsensitive(event_name, {search:String}) > 0 and event_type = 2) - or (positionCaseInsensitive(url_path, {search:String}) > 0 and event_type = 1))` + ? `and ((positionCaseInsensitive(event_name, {search:String}) > 0 and event_type = ${EVENT_TYPE.customEvent}) + or (positionCaseInsensitive(url_path, {search:String}) > 0 and event_type = ${EVENT_TYPE.pageView}))` : ''; return pagedRawQuery( diff --git a/src/queries/sql/sessions/getWebsiteSession.ts b/src/queries/sql/sessions/getWebsiteSession.ts index 3ad2c1677..8a4115157 100644 --- a/src/queries/sql/sessions/getWebsiteSession.ts +++ b/src/queries/sql/sessions/getWebsiteSession.ts @@ -49,8 +49,8 @@ async function relationalQuery(websiteId: string, sessionId: string) { session.city, min(website_event.created_at) as min_time, max(website_event.created_at) as max_time, - sum(case when website_event.event_type = 1 then 1 else 0 end) as views, - sum(case when website_event.event_type = 2 then 1 else 0 end) as events + sum(case when website_event.event_type = ${EVENT_TYPE.pageView} then 1 else 0 end) as views, + sum(case when website_event.event_type = ${EVENT_TYPE.customEvent} then 1 else 0 end) as events from session join website_event on website_event.session_id = session.session_id where session.website_id = {{websiteId::uuid}} diff --git a/src/queries/sql/sessions/getWebsiteSessionStats.ts b/src/queries/sql/sessions/getWebsiteSessionStats.ts index a14fbc5f3..316288eaf 100644 --- a/src/queries/sql/sessions/getWebsiteSessionStats.ts +++ b/src/queries/sql/sessions/getWebsiteSessionStats.ts @@ -36,11 +36,11 @@ async function relationalQuery( return rawQuery( ` select - sum(case when website_event.event_type = 1 then 1 else 0 end) as "pageviews", + sum(case when website_event.event_type = ${EVENT_TYPE.pageView} 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", - sum(case when website_event.event_type = 2 then 1 else 0 end) as "events" + sum(case when website_event.event_type = ${EVENT_TYPE.customEvent} then 1 else 0 end) as "events" from website_event ${cohortQuery} join session on website_event.session_id = session.session_id @@ -67,11 +67,11 @@ async function clickhouseQuery( if (EVENT_COLUMNS.some(item => Object.keys(filters).includes(item))) { sql = ` select - sumIf(1, event_type = 1) as "pageviews", + sumIf(1, event_type = ${EVENT_TYPE.pageView}) as "pageviews", uniq(session_id) as "visitors", uniq(visit_id) as "visits", uniq(country) as "countries", - sumIf(1, event_type = 2) as "events" + sumIf(1, event_type = ${EVENT_TYPE.customEvent}) as "events" from website_event ${cohortQuery} where website_id = {websiteId:UUID} diff --git a/src/queries/sql/sessions/getWebsiteSessions.ts b/src/queries/sql/sessions/getWebsiteSessions.ts index 6e41a47c3..641099469 100644 --- a/src/queries/sql/sessions/getWebsiteSessions.ts +++ b/src/queries/sql/sessions/getWebsiteSessions.ts @@ -50,8 +50,8 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) { min(website_event.created_at) as "firstAt", max(website_event.created_at) as "lastAt", count(distinct website_event.visit_id) as "visits", - sum(case when website_event.event_type = 1 then 1 else 0 end) as "views", - sum(case when website_event.event_type = 2 then 1 else 0 end) as "events", + sum(case when website_event.event_type = ${EVENT_TYPE.pageView} then 1 else 0 end) as "views", + sum(case when website_event.event_type = ${EVENT_TYPE.customEvent} then 1 else 0 end) as "events", max(website_event.created_at) as "createdAt" from website_event ${cohortQuery} @@ -125,8 +125,8 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) { ${getDateStringSQL('min(created_at)')} as firstAt, ${getDateStringSQL('max(created_at)')} as lastAt, uniq(visit_id) as visits, - sumIf(1, event_type = 1) as views, - sumIf(1, event_type = 2) as events, + sumIf(1, event_type = ${EVENT_TYPE.pageView}) as views, + sumIf(1, event_type = ${EVENT_TYPE.customEvent}) as events, max(created_at) as createdAt from website_event ${cohortQuery} @@ -155,7 +155,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) { ${getDateStringSQL('min(min_time)')} as firstAt, ${getDateStringSQL('max(max_time)')} as lastAt, uniq(visit_id) as visits, - sumIf(views, event_type = 1) as views, + sumIf(views, event_type = ${EVENT_TYPE.pageView}) as views, sum(length(event_name)) as events, max(max_time) as createdAt from website_event_stats_hourly as website_event