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
feat: Add default currency support and update currency handling in Revenue component
Yash4eddac21c754
diff --git a/next.config.ts b/next.config.tsindex 99dcca0d8..1a4e2e0ec 100644--- a/next.config.ts+++ b/next.config.ts@@ -8,6 +8,7 @@ const cloudMode = process.env.CLOUD_MODE || '';const cloudUrl = process.env.CLOUD_URL || '';const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT || '';const corsMaxAge = process.env.CORS_MAX_AGE || '';+const defaultCurrency = process.env.DEFAULT_CURRENCY || '';const defaultLocale = process.env.DEFAULT_LOCALE || '';const forceSSL = process.env.FORCE_SSL || '';const frameAncestors = process.env.ALLOWED_FRAME_URLS || '';@@ -170,6 +171,7 @@ export default {cloudMode,cloudUrl,currentVersion: pkg.version,+ defaultCurrency,defaultLocale,},basePath,diff --git a/src/app/(main)/websites/[websiteId]/(reports)/revenue/Revenue.tsx b/src/app/(main)/websites/[websiteId]/(reports)/revenue/Revenue.tsxindex 0e782a164..faee8b9a4 100644--- a/src/app/(main)/websites/[websiteId]/(reports)/revenue/Revenue.tsx+++ b/src/app/(main)/websites/[websiteId]/(reports)/revenue/Revenue.tsx@@ -12,9 +12,10 @@ import { ListTable } from '@/components/metrics/ListTable';import { MetricCard } from '@/components/metrics/MetricCard';import { MetricsBar } from '@/components/metrics/MetricsBar';import { renderDateLabels } from '@/lib/charts';-import { CHART_COLORS } from '@/lib/constants';+import { CHART_COLORS, CURRENCY_CONFIG, DEFAULT_CURRENCY } from '@/lib/constants';import { generateTimeSeries } from '@/lib/date';import { formatLongCurrency, formatLongNumber } from '@/lib/format';+import { getItem, setItem } from '@/lib/storage';export interface RevenueProps {websiteId: string;@@ -24,7 +25,15 @@ export interface RevenueProps {}export function Revenue({ websiteId, startDate, endDate, unit }: RevenueProps) {- const [currency, setCurrency] = useState('USD');+ const [currency, setCurrency] = useState(+ getItem(CURRENCY_CONFIG) || process.env.defaultCurrency || DEFAULT_CURRENCY,+ );++ const handleCurrencyChange = (value: string) => {+ setCurrency(value);+ setItem(CURRENCY_CONFIG, value);+ };+const { formatMessage, labels } = useMessages();const { locale, dateLocale } = useLocale();const { countryNames } = useCountryNames(locale);@@ -107,7 +116,7 @@ export function Revenue({ websiteId, startDate, endDate, unit }: RevenueProps) {return (<Column gap><Grid columns="280px" gap>- <CurrencySelect value={currency} onChange={setCurrency} />+ <CurrencySelect value={currency} onChange={handleCurrencyChange} /></Grid><LoadingPanel data={data} isLoading={isLoading} error={error}>{data && (diff --git a/src/lib/constants.ts b/src/lib/constants.tsindex e5090c3c0..502a3df6f 100644--- a/src/lib/constants.ts+++ b/src/lib/constants.ts@@ -4,6 +4,7 @@ export const LOCALE_CONFIG = 'umami.locale';export const TIMEZONE_CONFIG = 'umami.timezone';export const DATE_RANGE_CONFIG = 'umami.date-range';export const THEME_CONFIG = 'umami.theme';+export const CURRENCY_CONFIG = 'umami.currency';export const DASHBOARD_CONFIG = 'umami.dashboard';export const LAST_TEAM_CONFIG = 'umami.last-team';export const VERSION_CHECK = 'umami.version-check';@@ -25,6 +26,7 @@ export const DEFAULT_WEBSITE_LIMIT = 10;export const DEFAULT_RESET_DATE = '2000-01-01';export const DEFAULT_PAGE_SIZE = 20;export const DEFAULT_DATE_COMPARE = 'prev';+export const DEFAULT_CURRENCY = 'USD';export const REALTIME_RANGE = 30;export const REALTIME_INTERVAL = 10000;diff --git a/src/lib/format.ts b/src/lib/format.tsindex 52fd3048d..035a18111 100644--- a/src/lib/format.ts+++ b/src/lib/format.ts@@ -1,3 +1,5 @@+import { DEFAULT_CURRENCY } from './constants';+export function parseTime(val: number) {const days = ~~(val / 86400);const hours = ~~(val / 3600) - days * 24;@@ -94,7 +96,7 @@ export function formatCurrency(value: number, currency: string, locale = 'en-US'// Fallback to default currency format if an error occursformattedValue = new Intl.NumberFormat(locale, {style: 'currency',- currency: 'USD',+ currency: DEFAULT_CURRENCY,});}