refactor(queries): replace hardcoded event types with constants
Replaced hardcoded `event_type` values with named constants from `EVENT_TYPE`, as in #3614. Added the `BOUNCE_THRESHOLD` constant and documented it in `docker-compose.yml`.
This commit is contained in:
1 parent
9b41053d47
commit
19fcde2c9c
6 files changed
+20
-15
No files matched your search
@@ -7,6 +7,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
DATABASE_URL: postgresql://umami:umami@db:5432/umami
|
DATABASE_URL: postgresql://umami:umami@db:5432/umami
|
||||||
APP_SECRET: replace-me-with-a-random-string
|
APP_SECRET: replace-me-with-a-random-string
|
||||||
|
# BOUNCE_THRESHOLD: 2 # OPTIONAL: set the minimum amount custom events to trigger a bounce
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
export const CURRENT_VERSION = process.env.currentVersion;
|
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 AUTH_TOKEN = 'umami.auth';
|
||||||
export const LOCALE_CONFIG = 'umami.locale';
|
export const LOCALE_CONFIG = 'umami.locale';
|
||||||
export const TIMEZONE_CONFIG = 'umami.timezone';
|
export const TIMEZONE_CONFIG = 'umami.timezone';
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const searchQuery = search
|
const searchQuery = search
|
||||||
? `and ((event_name ilike {{search}} and event_type = 2)
|
? `and ((event_name ilike {{search}} and event_type = ${EVENT_TYPE.customEvent})
|
||||||
or (url_path ilike {{search}} and event_type = 1))`
|
or (url_path ilike {{search}} and event_type = ${EVENT_TYPE.pageView}))`
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
return pagedRawQuery(
|
return pagedRawQuery(
|
||||||
@@ -77,8 +77,8 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const searchQuery = search
|
const searchQuery = search
|
||||||
? `and ((positionCaseInsensitive(event_name, {search:String}) > 0 and event_type = 2)
|
? `and ((positionCaseInsensitive(event_name, {search:String}) > 0 and event_type = ${EVENT_TYPE.customEvent})
|
||||||
or (positionCaseInsensitive(url_path, {search:String}) > 0 and event_type = 1))`
|
or (positionCaseInsensitive(url_path, {search:String}) > 0 and event_type = ${EVENT_TYPE.pageView}))`
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
return pagedRawQuery(
|
return pagedRawQuery(
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ async function relationalQuery(websiteId: string, sessionId: string) {
|
|||||||
session.city,
|
session.city,
|
||||||
min(website_event.created_at) as min_time,
|
min(website_event.created_at) as min_time,
|
||||||
max(website_event.created_at) as max_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 = ${EVENT_TYPE.pageView} 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.customEvent} then 1 else 0 end) as events
|
||||||
from session
|
from session
|
||||||
join website_event on website_event.session_id = session.session_id
|
join website_event on website_event.session_id = session.session_id
|
||||||
where session.website_id = {{websiteId::uuid}}
|
where session.website_id = {{websiteId::uuid}}
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ async function relationalQuery(
|
|||||||
return rawQuery(
|
return rawQuery(
|
||||||
`
|
`
|
||||||
select
|
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.session_id) as "visitors",
|
||||||
count(distinct website_event.visit_id) as "visits",
|
count(distinct website_event.visit_id) as "visits",
|
||||||
count(distinct session.country) as "countries",
|
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
|
from website_event
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
join session on website_event.session_id = session.session_id
|
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))) {
|
if (EVENT_COLUMNS.some(item => Object.keys(filters).includes(item))) {
|
||||||
sql = `
|
sql = `
|
||||||
select
|
select
|
||||||
sumIf(1, event_type = 1) as "pageviews",
|
sumIf(1, event_type = ${EVENT_TYPE.pageView}) as "pageviews",
|
||||||
uniq(session_id) as "visitors",
|
uniq(session_id) as "visitors",
|
||||||
uniq(visit_id) as "visits",
|
uniq(visit_id) as "visits",
|
||||||
uniq(country) as "countries",
|
uniq(country) as "countries",
|
||||||
sumIf(1, event_type = 2) as "events"
|
sumIf(1, event_type = ${EVENT_TYPE.customEvent}) as "events"
|
||||||
from website_event
|
from website_event
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
|||||||
min(website_event.created_at) as "firstAt",
|
min(website_event.created_at) as "firstAt",
|
||||||
max(website_event.created_at) as "lastAt",
|
max(website_event.created_at) as "lastAt",
|
||||||
count(distinct website_event.visit_id) as "visits",
|
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 = ${EVENT_TYPE.pageView} 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.customEvent} then 1 else 0 end) as "events",
|
||||||
max(website_event.created_at) as "createdAt"
|
max(website_event.created_at) as "createdAt"
|
||||||
from website_event
|
from website_event
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
@@ -125,8 +125,8 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
|
|||||||
${getDateStringSQL('min(created_at)')} as firstAt,
|
${getDateStringSQL('min(created_at)')} as firstAt,
|
||||||
${getDateStringSQL('max(created_at)')} as lastAt,
|
${getDateStringSQL('max(created_at)')} as lastAt,
|
||||||
uniq(visit_id) as visits,
|
uniq(visit_id) as visits,
|
||||||
sumIf(1, event_type = 1) as views,
|
sumIf(1, event_type = ${EVENT_TYPE.pageView}) as views,
|
||||||
sumIf(1, event_type = 2) as events,
|
sumIf(1, event_type = ${EVENT_TYPE.customEvent}) as events,
|
||||||
max(created_at) as createdAt
|
max(created_at) as createdAt
|
||||||
from website_event
|
from website_event
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
@@ -155,7 +155,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
|
|||||||
${getDateStringSQL('min(min_time)')} as firstAt,
|
${getDateStringSQL('min(min_time)')} as firstAt,
|
||||||
${getDateStringSQL('max(max_time)')} as lastAt,
|
${getDateStringSQL('max(max_time)')} as lastAt,
|
||||||
uniq(visit_id) as visits,
|
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,
|
sum(length(event_name)) as events,
|
||||||
max(max_time) as createdAt
|
max(max_time) as createdAt
|
||||||
from website_event_stats_hourly as website_event
|
from website_event_stats_hourly as website_event
|
||||||
|
|||||||
Reference in new issue
Block a user