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!

Better Goals UI

Blue Mousea2c00b919f3f
diff --git a/web/app/modals/NewFunnel.tsx b/web/app/modals/NewFunnel.tsx
index e230dfeef..bdf0a8208 100644
--- a/web/app/modals/NewFunnel.tsx
+++ b/web/app/modals/NewFunnel.tsx
@@ -128,7 +128,7 @@ const NewFunnel = ({ onClose, onSubmit, isOpened, funnel, loading }: NewFunnelPr
{steps.length > MIN_FUNNEL_STEPS && allowedToManage ? (
<button
type='button'
- className='rounded-md p-2 text-gray-800 hover:bg-gray-100 hover:text-gray-900 dark:text-slate-400 dark:hover:bg-slate-700 dark:hover:text-slate-300'
+ className='rounded-md border border-transparent p-1.5 text-gray-800 transition-colors hover:border-gray-300 hover:bg-gray-50 hover:text-gray-900 dark:text-slate-400 hover:dark:border-slate-700/80 dark:hover:bg-slate-800 dark:hover:text-slate-300'
onClick={() => {
const newSteps = [...steps]
newSteps.splice(index, 1)
diff --git a/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx b/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx
index 10860adf4..36bfd10fd 100644
--- a/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx
+++ b/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx
@@ -210,7 +210,19 @@ const GoalSettingsModal = ({ isOpen, onClose, onSuccess, projectId, goalId }: Go
label={type === 'pageview' ? t('goals.pagePath') : t('goals.eventName')}
value={value}
onChange={(e) => setValue(e.target.value)}
- placeholder={type === 'pageview' ? '/pricing' : 'signup_completed'}
+ placeholder={
+ type === 'pageview'
+ ? matchType === 'exact'
+ ? '/pricing'
+ : matchType === 'contains'
+ ? 'pricing'
+ : '^/blog/.*'
+ : matchType === 'exact'
+ ? 'signup_completed'
+ : matchType === 'contains'
+ ? 'signup'
+ : 'signup_.*'
+ }
/>
{/* Metadata filters */}
@@ -245,9 +257,13 @@ const GoalSettingsModal = ({ isOpen, onClose, onSuccess, projectId, goalId }: Go
placeholder={t('goals.filterValue')}
className='flex-1'
/>
- <Button type='button' onClick={() => removeMetadataFilter(index)} noBorder small>
+ <button
+ type='button'
+ onClick={() => removeMetadataFilter(index)}
+ className='rounded-md border border-transparent p-1.5 text-gray-800 transition-colors hover:border-gray-300 hover:bg-gray-50 hover:text-gray-900 dark:text-slate-400 hover:dark:border-slate-700/80 dark:hover:bg-slate-800 dark:hover:text-slate-300'
+ >
<Trash2Icon className='h-4 w-4' />
- </Button>
+ </button>
</div>
))}
</div>
diff --git a/web/app/pages/Project/Goals/View/GoalsView.tsx b/web/app/pages/Project/Goals/View/GoalsView.tsx
index 4766ef600..62e7936d3 100644
--- a/web/app/pages/Project/Goals/View/GoalsView.tsx
+++ b/web/app/pages/Project/Goals/View/GoalsView.tsx
@@ -1,7 +1,15 @@
-import { ChevronRightIcon, XCircleIcon } from '@heroicons/react/24/outline'
+import { XCircleIcon } from '@heroicons/react/24/outline'
import _isEmpty from 'lodash/isEmpty'
import _map from 'lodash/map'
-import { TargetIcon, Trash2Icon, PencilIcon, PlusIcon, SearchIcon, FileTextIcon, ZapIcon } from 'lucide-react'
+import {
+ TargetIcon,
+ Trash2Icon,
+ PencilIcon,
+ PlusIcon,
+ SearchIcon,
+ FileTextIcon,
+ MousePointerClickIcon,
+} from 'lucide-react'
import { useState, useEffect, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router'
@@ -17,20 +25,16 @@ import {
} from '~/api'
import { useViewProjectContext } from '~/pages/Project/View/ViewProject'
import { useCurrentProject } from '~/providers/CurrentProjectProvider'
-import { Badge, type BadgeProps } from '~/ui/Badge'
import Button from '~/ui/Button'
import Loader from '~/ui/Loader'
import Modal from '~/ui/Modal'
import Pagination from '~/ui/Pagination'
+import ProgressRing from '~/ui/ProgressRing'
+import { Text } from '~/ui/Text'
import routes from '~/utils/routes'
import GoalSettingsModal from './GoalSettingsModal'
-const GOAL_TYPE_BADGE_COLOURS: Record<Goal['type'], BadgeProps['colour']> = {
- pageview: 'indigo',
- custom_event: 'green',
-}
-
interface GoalRowProps {
goal: Goal
stats: GoalStats | null
@@ -40,18 +44,10 @@ interface GoalRowProps {
onClick: (id: string) => void
}
-const Separator = () => (
- <svg viewBox='0 0 2 2' className='h-0.5 w-0.5 flex-none fill-gray-400'>
- <circle cx={1} cy={1} r={1} />
- </svg>
-)
-
const GoalRow = ({ goal, stats, statsLoading, onDelete, onEdit, onClick }: GoalRowProps) => {
const { t } = useTranslation()
const [showDeleteModal, setShowDeleteModal] = useState(false)
- const typeLabel = goal.type === 'pageview' ? t('goals.typePageview') : t('goals.typeCustomEvent')
-
const patternDisplay = useMemo(() => {
if (!goal.value) return null
const matchPrefix =
@@ -67,89 +63,92 @@ const GoalRow = ({ goal, stats, statsLoading, onDelete, onEdit, onClick }: GoalR
>
<div className='flex min-w-0 gap-x-4'>
<div className='min-w-0 flex-auto'>
- <p className='flex items-center gap-x-2 text-sm leading-6 font-semibold text-gray-900 dark:text-gray-50'>
+ <Text as='p' weight='semibold' truncate className='flex items-center gap-x-1.5'>
{goal.type === 'pageview' ? (
- <FileTextIcon className='size-4 text-indigo-500' strokeWidth={1.5} />
+ <FileTextIcon className='size-4 text-blue-500' strokeWidth={1.5} />
) : (
- <ZapIcon className='size-4 text-green-500' strokeWidth={1.5} />
+ <MousePointerClickIcon className='size-4 text-amber-500' strokeWidth={1.5} />
)}
<span>{goal.name}</span>
- <Badge colour={GOAL_TYPE_BADGE_COLOURS[goal.type]} label={typeLabel} />
- </p>
- {patternDisplay && (
- <p className='mt-1 flex flex-wrap items-center gap-x-2 text-xs leading-5 text-gray-500 dark:text-gray-300'>
- <code className='rounded bg-gray-200/80 px-1.5 py-0.5 font-mono text-xs text-gray-600 dark:bg-slate-700 dark:text-gray-300'>
- {patternDisplay}
- </code>
- </p>
- )}
+ </Text>
+ {patternDisplay ? (
+ <Text className='mt-1 max-w-max' as='p' size='xs' colour='secondary' code>
+ {patternDisplay}
+ </Text>
+ ) : null}
{/* Mobile stats */}
- <p className='mt-2 flex items-center gap-x-3 text-xs leading-5 text-gray-500 sm:hidden dark:text-gray-300'>
+ <div className='mt-2 flex items-center gap-x-3 text-xs leading-5 text-gray-500 sm:hidden dark:text-gray-300'>
{statsLoading ? (
- <Loader size='sm' />
+ <Loader />
) : stats ? (
<>
<span>
- <span className='font-semibold text-gray-900 dark:text-gray-50'>
+ <Text as='span' size='xs' weight='semibold'>
{stats.conversions.toLocaleString()}
- </span>{' '}
- {t('goals.conversions').toLowerCase()}
- </span>
- <Separator />
- <span>
- <span className='font-semibold text-gray-900 dark:text-gray-50'>{stats.conversionRate}%</span>{' '}
- {t('goals.conversionRate').toLowerCase()}
+ </Text>{' '}
+ <Text as='span' size='xs' colour='secondary'>
+ {t('goals.conversions').toLowerCase()}
+ </Text>
</span>
+ <ProgressRing value={stats.conversionRate} size={36} strokeWidth={3} />
</>
) : (
- <span>{t('goals.noData')}</span>
+ <Text as='p' size='xs' colour='muted'>
+ {t('goals.noData')}
+ </Text>
)}
- </p>
+ </div>
</div>
</div>
<div className='flex shrink-0 items-center gap-x-4'>
- <div className='hidden sm:flex sm:flex-col sm:items-end'>
+ <div className='hidden sm:flex sm:items-center sm:gap-x-3'>
{statsLoading ? (
- <Loader size='sm' />
+ <Loader />
) : stats ? (
<>
- <p className='text-sm leading-6 text-gray-900 dark:text-gray-50'>
- <span className='font-semibold'>{stats.conversions.toLocaleString()}</span>{' '}
- <span className='text-gray-500 dark:text-gray-400'>{t('goals.conversions').toLowerCase()}</span>
- </p>
- <p className='mt-1 text-xs leading-5 text-gray-500 dark:text-gray-400'>
- <span className='font-medium text-gray-700 dark:text-gray-300'>{stats.conversionRate}%</span>{' '}
- {t('goals.conversionRate').toLowerCase()}
+ <p className='text-sm leading-6'>
+ <Text as='span' size='sm' weight='semibold'>
+ {stats.conversions.toLocaleString()}
+ </Text>{' '}
+ <Text as='span' size='sm' colour='secondary'>
+ {t('goals.conversions').toLowerCase()}
+ </Text>
</p>
+ <ProgressRing value={stats.conversionRate} size={44} strokeWidth={3.5} />
</>
) : (
- <p className='text-sm text-gray-500 dark:text-gray-400'>{t('goals.noData')}</p>
+ <Text as='p' size='sm' colour='muted'>
+ {t('goals.noData')}
+ </Text>
)}
</div>
{/* Action buttons */}
- <div className='flex items-center gap-x-1'>
+ <div className='flex items-center gap-1'>
<button
+ type='button'
onClick={(e) => {
+ e.preventDefault()
e.stopPropagation()
onEdit(goal.id)
}}
aria-label={t('common.edit')}
- className='rounded-md p-1.5 text-gray-400 transition-colors hover:bg-gray-200 hover:text-gray-600 dark:text-gray-500 dark:hover:bg-slate-700 dark:hover:text-gray-300'
+ className='rounded-md border border-transparent p-1.5 text-gray-800 transition-colors hover:border-gray-300 hover:bg-gray-50 hover:text-gray-900 dark:text-slate-400 hover:dark:border-slate-700/80 dark:hover:bg-slate-800 dark:hover:text-slate-300'
>
<PencilIcon className='size-4' strokeWidth={1.5} />
</button>
<button
+ type='button'
onClick={(e) => {
+ e.preventDefault()
e.stopPropagation()
setShowDeleteModal(true)
}}
aria-label={t('common.delete')}
- className='rounded-md p-1.5 text-gray-400 transition-colors hover:bg-red-100 hover:text-red-600 dark:text-gray-500 dark:hover:bg-red-900/30 dark:hover:text-red-400'
+ className='rounded-md border border-transparent p-1.5 text-gray-800 transition-colors hover:border-gray-300 hover:bg-gray-50 hover:text-gray-900 dark:text-slate-400 hover:dark:border-slate-700/80 dark:hover:bg-slate-800 dark:hover:text-slate-300'
>
<Trash2Icon className='size-4' strokeWidth={1.5} />
</button>
</div>
- <ChevronRightIcon className='h-5 w-5 flex-none text-gray-400' aria-hidden='true' />
</div>
</li>
<Modal
@@ -384,9 +383,9 @@ const GoalsView = ({ period, from = '', to = '', timezone }: GoalsViewProps) =>
))}
</ul>
- {filteredGoals.length === 0 && filterQuery && (
+ {filteredGoals.length === 0 && filterQuery ? (
<p className='py-8 text-center text-sm text-gray-500 dark:text-gray-400'>{t('goals.noGoalsMatchFilter')}</p>
- )}
+ ) : null}
</>
)}
{pageAmount > 1 && !filterQuery ? (
diff --git a/web/app/ui/ProgressRing.tsx b/web/app/ui/ProgressRing.tsx
new file mode 100644
index 000000000..b5025007e
--- /dev/null
+++ b/web/app/ui/ProgressRing.tsx
@@ -0,0 +1,115 @@
+import { memo, useMemo } from 'react'
+
+import { cn } from '~/utils/generic'
+
+type ColourThresholds = {
+ green: number // >= this value is green
+ amber: number // >= this value (and < green) is amber
+ // < amber is red
+}
+
+interface ProgressRingProps {
+ /** Value from 0 to 100 */
+ value: number
+ /** Size of the ring in pixels */
+ size?: number
+ /** Stroke width of the ring */
+ strokeWidth?: number
+ /** Custom class name */
+ className?: string
+ /** Whether to show the percentage text in the center */
+ showValue?: boolean
+ /** Custom thresholds for colour coding. Default: { green: 80, amber: 40 } */
+ thresholds?: ColourThresholds
+}
+
+const DEFAULT_THRESHOLDS: ColourThresholds = {
+ green: 80,
+ amber: 40,
+}
+
+const getColourClasses = (value: number, thresholds: ColourThresholds) => {
+ if (value >= thresholds.green) {
+ return {
+ stroke: 'stroke-green-500 dark:stroke-green-400',
+ text: 'text-green-600 dark:text-green-400',
+ }
+ }
+
+ if (value >= thresholds.amber) {
+ return {
+ stroke: 'stroke-amber-500 dark:stroke-amber-400',
+ text: 'text-amber-600 dark:text-amber-400',
+ }
+ }
+
+ return {
+ stroke: 'stroke-red-500 dark:stroke-red-400',
+ text: 'text-red-600 dark:text-red-400',
+ }
+}
+
+const ProgressRing = ({
+ value,
+ size = 40,
+ strokeWidth = 4,
+ className,
+ showValue = true,
+ thresholds = DEFAULT_THRESHOLDS,
+}: ProgressRingProps) => {
+ const normalizedValue = useMemo(() => Math.min(100, Math.max(0, value)), [value])
+
+ const { radius, circumference, strokeDashoffset } = useMemo(() => {
+ const r = (size - strokeWidth) / 2
+ const c = 2 * Math.PI * r
+ const offset = c - (normalizedValue / 100) * c
+
+ return {
+ radius: r,
+ circumference: c,
+ strokeDashoffset: offset,
+ }
+ }, [size, strokeWidth, normalizedValue])
+
+ const colourClasses = useMemo(() => getColourClasses(normalizedValue, thresholds), [normalizedValue, thresholds])
+
+ const center = size / 2
+
+ return (
+ <div className={cn('relative inline-flex items-center justify-center', className)}>
+ <svg width={size} height={size} className='-rotate-90'>
+ {/* Background circle */}
+ <circle
+ cx={center}
+ cy={center}
+ r={radius}
+ fill='none'
+ strokeWidth={strokeWidth}
+ className='stroke-gray-200 dark:stroke-slate-600'
+ />
+ {/* Progress circle */}
+ <circle
+ cx={center}
+ cy={center}
+ r={radius}
+ fill='none'
+ strokeWidth={strokeWidth}
+ strokeLinecap='round'
+ strokeDasharray={circumference}
+ strokeDashoffset={strokeDashoffset}
+ className={cn('transition-all duration-300 ease-out', colourClasses.stroke)}
+ />
+ </svg>
+ {showValue ? (
+ <span
+ className={cn('absolute text-center font-semibold', colourClasses.text)}
+ style={{ fontSize: size * 0.22 }}
+ >
+ {Math.round(normalizedValue)}%
+ </span>
+ ) : null}
+ </div>
+ )
+}
+
+export default memo(ProgressRing)
diff --git a/web/app/ui/Text.tsx b/web/app/ui/Text.tsx
index d65ea0ef0..0ec51c671 100644
--- a/web/app/ui/Text.tsx
+++ b/web/app/ui/Text.tsx
@@ -14,6 +14,7 @@ interface TextProps {
weight?: TextWeight
colour?: TextColour
truncate?: boolean
+ code?: boolean
className?: string
[key: string]: unknown
}
@@ -54,11 +55,19 @@ export const Text = ({
weight = 'normal',
colour = 'primary',
truncate,
+ code,
className,
...props
}: TextProps) => (
<Component
- className={cn(sizeClasses[size], weightClasses[weight], colourClasses[colour], { truncate }, className)}
+ className={cn(
+ sizeClasses[size],
+ weightClasses[weight],
+ colourClasses[colour],
+ { truncate },
+ code && 'rounded bg-gray-200/80 px-1.5 py-0.5 font-mono dark:bg-slate-700',
+ className,
+ )}
{...props}
>
{children}