mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
revenue, events, and session activity optimization
This commit is contained in:
parent
533a42eb2e
commit
2e1a5b444a
3 changed files with 27 additions and 21 deletions
|
|
@ -96,7 +96,10 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
|
||||||
page_title as pageTitle,
|
page_title as pageTitle,
|
||||||
event_type as eventType,
|
event_type as eventType,
|
||||||
event_name as eventName,
|
event_name as eventName,
|
||||||
event_id IN (SELECT event_id FROM event_data where website_id = {websiteId:UUID}) as hasData
|
event_id IN (select event_id
|
||||||
|
from event_data
|
||||||
|
where website_id = {websiteId:UUID}
|
||||||
|
${dateQuery}) as hasData
|
||||||
from website_event
|
from website_event
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,15 @@ async function clickhouseQuery(
|
||||||
currency,
|
currency,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const joinQuery = filterQuery
|
||||||
|
? `join website_event
|
||||||
|
on website_event.website_id = website_revenue.website_id
|
||||||
|
and website_event.session_id = website_revenue.session_id
|
||||||
|
and website_event.event_id = website_revenue.event_id
|
||||||
|
and website_event.website_id = {websiteId:UUID}
|
||||||
|
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}`
|
||||||
|
: '';
|
||||||
|
|
||||||
const chart = await rawQuery<
|
const chart = await rawQuery<
|
||||||
{
|
{
|
||||||
x: string;
|
x: string;
|
||||||
|
|
@ -147,12 +156,7 @@ async function clickhouseQuery(
|
||||||
${getDateSQL('website_revenue.created_at', unit, timezone)} t,
|
${getDateSQL('website_revenue.created_at', unit, timezone)} t,
|
||||||
sum(website_revenue.revenue) y
|
sum(website_revenue.revenue) y
|
||||||
from website_revenue
|
from website_revenue
|
||||||
join website_event
|
${joinQuery}
|
||||||
on website_event.website_id = website_revenue.website_id
|
|
||||||
and website_event.session_id = website_revenue.session_id
|
|
||||||
and website_event.event_id = website_revenue.event_id
|
|
||||||
and website_event.website_id = {websiteId:UUID}
|
|
||||||
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_revenue.website_id = {websiteId:UUID}
|
where website_revenue.website_id = {websiteId:UUID}
|
||||||
and website_revenue.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and website_revenue.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
|
@ -175,13 +179,13 @@ async function clickhouseQuery(
|
||||||
website_event.country as name,
|
website_event.country as name,
|
||||||
sum(website_revenue.revenue) as value
|
sum(website_revenue.revenue) as value
|
||||||
from website_revenue
|
from website_revenue
|
||||||
join website_event
|
join website_event
|
||||||
on website_event.website_id = website_revenue.website_id
|
on website_event.website_id = website_revenue.website_id
|
||||||
and website_event.session_id = website_revenue.session_id
|
and website_event.session_id = website_revenue.session_id
|
||||||
and website_event.event_id = website_revenue.event_id
|
and website_event.event_id = website_revenue.event_id
|
||||||
and website_event.website_id = {websiteId:UUID}
|
and website_event.website_id = {websiteId:UUID}
|
||||||
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_revenue.website_id = {websiteId:UUID}
|
where website_revenue.website_id = {websiteId:UUID}
|
||||||
and website_revenue.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and website_revenue.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
and website_revenue.currency = {currency:String}
|
and website_revenue.currency = {currency:String}
|
||||||
|
|
@ -203,12 +207,7 @@ async function clickhouseQuery(
|
||||||
uniqExact(website_revenue.event_id) as count,
|
uniqExact(website_revenue.event_id) as count,
|
||||||
uniqExact(website_revenue.session_id) as unique_count
|
uniqExact(website_revenue.session_id) as unique_count
|
||||||
from website_revenue
|
from website_revenue
|
||||||
join website_event
|
${joinQuery}
|
||||||
on website_event.website_id = website_revenue.website_id
|
|
||||||
and website_event.session_id = website_revenue.session_id
|
|
||||||
and website_event.event_id = website_revenue.event_id
|
|
||||||
and website_event.website_id = {websiteId:UUID}
|
|
||||||
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_revenue.website_id = {websiteId:UUID}
|
where website_revenue.website_id = {websiteId:UUID}
|
||||||
and website_revenue.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and website_revenue.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,16 @@ async function clickhouseQuery(websiteId: string, sessionId: string, filters: Qu
|
||||||
event_type as eventType,
|
event_type as eventType,
|
||||||
event_name as eventName,
|
event_name as eventName,
|
||||||
visit_id as visitId,
|
visit_id as visitId,
|
||||||
event_id IN (SELECT event_id FROM event_data where website_id = {websiteId:UUID} and session_id = {sessionId:UUID}) AS hasData
|
event_id IN (select event_id
|
||||||
from website_event e
|
from event_data
|
||||||
where e.website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and e.session_id = {sessionId:UUID}
|
and session_id = {sessionId:UUID}
|
||||||
and e.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}) AS hasData
|
||||||
order by e.created_at desc
|
from website_event
|
||||||
|
where website_id = {websiteId:UUID}
|
||||||
|
and session_id = {sessionId:UUID}
|
||||||
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
order by created_at desc
|
||||||
limit 500
|
limit 500
|
||||||
`,
|
`,
|
||||||
{ websiteId, sessionId, startDate, endDate },
|
{ websiteId, sessionId, startDate, endDate },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue