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
performance page polish
Francis Cao383922ab1794
diff --git a/public/intl/messages/en-US.json b/public/intl/messages/en-US.jsonindex 25a94f3b4..969f9537c 100644--- a/public/intl/messages/en-US.json+++ b/public/intl/messages/en-US.json@@ -288,6 +288,7 @@"share": "Share","share-url": "Share URL","single-day": "Single day",+ "slug": "Slug","sms": "SMS","source": "Source","sources": "Sources",diff --git a/src/app/(main)/links/LinkEditForm.tsx b/src/app/(main)/links/LinkEditForm.tsxindex 64bfb8dbc..50f3bdb60 100644--- a/src/app/(main)/links/LinkEditForm.tsx+++ b/src/app/(main)/links/LinkEditForm.tsx@@ -94,7 +94,7 @@ export function LinkEditForm({<Grid columns="1fr auto" alignItems="end" gap><FormFieldname="slug"- label={t({ id: 'label.slug', defaultMessage: 'Slug' })}+ label={t(labels.slug)}rules={{required: t(labels.required),}}diff --git a/src/app/(main)/websites/[websiteId]/(reports)/performance/Performance.tsx b/src/app/(main)/websites/[websiteId]/(reports)/performance/Performance.tsxindex f35090e48..ff7bbb516 100644--- a/src/app/(main)/websites/[websiteId]/(reports)/performance/Performance.tsx+++ b/src/app/(main)/websites/[websiteId]/(reports)/performance/Performance.tsx@@ -18,9 +18,9 @@ import { BarChart } from '@/components/charts/BarChart';import { GridRow } from '@/components/common/GridRow';import { LoadingPanel } from '@/components/common/LoadingPanel';import { Panel } from '@/components/common/Panel';-import { TypeIcon } from '@/components/common/TypeIcon';import { useLocale, useMessages, useResultQuery } from '@/components/hooks';import { ListTable } from '@/components/metrics/ListTable';+import { MetricLabel } from '@/components/metrics/MetricLabel';import { PerformanceCard } from '@/components/metrics/PerformanceCard';import { renderDateLabels } from '@/lib/charts';import { CHART_COLORS, WEB_VITALS_THRESHOLDS } from '@/lib/constants';@@ -46,9 +46,8 @@ const METRIC_LABELS: Record<string, string> = {};function formatMetricValue(metric: string, value: number): string {- if (metric === 'cls') {- return value.toFixed(3);- }+ if (metric === 'cls') return value.toFixed(3);+ if (value >= 1000) return `${(value / 1000).toFixed(2)} s`;return `${Math.round(value)} ms`;}@@ -138,6 +137,11 @@ export function Performance({ websiteId, startDate, endDate, unit }: Performanceconst renderXLabel = useCallback(renderDateLabels(unit, locale), [unit, locale]);const threshold = WEB_VITALS_THRESHOLDS[selectedMetric as keyof typeof WEB_VITALS_THRESHOLDS];+ const isCls = selectedMetric === 'cls';+ const metricLabel = t(labels[selectedMetric]) || selectedMetric.toUpperCase();+ const formatListCount = isCls+ ? (n: number) => n.toFixed(3)+ : (n: number) => `${(n / 1000).toFixed(2)} s`;return (<Column gap>@@ -189,6 +193,7 @@ export function Performance({ websiteId, startDate, endDate, unit }: PerformancerenderYLabel={(label: string) => {const val = Number(label);if (selectedMetric === 'cls') return val.toFixed(2);+ if (val >= 1000) return `${(val / 1000).toFixed(2)} s`;return `${Math.round(val)} ms`;}}height="400px"@@ -205,26 +210,40 @@ export function Performance({ websiteId, startDate, endDate, unit }: Performance</TabList><TabPanel id="path"><ListTable- metric={t(labels[selectedMetric]) || selectedMetric.toUpperCase()}+ metric={metricLabel}showPercentage={false}- data={data.pages?.map(({ name, p50, p75, p95 }: any) => ({- label: name,- count: Number({ p50, p75, p95 }[selectedPercentile]),- percent: 0,- }))}+ formatCount={formatListCount}+ data={data.pages+ ?.filter(+ ({ p50, p75, p95 }: any) =>+ Number({ p50, p75, p95 }[selectedPercentile]) > 0,+ )+ .slice(0, 20)+ .map(({ name, p50, p75, p95 }: any) => ({+ label: name,+ count: Number({ p50, p75, p95 }[selectedPercentile]),+ percent: 0,+ }))}renderLabel={({ label }: { label: string }) => <Text>{label}</Text>}/></TabPanel><TabPanel id="title"><ListTable- metric={t(labels[selectedMetric]) || selectedMetric.toUpperCase()}+ metric={metricLabel}showPercentage={false}- data={data.pageTitles?.map(({ name, p50, p75, p95 }: any) => ({- label: name,- count: Number({ p50, p75, p95 }[selectedPercentile]),- percent: 0,- }))}- renderLabel={({ label }: { label: string }) => <Text>{label}</Text>}+ formatCount={formatListCount}+ data={data.pageTitles+ ?.filter(+ ({ p50, p75, p95 }: any) =>+ Number({ p50, p75, p95 }[selectedPercentile]) > 0,+ )+ .slice(0, 20)+ .map(({ name, p50, p75, p95 }: any) => ({+ label: name,+ count: Number({ p50, p75, p95 }[selectedPercentile]),+ percent: 0,+ }))}+ renderLabel={(row: any) => <MetricLabel type="title" data={row} />}/></TabPanel></Tabs>@@ -238,36 +257,40 @@ export function Performance({ websiteId, startDate, endDate, unit }: Performance</TabList><TabPanel id="device"><ListTable- metric={t(labels[selectedMetric]) || selectedMetric.toUpperCase()}+ metric={metricLabel}showPercentage={false}- data={data.devices?.map(({ name, p50, p75, p95 }: any) => ({- label: name,- count: Number({ p50, p75, p95 }[selectedPercentile]),- percent: 0,- }))}- renderLabel={({ label }: { label: string }) => (- <Row gap="2" alignItems="center">- <TypeIcon type="device" value={label} />- <Text>{label}</Text>- </Row>- )}+ formatCount={formatListCount}+ data={data.devices+ ?.filter(+ ({ p50, p75, p95 }: any) =>+ Number({ p50, p75, p95 }[selectedPercentile]) > 0,+ )+ .slice(0, 20)+ .map(({ name, p50, p75, p95 }: any) => ({+ label: name,+ count: Number({ p50, p75, p95 }[selectedPercentile]),+ percent: 0,+ }))}+ renderLabel={(row: any) => <MetricLabel type="device" data={row} />}/></TabPanel><TabPanel id="browser"><ListTable- metric={t(labels[selectedMetric]) || selectedMetric.toUpperCase()}+ metric={metricLabel}showPercentage={false}- data={data.browsers?.map(({ name, p50, p75, p95 }: any) => ({- label: name,- count: Number({ p50, p75, p95 }[selectedPercentile]),- percent: 0,- }))}- renderLabel={({ label }: { label: string }) => (- <Row gap="2" alignItems="center">- <TypeIcon type="browser" value={label} />- <Text>{label}</Text>- </Row>- )}+ formatCount={formatListCount}+ data={data.browsers+ ?.filter(+ ({ p50, p75, p95 }: any) =>+ Number({ p50, p75, p95 }[selectedPercentile]) > 0,+ )+ .slice(0, 20)+ .map(({ name, p50, p75, p95 }: any) => ({+ label: name,+ count: Number({ p50, p75, p95 }[selectedPercentile]),+ percent: 0,+ }))}+ renderLabel={(row: any) => <MetricLabel type="browser" data={row} />}/></TabPanel></Tabs>diff --git a/src/components/input/FieldFilters.tsx b/src/components/input/FieldFilters.tsxindex 4856cd1d1..7107aeb2f 100644--- a/src/components/input/FieldFilters.tsx+++ b/src/components/input/FieldFilters.tsx@@ -95,6 +95,7 @@ export function FieldFilters({>{groupLabels.map(({ key: groupKey, label }) => {const groupFields = groupedFields[groupKey];+ if (!groupFields || groupFields.length === 0) return null;return (<MenuSection key={groupKey} title={label}>{groupFields.map(field => {diff --git a/src/components/input/FilterEditForm.tsx b/src/components/input/FilterEditForm.tsxindex 6b3353f53..5e7e6020f 100644--- a/src/components/input/FilterEditForm.tsx+++ b/src/components/input/FilterEditForm.tsx@@ -27,8 +27,28 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormPconst [currentCohort, setCurrentCohort] = useState(cohort);const [currentMatch, setCurrentMatch] = useState<string>(match || 'all');const { isMobile } = useMobile();- const excludeFilters = !websiteId || pathname.includes('/pixels') || pathname.includes('/links');+ const isPixelLink = !websiteId || pathname.includes('/pixels') || pathname.includes('/links');const excludeEvent = !pathname.endsWith('/events') && !pathname.endsWith('/replays');+ const isPerformance = pathname.includes('/performance');++ const excludedFields = isPixelLink+ ? ['path', 'title', 'hostname', 'distinctId', 'tag', 'event']+ : isPerformance+ ? [+ 'referrer',+ 'query',+ 'event',+ 'tag',+ 'distinctId',+ 'utmSource',+ 'utmMedium',+ 'utmCampaign',+ 'utmContent',+ 'utmTerm',+ ]+ : excludeEvent+ ? ['event']+ : [];const handleReset = () => {setCurrentFilters([]);@@ -58,7 +78,7 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP<Tabs><TabList><Tab id="fields">{t(labels.fields)}</Tab>- {!excludeFilters && (+ {!isPixelLink && (<><Tab id="segments">{t(labels.segments)}</Tab><Tab id="cohorts">{t(labels.cohorts)}</Tab>@@ -72,13 +92,7 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormPmatch={currentMatch}onChange={setCurrentFilters}onMatchChange={setCurrentMatch}- exclude={- excludeFilters- ? ['path', 'title', 'hostname', 'distinctId', 'tag', 'event']- : excludeEvent- ? ['event']- : []- }+ exclude={excludedFields}/></TabPanel><TabPanel id="segments">diff --git a/src/components/messages.ts b/src/components/messages.tsindex 6bd5b3fc1..11899a5c3 100644--- a/src/components/messages.ts+++ b/src/components/messages.ts@@ -339,6 +339,7 @@ export const labels: Record<string, string> = {saveCohort: 'label.save-cohort',analysis: 'label.analysis',destinationUrl: 'label.destination-url',+ slug: 'label.slug',audience: 'label.audience',invalidUrl: 'label.invalid-url',environment: 'label.environment',diff --git a/src/components/metrics/ListTable.tsx b/src/components/metrics/ListTable.tsxindex 9c2fb2360..75080de95 100644--- a/src/components/metrics/ListTable.tsx+++ b/src/components/metrics/ListTable.tsx@@ -27,6 +27,7 @@ export interface ListTableProps {showPercentage?: boolean;itemCount?: number;currency?: string;+ formatCount?: (n: number) => string;}export function ListTable({@@ -40,6 +41,7 @@ export function ListTable({showPercentage = true,itemCount = 10,currency,+ formatCount,}: ListTableProps) {const { t, labels } = useMessages();const { isPhone } = useMobile();@@ -57,6 +59,7 @@ export function ListTable({showPercentage={showPercentage}change={renderChange ? renderChange(row, index) : null}currency={currency}+ formatCount={formatCount}isPhone={isPhone}/>);@@ -106,6 +109,7 @@ const AnimatedRow = ({animate,showPercentage = true,currency,+ formatCount,isPhone,}) => {const props = useSpring({@@ -135,7 +139,9 @@ const AnimatedRow = ({<AnimatedDiv title={props?.y as any}>{currency? props.y?.to(n => formatLongCurrency(n, currency))- : props.y?.to(formatLongNumber)}+ : formatCount+ ? props.y?.to(formatCount)+ : props.y?.to(formatLongNumber)}</AnimatedDiv></Text></Row>diff --git a/src/components/metrics/PerformanceCard.module.css b/src/components/metrics/PerformanceCard.module.cssindex c0de4ae2d..ae650d4ee 100644--- a/src/components/metrics/PerformanceCard.module.css+++ b/src/components/metrics/PerformanceCard.module.css@@ -3,7 +3,9 @@}.card:hover {- box-shadow: 0 0 0 1px color-mix(in srgb, var(--primary) 15%, transparent);+ box-shadow:+ 0 0 0 1px color-mix(in srgb, var(--primary) 40%, transparent),+ 0 0 6px color-mix(in srgb, var(--primary) 15%, transparent);}.card.selected {diff --git a/src/components/metrics/PerformanceCard.tsx b/src/components/metrics/PerformanceCard.tsxindex 96f909459..be745d47b 100644--- a/src/components/metrics/PerformanceCard.tsx+++ b/src/components/metrics/PerformanceCard.tsx@@ -1,4 +1,7 @@+import { config, useSpring } from '@react-spring/web';import { Column, Text } from '@umami/react-zen';+import { useRef } from 'react';+import { AnimatedDiv } from '@/components/common/AnimatedDiv';import { useMessages } from '@/components/hooks';import { WEB_VITALS_THRESHOLDS } from '@/lib/constants';import { formatNumber } from '@/lib/format';@@ -31,6 +34,14 @@ export const PerformanceCard = ({}: PerformanceCardProps) => {const { t, labels } = useMessages();const rating = getRating(metric, value);+ const prevMetricRef = useRef(metric);+ const metricChanged = prevMetricRef.current !== metric;+ if (metricChanged) prevMetricRef.current = metric;++ const spring = useSpring({+ value: !Number.isNaN(value) ? value : 0,+ config: metricChanged ? { duration: 0 } : config.default,+ });return (<Column@@ -49,7 +60,7 @@ export const PerformanceCard = ({{label}</Text><Text size="4xl" weight="bold" wrap="nowrap">- {formatValue(value)}+ <AnimatedDiv>{spring.value.to(n => formatValue(n))}</AnimatedDiv></Text><Text size="sm" className={styles.rating}>{t(labels[rating === 'needs-improvement' ? 'needsImprovement' : rating])}