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
@@ -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(
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user