Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Improve dashboard panel empty states

Blue Mouse23f10ea9e72d
diff --git a/web/app/lib/constants/index.ts b/web/app/lib/constants/index.ts
index 30983171a..282c8854e 100644
--- a/web/app/lib/constants/index.ts
+++ b/web/app/lib/constants/index.ts
@@ -537,7 +537,7 @@ export const localisePath = (pathname: string, lang: string): string => {
// Increase this counter every time some major change is done within localisation files
// This will prevent cached version or raw locale strings being displayed in production
-export const I18N_CACHE_BREAKER = 39
+export const I18N_CACHE_BREAKER = 40
export const roles: Role[] = ['admin', 'viewer']
diff --git a/web/app/pages/Project/View/Panels.tsx b/web/app/pages/Project/View/Panels.tsx
index 2a0fa0e06..e2118e684 100644
--- a/web/app/pages/Project/View/Panels.tsx
+++ b/web/app/pages/Project/View/Panels.tsx
@@ -23,6 +23,10 @@ import {
CaretDownIcon,
CaretRightIcon,
StackIcon,
+ CursorClickIcon,
+ MegaphoneIcon,
+ TagIcon,
+ ArrowUpRightIcon,
ArrowLineRightIcon,
ArrowLineLeftIcon,
MagnifyingGlassIcon,
@@ -72,6 +76,16 @@ import {
const ENTRIES_PER_PANEL = 8
const ENTRIES_PER_CUSTOM_EVENTS_PANEL = 7
const CUSTOM_EVENTS_TOP_LIMITS = [1, 3, 5, 10] as const
+const UTM_TRACKING_PANEL_IDS = new Set(['so', 'me', 'ca', 'te', 'co'])
+const PANEL_EMPTY_STATE_DOCS = {
+ customEvents: 'https://swetrix.com/docs/swetrix-js-reference#track',
+ customEventMetadata: 'https://swetrix.com/docs/swetrix-js-reference#track',
+ pageviewMetadata: 'https://swetrix.com/docs/swetrix-js-reference#pageview',
+ utmTracking:
+ 'https://swetrix.com/docs/traffic-sources#1-tag-every-campaign-with-utm-parameters',
+} as const
+
+type PanelDocsEmptyStateVariant = keyof typeof PANEL_EMPTY_STATE_DOCS
const getPercentage = (value: number, total: number, precision = 2) => {
if (!total) return 0
@@ -80,17 +94,80 @@ const getPercentage = (value: number, total: number, precision = 2) => {
return Number.isFinite(percentage) ? _round(percentage, precision) : 0
}
-const PanelEmptyState = ({ message }: { message: string }) => (
- <div className='flex flex-col items-center justify-center py-8 text-center'>
+const getDocsEmptyStateVariant = (
+ id: string,
+ activeTab: keyof typeof PROJECT_TABS,
+): PanelDocsEmptyStateVariant | null => {
+ if (activeTab === PROJECT_TABS.traffic && UTM_TRACKING_PANEL_IDS.has(id)) {
+ return 'utmTracking'
+ }
+
+ return null
+}
+
+interface PanelEmptyStateProps {
+ message?: React.ReactNode
+ children?: React.ReactNode
+ icon?: React.ReactNode
+}
+
+const PanelEmptyState = ({
+ message,
+ children,
+ icon = <StackIcon className='size-5 text-gray-400 dark:text-slate-500' />,
+}: PanelEmptyStateProps) => (
+ <div className='flex h-full flex-1 flex-col items-center justify-center px-4 py-8 text-center'>
<div className='mb-3 flex size-10 items-center justify-center rounded-lg bg-gray-100 dark:bg-slate-900'>
- <StackIcon className='size-5 text-gray-400 dark:text-slate-500' />
+ {icon}
</div>
- <Text as='p' size='sm' colour='secondary'>
- {message}
- </Text>
+ {children ?? (
+ <Text as='p' size='sm' colour='secondary'>
+ {message}
+ </Text>
+ )}
</div>
)
+const PanelDocsEmptyState = ({
+ variant,
+}: {
+ variant: PanelDocsEmptyStateVariant
+}) => {
+ const { t } = useTranslation('common')
+ const linkLabel = t(`project.emptyStates.${variant}.link`)
+ const icon =
+ variant === 'customEvents' ? (
+ <CursorClickIcon className='size-5 text-gray-400 dark:text-slate-500' />
+ ) : variant === 'utmTracking' ? (
+ <MegaphoneIcon className='size-5 text-gray-400 dark:text-slate-500' />
+ ) : (
+ <TagIcon className='size-5 text-gray-400 dark:text-slate-500' />
+ )
+
+ return (
+ <PanelEmptyState icon={icon}>
+ <div className='max-w-md'>
+ <Text as='p' size='sm' colour='secondary' className='leading-6'>
+ {t(`project.emptyStates.${variant}.title`)}
+ </Text>
+ <Text as='p' size='sm' colour='secondary' className='leading-6'>
+ {t(`project.emptyStates.${variant}.description`)}{' '}
+ <a
+ href={PANEL_EMPTY_STATE_DOCS[variant]}
+ target='_blank'
+ rel='noopener noreferrer'
+ aria-label={`${linkLabel} (opens in a new tab)`}
+ className='inline-flex items-center gap-1 font-medium underline decoration-dashed hover:decoration-solid'
+ >
+ {linkLabel}
+ <ArrowUpRightIcon className='size-3.5' aria-hidden />
+ </a>
+ </Text>
+ </div>
+ </PanelEmptyState>
+ )
+}
+
interface PanelContainerProps {
name: React.ReactNode
children?: React.ReactNode
@@ -529,6 +606,7 @@ const CustomEvents = ({
() => _sum(_map(Object.values(eventsData || {}), (v) => Number(v) || 0)),
[eventsData],
)
+ const hasCustomEvents = !_isEmpty(eventsData)
const topEventsForChart = useMemo(() => {
if (_isEmpty(customs)) {
return []
@@ -845,7 +923,7 @@ const CustomEvents = ({
const renderContent = () => {
if (_isEmpty(eventsData)) {
- return <PanelEmptyState message={t('project.noParamData')} />
+ return <PanelDocsEmptyState variant='customEvents' />
}
return (
@@ -971,6 +1049,14 @@ const CustomEvents = ({
)
}
+ if (!hasCustomEvents) {
+ return (
+ <PanelContainer name={t('dashboard.events')} type='customEvents'>
+ <PanelDocsEmptyState variant='customEvents' />
+ </PanelContainer>
+ )
+ }
+
return (
<div className='col-span-full grid grid-cols-1 gap-3 sm:col-span-2 lg:grid-cols-[0.35fr_0.65fr]'>
<PanelContainer
@@ -1284,7 +1370,13 @@ const MetadataKeyBody = ({
const renderContent = () => {
if (!hasMetadataKeys) {
- return <PanelEmptyState message={t('project.noParamData')} />
+ return (
+ <PanelDocsEmptyState
+ variant={
+ mode === 'customEvent' ? 'customEventMetadata' : 'pageviewMetadata'
+ }
+ />
+ )
}
if (!activeKey) {
@@ -1304,6 +1396,10 @@ const MetadataKeyBody = ({
_isEmpty(valuesData) &&
(mode === 'property' || _isEmpty(rawMetadata))
) {
+ if (mode === 'customEvent') {
+ return <PanelDocsEmptyState variant='customEventMetadata' />
+ }
+
return <PanelEmptyState message={t('project.noData')} />
}
@@ -2109,6 +2205,7 @@ const Panel = ({
} | null>(null)
const tnMapping = typeNameMapping(t)
+ const docsEmptyStateVariant = getDocsEmptyStateVariant(id, activeTab)
const entriesToDisplay = useMemo(() => {
const orderedData = _orderBy(data, 'count', 'desc')
@@ -2151,7 +2248,11 @@ const Panel = ({
{customRenderer ? (
customRenderer()
) : _isEmpty(data) ? (
- <PanelEmptyState message={t('project.noParamData')} />
+ docsEmptyStateVariant ? (
+ <PanelDocsEmptyState variant={docsEmptyStateVariant} />
+ ) : (
+ <PanelEmptyState message={t('project.noParamData')} />
+ )
) : (
<>
<div className='mb-1 flex items-center justify-between p-1'>
diff --git a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
index 2872619f9..018d0a358 100644
--- a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
+++ b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
@@ -419,10 +419,13 @@ const TrafficViewInner = ({
return baseChartData
}, [baseChartData, revenueOverlay])
- const isPanelsDataEmptyRaw = useMemo(
- () => _isEmpty(panelsData.data) && _isEmpty(panelsData.customs),
- [panelsData.data, panelsData.customs],
- )
+ const isPanelsDataEmptyRaw = useMemo(() => {
+ const data = panelsData.data || {}
+ const isPanelDataEmpty =
+ _isEmpty(data) || Object.values(data).every((value) => _isEmpty(value))
+
+ return isPanelDataEmpty && _isEmpty(panelsData.customs)
+ }, [panelsData.data, panelsData.customs])
// Track when we've shown content to prevent NoEvents flash during exit animation
if (!isPanelsDataEmptyRaw) {
@@ -1417,36 +1420,31 @@ const TrafficViewInner = ({
})
: null}
{/* Combined Metadata Panel - holds both pageview properties and custom event metadata */}
- {!_isEmpty(panelsData.customs) || !_isEmpty(panelsData.properties) ? (
- <CombinedMetadataPanel
- title={t('project.metadata')}
- property={{
- metadataKeys: _keys(panelsData.properties),
- getMetadataValues: _getPropertyMetadata,
- activeKey: panelsActiveTabs.pageviewMetadata,
- onKeyChange: (key) => setPanelTab('pageviewMetadata', key),
- }}
- customEvent={{
- metadataKeys: _keys(panelsData.customs),
- getMetadataValues: getCustomEventMetadata,
- activeKey: panelsActiveTabs.customEvMetadata,
- onKeyChange: (key) => setPanelTab('customEvMetadata', key),
- }}
- getFilterLink={getFilterLink}
- chartData={chartData}
- filters={filters}
- />
- ) : null}
- {/* Custom Events Panel - Full Width */}
- {!_isEmpty(panelsData.customs) ? (
- <CustomEvents
- customs={panelsData.customs}
- filters={filters}
- getFilterLink={getFilterLink}
- chartData={chartData}
- getCustomEventMetadata={getCustomEventMetadata}
- />
- ) : null}
+ <CombinedMetadataPanel
+ title={t('project.metadata')}
+ property={{
+ metadataKeys: _keys(panelsData.properties),
+ getMetadataValues: _getPropertyMetadata,
+ activeKey: panelsActiveTabs.pageviewMetadata,
+ onKeyChange: (key) => setPanelTab('pageviewMetadata', key),
+ }}
+ customEvent={{
+ metadataKeys: _keys(panelsData.customs),
+ getMetadataValues: getCustomEventMetadata,
+ activeKey: panelsActiveTabs.customEvMetadata,
+ onKeyChange: (key) => setPanelTab('customEvMetadata', key),
+ }}
+ getFilterLink={getFilterLink}
+ chartData={chartData}
+ filters={filters}
+ />
+ <CustomEvents
+ customs={panelsData.customs}
+ filters={filters}
+ getFilterLink={getFilterLink}
+ chartData={chartData}
+ getCustomEventMetadata={getCustomEventMetadata}
+ />
</div>
<AnnotationModal
isOpened={isAnnotationModalOpen}
diff --git a/web/app/pages/Project/tabs/Traffic/UserFlow.tsx b/web/app/pages/Project/tabs/Traffic/UserFlow.tsx
index c0c9ab975..25f4617f9 100644
--- a/web/app/pages/Project/tabs/Traffic/UserFlow.tsx
+++ b/web/app/pages/Project/tabs/Traffic/UserFlow.tsx
@@ -1,4 +1,5 @@
import { ResponsiveSankey } from '@nivo/sankey'
+import { ArrowClockwiseIcon, TreeStructureIcon } from '@phosphor-icons/react'
import _isEmpty from 'lodash/isEmpty'
import { useEffect, useState, memo, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
@@ -6,6 +7,8 @@ import { toast } from 'sonner'
import { useUserFlowProxy } from '~/hooks/useAnalyticsProxy'
import type { UserFlowResponse } from '~/api/api.server'
+import { PanelEmptyState } from '~/pages/Project/View/Panels'
+import Button from '~/ui/Button'
import Loader from '~/ui/Loader'
import { Text } from '~/ui/Text'
@@ -84,20 +87,27 @@ const UserFlow = ({ setReversed, isReversed }: UserFlowProps) => {
_isEmpty(userFlow?.descending?.nodes)
) {
return (
- <>
- <Text as='p' className='text-md mt-4 flex items-center justify-center'>
+ <PanelEmptyState
+ icon={
+ <TreeStructureIcon className='size-5 text-gray-400 dark:text-slate-500' />
+ }
+ >
+ <Text as='p' size='sm' colour='secondary'>
{t('project.userFlow.noData')}
</Text>
- <button
+ <Button
+ variant='icon'
type='button'
onClick={() => {
setReversed()
}}
- className='mt-2 inline-flex w-full justify-center rounded-md border border-gray-300 bg-white px-4 py-2 text-base font-medium text-gray-700 hover:bg-gray-50 sm:w-auto sm:text-sm dark:border-none dark:border-gray-600 dark:bg-slate-700 dark:text-gray-50 dark:hover:border-gray-600 dark:hover:bg-gray-700'
+ className='mt-3 gap-1.5 px-3 py-2'
+ aria-label={t('project.reverse')}
>
+ <ArrowClockwiseIcon className='size-4' />
{t('project.reverse')}
- </button>
- </>
+ </Button>
+ </PanelEmptyState>
)
}
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index af48e1b36..028be9a97 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -2059,6 +2059,28 @@
"properties": "Properties",
"property": "Property",
"noParamData": "No data for this parameter yet",
+ "emptyStates": {
+ "customEvents": {
+ "title": "No custom events just yet.",
+ "description": "Learn how to send them at our",
+ "link": "documentation"
+ },
+ "customEventMetadata": {
+ "title": "No custom event metadata yet.",
+ "description": "Send metadata with custom events in our",
+ "link": "documentation"
+ },
+ "pageviewMetadata": {
+ "title": "No pageview metadata yet.",
+ "description": "Attach custom properties to pageviews in our",
+ "link": "documentation"
+ },
+ "utmTracking": {
+ "title": "No UTM data just yet.",
+ "description": "Learn how to tag campaigns with UTM parameters in our",
+ "link": "documentation"
+ }
+ },
"selectKey": "Select a key from the dropdown",
"selectEvent": "Select event",
"selectProperty": "Select property",