change pagestable to visitors and update clickhouse hostname column to array

This commit is contained in:
Francis Cao 2025-07-13 22:44:09 -07:00
parent 195619aeed
commit 2dcb9e21bd
8 changed files with 296 additions and 29 deletions

View file

@ -34,7 +34,7 @@ async function relationalQuery(
...filters,
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
},
{ joinSession: SESSION_COLUMNS.includes(type) || column === 'referrer_domain' },
{ joinSession: SESSION_COLUMNS.includes(type) },
);
let entryExitQuery = '';
@ -66,7 +66,7 @@ async function relationalQuery(
return rawQuery(
`
select ${column} x,
${column === 'referrer_domain' ? 'count(distinct website_event.session_id)' : 'count(*)'} as y
count(distinct website_event.session_id) as y
from website_event
${cohortQuery}
${joinSession}
@ -126,7 +126,7 @@ async function clickhouseQuery(
sql = `
select ${column} x,
${column === 'referrer_domain' ? 'uniq(session_id)' : 'count(*)'} as y
uniq(website_event.session_id) as y
from website_event
${cohortQuery}
${entryExitQuery}
@ -142,28 +142,27 @@ async function clickhouseQuery(
`;
} else {
let groupByQuery = '';
let columnQuery = `arrayJoin(${column})`;
let columnQuery = `session_id s, arrayJoin(${column})`;
if (column === 'referrer_domain') {
excludeDomain = `and t != hostname and t != ''`;
columnQuery = `session_id s, arrayJoin(${column})`;
excludeDomain = `and t != ''`;
}
if (type === 'entry') {
columnQuery = `visit_id x, argMinMerge(entry_url)`;
columnQuery = `session_id s, argMinMerge(entry_url)`;
}
if (type === 'exit') {
columnQuery = `visit_id x, argMaxMerge(exit_url)`;
columnQuery = `session_id s, argMaxMerge(exit_url)`;
}
if (type === 'entry' || type === 'exit') {
groupByQuery = 'group by x';
groupByQuery = 'group by s';
}
sql = `
select g.t as x,
${column === 'referrer_domain' ? 'uniq(s)' : 'count(*)'} as y
uniq(s) as y
from (
select ${columnQuery} as t
from website_event_stats_hourly website_event