Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Fix revenue bigInt but and case insensitive currency
Francis Caobf548c5acae5
diff --git a/src/queries/sql/reports/getRevenue.ts b/src/queries/sql/reports/getRevenue.tsindex e13106ced..5771bdef0 100644--- a/src/queries/sql/reports/getRevenue.ts+++ b/src/queries/sql/reports/getRevenue.ts@@ -41,6 +41,15 @@ async function relationalQuery(currency,});+ const joinQuery = filterQuery+ ? `join website_event+ on website_event.website_id = revenue.website_id+ and website_event.session_id = revenue.session_id+ and website_event.event_id = revenue.event_id+ and website_event.website_id = {{websiteId::uuid}}+ and website_event.created_at between {{startDate}} and {{endDate}}`+ : '';+const chart = await rawQuery(`select@@ -48,17 +57,12 @@ async function relationalQuery(${getDateSQL('revenue.created_at', unit, timezone)} t,sum(revenue.revenue) yfrom revenue- join website_event- on website_event.website_id = revenue.website_id- and website_event.session_id = revenue.session_id- and website_event.event_id = revenue.event_id- and website_event.website_id = {{websiteId::uuid}}- and website_event.created_at between {{startDate}} and {{endDate}}+ ${joinQuery}${cohortQuery}${joinSessionQuery}where revenue.website_id = {{websiteId::uuid}}and revenue.created_at between {{startDate}} and {{endDate}}- and revenue.currency like {{currency}}+ and revenue.currency ilike {{currency}}${filterQuery}group by x, torder by t@@ -72,19 +76,14 @@ async function relationalQuery(session.country as name,sum(revenue) valuefrom revenue- join website_event- on website_event.website_id = revenue.website_id- and website_event.session_id = revenue.session_id- and website_event.event_id = revenue.event_id- and website_event.website_id = {{websiteId::uuid}}- and website_event.created_at between {{startDate}} and {{endDate}}+ ${joinQuery}join sessionon session.website_id = revenue.website_idand session.session_id = revenue.session_id${cohortQuery}where revenue.website_id = {{websiteId::uuid}}and revenue.created_at between {{startDate}} and {{endDate}}- and revenue.currency = {{currency}}+ and revenue.currency ilike {{currency}}${filterQuery}group by session.country`,@@ -98,23 +97,18 @@ async function relationalQuery(count(distinct revenue.event_id) as count,count(distinct revenue.session_id) as unique_countfrom revenue- join website_event- on website_event.website_id = revenue.website_id- and website_event.session_id = revenue.session_id- and website_event.event_id = revenue.event_id- and website_event.website_id = {{websiteId::uuid}}- and website_event.created_at between {{startDate}} and {{endDate}}+ ${joinQuery}${cohortQuery}${joinSessionQuery}where revenue.website_id = {{websiteId::uuid}}and revenue.created_at between {{startDate}} and {{endDate}}- and revenue.currency = {{currency}}+ and revenue.currency ilike {{currency}}${filterQuery}`,queryParams,).then(result => result?.[0]);- total.average = total.count > 0 ? total.sum / total.count : 0;+ total.average = total.count > 0 ? Number(total.sum) / Number(total.count) : 0;return { chart, country, total };}