2022-08-08 10:26:20 +02:00
|
|
|
import { parseFilters, rawQuery, runAnalyticsQuery } from 'lib/db';
|
|
|
|
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
2022-07-21 23:57:29 +02:00
|
|
|
|
2022-07-23 04:50:43 +02:00
|
|
|
export async function getPageviewParams(...args) {
|
|
|
|
return runAnalyticsQuery({
|
2022-07-25 18:47:11 +02:00
|
|
|
[RELATIONAL]: () => relationalQuery(...args),
|
|
|
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
2022-07-23 04:50:43 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-08 10:26:20 +02:00
|
|
|
async function relationalQuery(website_id, start_at, end_at, column, table, filters = {}) {
|
|
|
|
const params = [website_id, start_at, end_at];
|
2022-07-21 23:57:29 +02:00
|
|
|
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
|
|
|
|
table,
|
|
|
|
column,
|
|
|
|
filters,
|
|
|
|
params,
|
|
|
|
);
|
|
|
|
|
|
|
|
return rawQuery(
|
2022-08-08 10:26:20 +02:00
|
|
|
`
|
|
|
|
select url x,
|
|
|
|
count(*) y
|
|
|
|
from ${table}
|
|
|
|
${joinSession}
|
|
|
|
where ${table}.website_id=$1
|
|
|
|
and ${table}.created_at between $2 and $3
|
|
|
|
and ${table}.url like '%?%'
|
|
|
|
${pageviewQuery}
|
|
|
|
${joinSession && sessionQuery}
|
|
|
|
${eventQuery}
|
|
|
|
group by 1
|
|
|
|
order by 2 desc
|
|
|
|
`,
|
2022-07-21 23:57:29 +02:00
|
|
|
params,
|
|
|
|
);
|
|
|
|
}
|
2022-07-23 04:50:43 +02:00
|
|
|
|
|
|
|
function clickhouseQuery() {
|
|
|
|
return Promise.reject(new Error('Not implemented.'));
|
|
|
|
}
|