Skip to content

armgit / umami

Public Imported from GitHub
0

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.

add timezone to revenue chartData. Fix min/max date for 7day value

Francis Cao89d3cd4f5abd
diff --git a/src/app/(main)/websites/[websiteId]/(reports)/revenue/Revenue.tsx b/src/app/(main)/websites/[websiteId]/(reports)/revenue/Revenue.tsx
index 4c870810e..c56eca68d 100644
--- a/src/app/(main)/websites/[websiteId]/(reports)/revenue/Revenue.tsx
+++ b/src/app/(main)/websites/[websiteId]/(reports)/revenue/Revenue.tsx
@@ -18,20 +18,20 @@ import { useCallback, useMemo, useState } from 'react';
export interface RevenueProps {
websiteId: string;
- minDate: Date;
- maxDate: Date;
+ startDate: Date;
+ endDate: Date;
unit: string;
}
-export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
+export function Revenue({ websiteId, startDate, endDate, unit }: RevenueProps) {
const [currency, setCurrency] = useState('USD');
const { formatMessage, labels } = useMessages();
const { locale, dateLocale } = useLocale();
const { countryNames } = useCountryNames(locale);
const { data, error, isLoading } = useResultQuery<any>('revenue', {
websiteId,
- minDate,
- maxDate,
+ startDate,
+ endDate,
currency,
});
@@ -63,7 +63,7 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
const color = colord(CHART_COLORS[index % CHART_COLORS.length]);
return {
label: key,
- data: generateTimeSeries(map[key], minDate, maxDate, unit, dateLocale),
+ data: generateTimeSeries(map[key], startDate, endDate, unit, dateLocale),
lineTension: 0,
backgroundColor: color.alpha(0.6).toRgbString(),
borderColor: color.alpha(0.7).toRgbString(),
@@ -71,7 +71,7 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
};
}),
};
- }, [data, minDate, maxDate, unit]);
+ }, [data, startDate, endDate, unit]);
const metrics = useMemo(() => {
if (!data) return [];
@@ -122,8 +122,8 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
<Panel>
<BarChart
chartData={chartData}
- minDate={minDate}
- maxDate={maxDate}
+ minDate={startDate}
+ maxDate={endDate}
unit={unit}
stacked={true}
currency={currency}
diff --git a/src/app/(main)/websites/[websiteId]/(reports)/revenue/RevenuePage.tsx b/src/app/(main)/websites/[websiteId]/(reports)/revenue/RevenuePage.tsx
index 0b46a2da9..0d74c38e9 100644
--- a/src/app/(main)/websites/[websiteId]/(reports)/revenue/RevenuePage.tsx
+++ b/src/app/(main)/websites/[websiteId]/(reports)/revenue/RevenuePage.tsx
@@ -12,7 +12,7 @@ export function RevenuePage({ websiteId }: { websiteId: string }) {
return (
<Column gap>
<WebsiteControls websiteId={websiteId} />
- <Revenue websiteId={websiteId} minDate={startDate} maxDate={endDate} unit={unit} />
+ <Revenue websiteId={websiteId} startDate={startDate} endDate={endDate} unit={unit} />
</Column>
);
}
diff --git a/src/lib/date.ts b/src/lib/date.ts
index 6a967477e..029318340 100644
--- a/src/lib/date.ts
+++ b/src/lib/date.ts
@@ -157,7 +157,12 @@ export function parseDateRange(value: string, locale = 'en-US'): DateRange {
const now = new Date();
const dateLocale = getDateLocale(locale);
- const { num = 1, unit } = parseDateValue(value);
+ const { unit } = parseDateValue(value);
+ let { num = 1 } = parseDateValue(value);
+
+ if (value === '7day') {
+ num--;
+ }
switch (unit) {
case 'hour':
diff --git a/src/queries/sql/reports/getRevenue.ts b/src/queries/sql/reports/getRevenue.ts
index 1ec4a1306..890717d96 100644
--- a/src/queries/sql/reports/getRevenue.ts
+++ b/src/queries/sql/reports/getRevenue.ts
@@ -7,6 +7,7 @@ export interface RevenuParameters {
startDate: Date;
endDate: Date;
unit: string;
+ timezone: string;
currency: string;
}
@@ -30,7 +31,7 @@ async function relationalQuery(
parameters: RevenuParameters,
filters: QueryFilters,
): Promise<RevenueResult> {
- const { startDate, endDate, currency, unit = 'day' } = parameters;
+ const { startDate, endDate, unit = 'day', timezone = 'utc', currency } = parameters;
const { getDateSQL, rawQuery, parseFilters } = prisma;
const { queryParams, filterQuery, cohortQuery, joinSessionQuery } = parseFilters({
...filters,
@@ -44,7 +45,7 @@ async function relationalQuery(
`
select
revenue.event_name x,
- ${getDateSQL('revenue.created_at', unit)} t,
+ ${getDateSQL('revenue.created_at', unit, timezone)} t,
sum(revenue.revenue) y
from revenue
join website_event
@@ -123,7 +124,7 @@ async function clickhouseQuery(
parameters: RevenuParameters,
filters: QueryFilters,
): Promise<RevenueResult> {
- const { startDate, endDate, unit = 'day', currency } = parameters;
+ const { startDate, endDate, unit = 'day', timezone = 'utc', currency } = parameters;
const { getDateSQL, rawQuery, parseFilters } = clickhouse;
const { filterQuery, cohortQuery, queryParams } = parseFilters({
...filters,
@@ -143,7 +144,7 @@ async function clickhouseQuery(
`
select
website_revenue.event_name x,
- ${getDateSQL('website_revenue.created_at', unit)} t,
+ ${getDateSQL('website_revenue.created_at', unit, timezone)} t,
sum(website_revenue.revenue) y
from website_revenue
join website_event