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
update avg aggregate for revenue report
Francis Cao065499a3fa4d
diff --git a/src/app/(main)/console/TestConsole.tsx b/src/app/(main)/console/TestConsole.tsxindex d33f95e9d..544aaa9ae 100644--- a/src/app/(main)/console/TestConsole.tsx+++ b/src/app/(main)/console/TestConsole.tsx@@ -55,35 +55,35 @@ export function TestConsole({ websiteId }: { websiteId: string }) {referrer: 'https://www.google.com',}));window['umami'].track('checkout-cart', {- revenue: parseFloat((Math.random() * 100000).toFixed(2)),- currency: 'SHIBA',+ revenue: parseFloat((Math.random() * 1000).toFixed(2)),+ currency: 'USD',});window['umami'].track('affiliate-link', {- revenue: parseFloat((Math.random() * 100000).toFixed(2)),- currency: 'ETH',+ revenue: parseFloat((Math.random() * 1000).toFixed(2)),+ currency: 'USD',});window['umami'].track('promotion-link', {- revenue: parseFloat((Math.random() * 100000).toFixed(2)),+ revenue: parseFloat((Math.random() * 1000).toFixed(2)),currency: 'USD',});window['umami'].track('checkout-cart', {- revenue: parseFloat((Math.random() * 100000).toFixed(2)),+ revenue: parseFloat((Math.random() * 1000).toFixed(2)),currency: 'EUR',});window['umami'].track('promotion-link', {- revenue: parseFloat((Math.random() * 100000).toFixed(2)),+ revenue: parseFloat((Math.random() * 1000).toFixed(2)),currency: 'EUR',});window['umami'].track('affiliate-link', {item1: {productIdentity: 'ABC424',- revenue: parseFloat((Math.random() * 100000).toFixed(2)),- currency: 'MXN',+ revenue: parseFloat((Math.random() * 10000).toFixed(2)),+ currency: 'JPY',},item2: {productIdentity: 'ZYW684',- revenue: parseFloat((Math.random() * 100000).toFixed(2)),- currency: 'MXN',+ revenue: parseFloat((Math.random() * 10000).toFixed(2)),+ currency: 'JPY',},});}diff --git a/src/app/(main)/reports/revenue/RevenueTable.tsx b/src/app/(main)/reports/revenue/RevenueTable.tsxindex bf7114e8f..0b9fcdc3d 100644--- a/src/app/(main)/reports/revenue/RevenueTable.tsx+++ b/src/app/(main)/reports/revenue/RevenueTable.tsx@@ -23,7 +23,7 @@ export function RevenueTable() {{row => formatLongCurrency(row.sum, row.currency)}</GridColumn><GridColumn name="currency" label={formatMessage(labels.average)} alignment="end">- {row => formatLongCurrency(row.avg, row.currency)}+ {row => formatLongCurrency(row.count ? row.sum / row.count : 0, row.currency)}</GridColumn><GridColumn name="currency" label={formatMessage(labels.transactions)} alignment="end">{row => row.count}diff --git a/src/app/(main)/reports/revenue/RevenueView.tsx b/src/app/(main)/reports/revenue/RevenueView.tsxindex cd53129a1..2d559893f 100644--- a/src/app/(main)/reports/revenue/RevenueView.tsx+++ b/src/app/(main)/reports/revenue/RevenueView.tsx@@ -87,7 +87,7 @@ export function RevenueView({ isLoading }: RevenueViewProps) {const metricData = useMemo(() => {if (!data) return [];- const { sum, avg, count, unique_count } = data.total;+ const { sum, count, unique_count } = data.total;return [{@@ -96,7 +96,7 @@ export function RevenueView({ isLoading }: RevenueViewProps) {formatValue: n => formatLongCurrency(n, currency),},{- value: avg,+ value: count ? sum / count : 0,label: formatMessage(labels.average),formatValue: n => formatLongCurrency(n, currency),},diff --git a/src/lib/format.ts b/src/lib/format.tsindex 71e4916d1..e497464a6 100644--- a/src/lib/format.ts+++ b/src/lib/format.ts@@ -114,5 +114,5 @@ export function formatLongCurrency(value: number, currency: string, locale = 'enreturn `${formatCurrency(n / 1000, currency, locale)}k`;}- return formatCurrency(n / 1000, currency, locale);+ return formatCurrency(n, currency, locale);}diff --git a/src/queries/analytics/reports/getRevenue.ts b/src/queries/analytics/reports/getRevenue.tsindex 5fb419c0e..caef94694 100644--- a/src/queries/analytics/reports/getRevenue.ts+++ b/src/queries/analytics/reports/getRevenue.ts@@ -32,11 +32,10 @@ async function relationalQuery(): Promise<{chart: { x: string; t: string; y: number }[];country: { name: string; value: number }[];- total: { sum: number; avg: number; count: number; unique_count: number };+ total: { sum: number; count: number; unique_count: number };table: {currency: string;sum: number;- avg: number;count: number;unique_count: number;}[];@@ -96,7 +95,6 @@ async function relationalQuery(`selectsum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as sum,- avg(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as avg,count(distinct event_id) as count,count(distinct session_id) as unique_countfrom event_data ed@@ -119,7 +117,6 @@ async function relationalQuery(selectc.currency,sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as sum,- avg(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as avg,count(distinct ed.website_event_id) as count,count(distinct we.session_id) as unique_countfrom event_data ed@@ -153,11 +150,10 @@ async function clickhouseQuery(): Promise<{chart: { x: string; t: string; y: number }[];country: { name: string; value: number }[];- total: { sum: number; avg: number; count: number; unique_count: number };+ total: { sum: number; count: number; unique_count: number };table: {currency: string;sum: number;- avg: number;count: number;unique_count: number;}[];@@ -230,7 +226,6 @@ async function clickhouseQuery(`selectsum(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) as sum,- avg(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) as avg,uniqExact(event_id) as count,uniqExact(session_id) as unique_countfrom event_data@@ -259,7 +254,6 @@ async function clickhouseQuery(selectc.currency,sum(coalesce(toDecimal64(ed.number_value, 2), toDecimal64(ed.string_value, 2))) as sum,- avg(coalesce(toDecimal64(ed.number_value, 2), toDecimal64(ed.string_value, 2))) as avg,uniqExact(ed.event_id) as count,uniqExact(ed.session_id) as unique_countfrom event_data ed