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!

Move horizontal tabs to a vertical sidebar

Blue Mouse488a1755274f
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index ca9b50729..88c3e5075 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -187,6 +187,7 @@ import NoEvents from './components/NoEvents'
import NoSessionDetails from './components/NoSessionDetails'
import { Pageflow } from './components/Pageflow'
import { PerformanceChart } from './components/PerformanceChart'
+import ProjectSidebar from './components/ProjectSidebar'
import { RefreshStatsButton } from './components/RefreshStatsButton'
import RefRow from './components/RefRow'
import SearchFilters, { getFiltersUrlParams } from './components/SearchFilters'
@@ -3225,80 +3226,25 @@ const ViewProjectContent = () => {
updatePeriod(pair)
})
- const TabSelector = () => (
- <div className='mb-[1px]'>
- <div className='sm:hidden'>
- <Select
- items={tabs}
- keyExtractor={(item) => item.id}
- labelExtractor={(item) => item.label}
- onSelect={(item) => {
- if (item.id === 'settings') {
- openSettingsHandler()
- return
- }
-
- setDashboardTab(item?.id)
- }}
- title={activeTabLabel}
- capitalise
- selectedItem={tabs.find((tab) => tab.id === activeTab)}
- />
- </div>
- <div className='hidden sm:block'>
- <nav className='-mb-px flex space-x-4 overflow-x-auto' aria-label='Tabs'>
- {_map(tabs, (tab) => {
- const isCurrent = tab.id === activeTab
-
- const handleClick = (e: React.MouseEvent) => {
- if (tab.id === 'settings') {
- return
- }
+ // Mobile tab selector dropdown
+ const MobileTabSelector = () => (
+ <div className='mb-4 md:hidden'>
+ <Select
+ items={tabs}
+ keyExtractor={(item) => item.id}
+ labelExtractor={(item) => item.label}
+ onSelect={(item) => {
+ if (item.id === 'settings') {
+ openSettingsHandler()
+ return
+ }
- e.preventDefault()
- setDashboardTab(tab.id)
- }
-
- const newSearchParams = new URLSearchParams(searchParams.toString())
- newSearchParams.set('tab', tab.id)
- const tabUrl: LinkProps['to'] =
- tab.id === 'settings'
- ? _replace(routes.project_settings, ':id', id)
- : { search: newSearchParams.toString() }
-
- return (
- <Link
- key={tab.id}
- to={tabUrl}
- onClick={handleClick}
- className={cx(
- 'text-md group inline-flex cursor-pointer items-center border-b-2 px-1 py-2 font-bold whitespace-nowrap transition-colors',
- {
- 'border-slate-900 text-slate-900 dark:border-gray-50 dark:text-gray-50': isCurrent,
- 'border-transparent text-gray-500 dark:text-gray-400': !isCurrent,
- 'cursor-wait': dataLoading && tab.id !== 'settings',
- 'hover:border-gray-300 hover:text-gray-700 dark:hover:border-gray-300 dark:hover:text-gray-300':
- !isCurrent && !dataLoading,
- },
- )}
- aria-current={isCurrent ? 'page' : undefined}
- >
- <tab.icon
- className={cx(
- isCurrent
- ? 'text-slate-900 dark:text-gray-50'
- : 'text-gray-500 group-hover:text-gray-500 dark:text-gray-400 dark:group-hover:text-gray-300',
- 'mr-2 -ml-0.5 h-5 w-5',
- )}
- aria-hidden='true'
- strokeWidth={1.5}
- />
- <span>{tab.label}</span>
- </Link>
- )
- })}
- </nav>
- </div>
+ setDashboardTab(item?.id)
+ }}
+ title={activeTabLabel}
+ capitalise
+ selectedItem={tabs.find((tab) => tab.id === activeTab)}
+ />
</div>
)
@@ -3324,19 +3270,29 @@ const ViewProjectContent = () => {
<>
{!isEmbedded ? <Header /> : null}
<div
- className={cx(
- 'mx-auto flex w-full max-w-7xl flex-col bg-gray-50 px-4 py-6 sm:px-6 lg:px-8 dark:bg-slate-900',
- {
- 'min-h-min-footer': !isEmbedded,
- 'min-h-[100vh]': isEmbedded,
- },
- )}
+ className={cx('flex bg-gray-50 dark:bg-slate-900', {
+ 'min-h-min-footer': !isEmbedded,
+ 'min-h-[100vh]': isEmbedded,
+ })}
>
- <TabSelector />
- <h2 className='mt-2 text-center text-xl font-bold break-words break-all text-gray-900 sm:text-left dark:text-gray-50'>
- {project.name}
- </h2>
- <LockedDashboard />
+ {/* Desktop Sidebar */}
+ <div className='sticky top-0 hidden h-dvh md:block'>
+ <ProjectSidebar
+ tabs={tabs}
+ activeTab={activeTab}
+ onTabChange={setDashboardTab}
+ projectId={id}
+ projectName={project.name}
+ dataLoading={dataLoading}
+ searchParams={searchParams}
+ allowedToManage={allowedToManage}
+ />
+ </div>
+ {/* Main Content */}
+ <div className='flex-1 px-4 py-3 sm:px-6 lg:px-8'>
+ <MobileTabSelector />
+ <LockedDashboard />
+ </div>
</div>
{!isEmbedded ? <Footer /> : null}
</>
@@ -3348,19 +3304,29 @@ const ViewProjectContent = () => {
<>
{!isEmbedded ? <Header /> : null}
<div
- className={cx(
- 'mx-auto flex w-full max-w-7xl flex-col bg-gray-50 px-4 py-6 sm:px-6 lg:px-8 dark:bg-slate-900',
- {
- 'min-h-min-footer': !isEmbedded,
- 'min-h-[100vh]': isEmbedded,
- },
- )}
+ className={cx('flex bg-gray-50 dark:bg-slate-900', {
+ 'min-h-min-footer': !isEmbedded,
+ 'min-h-[100vh]': isEmbedded,
+ })}
>
- <TabSelector />
- <h2 className='mt-2 text-center text-xl font-bold break-words break-all text-gray-900 sm:text-left dark:text-gray-50'>
- {project.name}
- </h2>
- <WaitingForAnEvent />
+ {/* Desktop Sidebar */}
+ <div className='sticky top-0 hidden h-dvh md:block'>
+ <ProjectSidebar
+ tabs={tabs}
+ activeTab={activeTab}
+ onTabChange={setDashboardTab}
+ projectId={id}
+ projectName={project.name}
+ dataLoading={dataLoading}
+ searchParams={searchParams}
+ allowedToManage={allowedToManage}
+ />
+ </div>
+ {/* Main Content */}
+ <div className='flex-1 px-4 py-3 sm:px-6 lg:px-8'>
+ <MobileTabSelector />
+ <WaitingForAnEvent />
+ </div>
</div>
{!isEmbedded ? <Footer /> : null}
</>
@@ -3376,19 +3342,29 @@ const ViewProjectContent = () => {
<>
{!isEmbedded ? <Header /> : null}
<div
- className={cx(
- 'mx-auto flex w-full max-w-7xl flex-col bg-gray-50 px-4 py-6 sm:px-6 lg:px-8 dark:bg-slate-900',
- {
- 'min-h-min-footer': !isEmbedded,
- 'min-h-[100vh]': isEmbedded,
- },
- )}
+ className={cx('flex bg-gray-50 dark:bg-slate-900', {
+ 'min-h-min-footer': !isEmbedded,
+ 'min-h-[100vh]': isEmbedded,
+ })}
>
- <TabSelector />
- <h2 className='mt-2 text-center text-xl font-bold break-words break-all text-gray-900 sm:text-left dark:text-gray-50'>
- {project.name}
- </h2>
- <WaitingForAnError />
+ {/* Desktop Sidebar */}
+ <div className='sticky top-0 hidden h-dvh md:block'>
+ <ProjectSidebar
+ tabs={tabs}
+ activeTab={activeTab}
+ onTabChange={setDashboardTab}
+ projectId={id}
+ projectName={project.name}
+ dataLoading={dataLoading}
+ searchParams={searchParams}
+ allowedToManage={allowedToManage}
+ />
+ </div>
+ {/* Main Content */}
+ <div className='flex-1 px-4 py-3 sm:px-6 lg:px-8'>
+ <MobileTabSelector />
+ <WaitingForAnError />
+ </div>
</div>
{!isEmbedded ? <Footer /> : null}
</>
@@ -3429,18 +3405,32 @@ const ViewProjectContent = () => {
<EventsRunningOutBanner />
<div
ref={ref}
- className={cx('bg-gray-50 dark:bg-slate-900', {
+ className={cx('flex bg-gray-50 dark:bg-slate-900', {
'min-h-[100vh]': analyticsLoading && isEmbedded,
})}
>
+ {/* Desktop Sidebar */}
+ <div className='sticky top-0 hidden h-dvh md:block'>
+ <ProjectSidebar
+ tabs={tabs}
+ activeTab={activeTab}
+ onTabChange={setDashboardTab}
+ projectId={id}
+ projectName={project.name}
+ dataLoading={dataLoading}
+ searchParams={searchParams}
+ allowedToManage={allowedToManage}
+ />
+ </div>
+ {/* Main Content */}
<div
- className={cx('mx-auto flex w-full max-w-7xl flex-col px-4 py-6 sm:px-6 lg:px-8', {
+ className={cx('flex-1 px-4 py-3 sm:px-6 lg:px-8', {
'min-h-min-footer': !isEmbedded,
'min-h-[100vh]': isEmbedded,
})}
ref={dashboardRef}
>
- <TabSelector />
+ <MobileTabSelector />
<AnimatePresence mode='wait'>
<motion.div
key={activeTab}
@@ -3453,7 +3443,7 @@ const ViewProjectContent = () => {
(activeTab !== PROJECT_TABS.sessions || !activePSID) &&
(activeFunnel || activeTab !== PROJECT_TABS.funnels) ? (
<>
- <div className='relative top-0 z-20 flex flex-col items-center justify-between bg-gray-50/50 py-2 backdrop-blur-md lg:sticky lg:flex-row dark:bg-slate-900/50'>
+ <div className='relative top-0 z-20 mb-2 flex flex-col items-center justify-between bg-gray-50/50 backdrop-blur-md lg:sticky lg:flex-row dark:bg-slate-900/50'>
<div className='flex flex-wrap items-center justify-center gap-2'>
<h2 className='text-xl font-bold break-words break-all text-gray-900 dark:text-gray-50'>
{/* If tab is funnels - then display a funnel name, otherwise a project name */}
diff --git a/web/app/pages/Project/View/components/ProjectSidebar.tsx b/web/app/pages/Project/View/components/ProjectSidebar.tsx
new file mode 100644
index 000000000..2cef9d715
--- /dev/null
+++ b/web/app/pages/Project/View/components/ProjectSidebar.tsx
@@ -0,0 +1,279 @@
+import cx from 'clsx'
+import _map from 'lodash/map'
+import { ChevronDownIcon, ChevronRightIcon, GlobeIcon, BarChart3Icon, SettingsIcon } from 'lucide-react'
+import React, { useState, useMemo } from 'react'
+import { useTranslation } from 'react-i18next'
+import { Link, LinkProps } from 'react-router'
+
+import { PROJECT_TABS } from '~/lib/constants'
+import Tooltip from '~/ui/Tooltip'
+import routes from '~/utils/routes'
+
+type ProjectTabKey = keyof typeof PROJECT_TABS | 'settings'
+
+// Icon color classes for each tab - similar to Posthog's colorful sidebar
+const ICON_COLORS: Record<string, string> = {
+ // Web Analytics
+ traffic: 'text-emerald-500',
+ performance: 'text-orange-500',
+ alerts: 'text-yellow-500',
+ // Product Analytics
+ profiles: 'text-blue-500',
+ sessions: 'text-violet-500',
+ funnels: 'text-pink-500',
+ errors: 'text-red-500',
+ // Revenue Analytics (placeholder)
+ revenue: 'text-green-500',
+ // Settings
+ settings: 'text-gray-500',
+}
+
+// Group icon colors
+const GROUP_ICON_COLORS: Record<string, string> = {
+ webAnalytics: 'text-emerald-500',
+ productAnalytics: 'text-blue-500',
+ revenueAnalytics: 'text-green-500',
+}
+
+interface Tab {
+ id: ProjectTabKey
+ label: string
+ icon: React.ComponentType<{ className?: string; strokeWidth?: number }>
+}
+
+interface TabGroup {
+ id: string
+ label: string
+ icon: React.ComponentType<{ className?: string; strokeWidth?: number }>
+ tabs: Tab[]
+ defaultExpanded?: boolean
+}
+
+interface ProjectSidebarProps {
+ tabs: Tab[]
+ activeTab: ProjectTabKey
+ onTabChange: (tabId: keyof typeof PROJECT_TABS) => void
+ projectId: string
+ projectName: string
+ dataLoading?: boolean
+ searchParams: URLSearchParams
+ allowedToManage?: boolean
+}
+
+const CollapsibleGroup: React.FC<{
+ group: TabGroup
+ activeTab: ProjectTabKey
+ onTabChange: (tabId: keyof typeof PROJECT_TABS) => void
+ projectId: string
+ dataLoading?: boolean
+ searchParams: URLSearchParams
+}> = ({ group, activeTab, onTabChange, projectId, dataLoading, searchParams }) => {
+ const [isExpanded, setIsExpanded] = useState(group.defaultExpanded ?? true)
+
+ const hasActiveTab = useMemo(() => {
+ return group.tabs.some((tab) => tab.id === activeTab)
+ }, [group.tabs, activeTab])
+
+ // Auto-expand if a tab in this group is active
+ React.useEffect(() => {
+ if (hasActiveTab && !isExpanded) {
+ setIsExpanded(true)
+ }
+ }, [hasActiveTab]) // eslint-disable-line react-hooks/exhaustive-deps
+
+ const GroupIcon = group.icon
+ const groupColorClass = GROUP_ICON_COLORS[group.id] || 'text-gray-500'
+
+ return (
+ <div className='mb-1'>
+ <button
+ type='button'
+ onClick={() => setIsExpanded(!isExpanded)}
+ className={cx(
+ 'group flex w-full items-center justify-between rounded-md px-2 py-1.5 text-left text-xs font-semibold tracking-wide uppercase transition-colors',
+ {
+ 'text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-slate-800/50': !hasActiveTab,
+ 'text-gray-900 dark:text-gray-100': hasActiveTab,
+ },
+ )}
+ >
+ <div className='flex items-center gap-2'>
+ <GroupIcon className={cx('h-4 w-4', groupColorClass)} strokeWidth={1.5} />
+ <span>{group.label}</span>
+ </div>
+ {isExpanded ? (
+ <ChevronDownIcon className='h-3.5 w-3.5 text-gray-400' strokeWidth={2} />
+ ) : (
+ <ChevronRightIcon className='h-3.5 w-3.5 text-gray-400' strokeWidth={2} />
+ )}
+ </button>
+
+ <div
+ className={cx('overflow-hidden transition-all duration-200 ease-in-out', {
+ 'max-h-96 opacity-100': isExpanded,
+ 'max-h-0 opacity-0': !isExpanded,
+ })}
+ >
+ <nav className='mt-1 flex flex-col gap-0.5 pl-2'>
+ {_map(group.tabs, (tab) => {
+ const isCurrent = tab.id === activeTab
+ const TabIcon = tab.icon
+ const iconColorClass = ICON_COLORS[tab.id] || 'text-gray-500'
+
+ const handleClick = (e: React.MouseEvent) => {
+ if (tab.id === 'settings') {
+ return // Let the Link handle navigation
+ }
+
+ e.preventDefault()
+ if (!dataLoading) {
+ onTabChange(tab.id as keyof typeof PROJECT_TABS)
+ }
+ }
+
+ const newSearchParams = new URLSearchParams(searchParams.toString())
+ newSearchParams.set('tab', tab.id)
+ const tabUrl: LinkProps['to'] =
+ tab.id === 'settings'
+ ? routes.project_settings.replace(':id', projectId)
+ : { search: newSearchParams.toString() }
+
+ return (
+ <Link
+ key={tab.id}
+ to={tabUrl}
+ onClick={handleClick}
+ className={cx(
+ 'group flex items-center gap-2.5 rounded-md px-2.5 py-2 text-sm font-medium transition-colors',
+ {
+ 'bg-gray-100 text-gray-900 dark:bg-slate-800 dark:text-gray-50': isCurrent,
+ 'text-gray-600 hover:bg-gray-50 hover:text-gray-900 dark:text-gray-400 dark:hover:bg-slate-800/50 dark:hover:text-gray-200':
+ !isCurrent,
+ 'cursor-wait opacity-50': dataLoading && tab.id !== 'settings',
+ },
+ )}
+ aria-current={isCurrent ? 'page' : undefined}
+ >
+ <TabIcon className={cx('h-5 w-5 shrink-0', iconColorClass)} strokeWidth={1.5} aria-hidden='true' />
+ <span className='truncate'>{tab.label}</span>
+ </Link>
+ )
+ })}
+ </nav>
+ </div>
+ </div>
+ )
+}
+
+const ProjectSidebar: React.FC<ProjectSidebarProps> = ({
+ tabs,
+ activeTab,
+ onTabChange,
+ projectId,
+ projectName,
+ dataLoading,
+ searchParams,
+ allowedToManage,
+}) => {
+ const { t } = useTranslation('common')
+
+ // Group tabs by category
+ const tabGroups = useMemo<TabGroup[]>(() => {
+ const groups: TabGroup[] = []
+
+ // Web Analytics group
+ const webAnalyticsTabs = tabs.filter((tab) =>
+ [PROJECT_TABS.traffic, PROJECT_TABS.performance, PROJECT_TABS.alerts].includes(tab.id as any),
+ )
+ if (webAnalyticsTabs.length > 0) {
+ groups.push({
+ id: 'webAnalytics',
+ label: t('dashboard.webAnalytics'),
+ icon: GlobeIcon,
+ tabs: webAnalyticsTabs,
+ defaultExpanded: true,
+ })
+ }
+
+ // Product Analytics group
+ const productAnalyticsTabs = tabs.filter((tab) =>
+ [PROJECT_TABS.profiles, PROJECT_TABS.sessions, PROJECT_TABS.funnels, PROJECT_TABS.errors].includes(tab.id as any),
+ )
+ if (productAnalyticsTabs.length > 0) {
+ groups.push({
+ id: 'productAnalytics',
+ label: t('dashboard.productAnalytics'),
+ icon: BarChart3Icon,
+ tabs: productAnalyticsTabs,
+ defaultExpanded: true,
+ })
+ }
+
+ // Revenue Analytics group (placeholder for future)
+ // const revenueAnalyticsTabs = tabs.filter((tab) =>
+ // ['revenue'].includes(tab.id),
+ // )
+ // if (revenueAnalyticsTabs.length > 0) {
+ // groups.push({
+ // id: 'revenueAnalytics',
+ // label: t('dashboard.revenueAnalytics'),
+ // icon: DollarSignIcon,
+ // tabs: revenueAnalyticsTabs,
+ // defaultExpanded: true,
+ // })
+ // }
+
+ return groups
+ }, [tabs, t])
+
+ return (
+ <aside className='flex h-full w-56 shrink-0 flex-col overflow-y-auto border-r border-gray-200 bg-white dark:border-slate-800 dark:bg-slate-900'>
+ {/* Project name at the top */}
+ <div className='sticky top-0 z-10 border-b border-gray-200 bg-white px-3 py-3 dark:border-slate-800 dark:bg-slate-900'>
+ <Tooltip
+ text={projectName}
+ tooltipNode={
+ <p className='max-w-full truncate text-sm font-medium text-gray-900 dark:text-gray-50'>{projectName}</p>
+ }
+ />
+ </div>
+
+ {/* Tabs area */}
+ <div className='flex-1 px-2 py-3'>
+ {_map(tabGroups, (group) => (
+ <CollapsibleGroup
+ key={group.id}
+ group={group}
+ activeTab={activeTab}
+ onTabChange={onTabChange}
+ projectId={projectId}
+ dataLoading={dataLoading}
+ searchParams={searchParams}
+ />
+ ))}
+ </div>
+
+ {/* Settings at the bottom - always show if user is allowed to manage */}
+ {allowedToManage ? (
+ <div className='sticky bottom-0 border-t border-gray-200 bg-white px-2 py-2 dark:border-slate-800 dark:bg-slate-900'>
+ <Link
+ to={routes.project_settings.replace(':id', projectId)}
+ className={cx(
+ 'group flex items-center gap-2.5 rounded-md px-2.5 py-2 text-sm font-medium transition-colors',
+ 'text-gray-600 hover:bg-gray-50 hover:text-gray-900 dark:text-gray-400 dark:hover:bg-slate-800/50 dark:hover:text-gray-200',
+ )}
+ >
+ <SettingsIcon
+ className={cx('h-5 w-5 shrink-0', ICON_COLORS.settings)}
+ strokeWidth={1.5}
+ aria-hidden='true'
+ />
+ <span className='truncate'>{t('common.settings')}</span>
+ </Link>
+ </div>
+ ) : null}
+ </aside>
+ )
+}
+
+export default ProjectSidebar
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index 81c8dea6b..b2492eee5 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -837,6 +837,9 @@
"events": "Events",
"alerts": "Alerts",
"alertsDesc": "Automated alerts is a powerful tool that notifies you when some events occur on your website.\nWe can automatically monitor your project for traffic spikes and notify you via Telegram, Slack or Discord.",
+ "webAnalytics": "Web analytics",
+ "productAnalytics": "Product analytics",
+ "revenueAnalytics": "Revenue analytics",
"funnelsDesc": "Funnels is a powerful tool that allows you to track the conversion rate of your users through a series of steps.\nThe analysis provided by the marketing funnel gives you the ability to discover potential problems, improve your website, and boost your conversion rate.",
"frontend": "Frontend",
"backend": "Backend",