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!

Make sessions list items more minimalistic

Blue Mousee94467ba7268
diff --git a/web/app/pages/Project/tabs/Sessions/Sessions.tsx b/web/app/pages/Project/tabs/Sessions/Sessions.tsx
index 6107c0bed..24fbb687b 100644
--- a/web/app/pages/Project/tabs/Sessions/Sessions.tsx
+++ b/web/app/pages/Project/tabs/Sessions/Sessions.tsx
@@ -7,23 +7,30 @@ import {
FileTextIcon,
WarningIcon,
CursorClickIcon,
- CalendarDotsIcon,
CaretRightIcon,
+ GlobeIcon,
} from '@phosphor-icons/react'
import React, { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { Link, useLocation } from 'react-router'
import { ClientOnly } from 'remix-utils/client-only'
+import {
+ BROWSER_LOGO_MAP,
+ OS_LOGO_MAP,
+ OS_LOGO_MAP_DARK,
+} from '~/lib/constants'
import { Session as SessionType } from '~/lib/models/Project'
+import { useTheme } from '~/providers/ThemeProvider'
import { Badge } from '~/ui/Badge'
+import Flag from '~/ui/Flag'
import Loader from '~/ui/Loader'
+import { Text } from '~/ui/Text'
import Tooltip from '~/ui/Tooltip'
import { getStringFromTime, getTimeFromSeconds } from '~/utils/generic'
+import countries from '~/utils/isoCountries'
import { getProfileDisplayName, ProfileAvatar } from '~/utils/profileAvatars'
-import CCRow from '../../View/components/CCRow'
-
dayjs.extend(duration)
dayjs.extend(relativeTime)
@@ -76,11 +83,60 @@ interface SessionProps {
currency?: string
}
-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 BrowserIcon = ({
+ browser,
+ className,
+}: {
+ browser: string | null
+ className?: string
+}) => {
+ if (!browser)
+ return (
+ <GlobeIcon
+ className={className || 'size-3.5 text-gray-400'}
+ weight='duotone'
+ />
+ )
+ const logoUrl = BROWSER_LOGO_MAP[browser as keyof typeof BROWSER_LOGO_MAP]
+ if (!logoUrl)
+ return (
+ <GlobeIcon
+ className={className || 'size-3.5 text-gray-400'}
+ weight='duotone'
+ />
+ )
+ return <img src={logoUrl} className={className || 'size-3.5'} alt={browser} />
+}
+
+const OSIcon = ({
+ os,
+ theme,
+ className,
+}: {
+ os: string | null
+ theme: string
+ className?: string
+}) => {
+ if (!os)
+ return (
+ <GlobeIcon
+ className={className || 'size-3.5 text-gray-400'}
+ weight='duotone'
+ />
+ )
+ const logoUrlLight = OS_LOGO_MAP[os as keyof typeof OS_LOGO_MAP]
+ const logoUrlDark = OS_LOGO_MAP_DARK[os as keyof typeof OS_LOGO_MAP_DARK]
+ let logoUrl = theme === 'dark' ? logoUrlDark : logoUrlLight
+ logoUrl ||= logoUrlLight
+ if (!logoUrl)
+ return (
+ <GlobeIcon
+ className={className || 'size-3.5 text-gray-400'}
+ weight='duotone'
+ />
+ )
+ return <img src={logoUrl} className={className || 'size-3.5'} alt={os} />
+}
export const Session = ({
session,
@@ -95,6 +151,7 @@ export const Session = ({
i18n: { language },
} = useTranslation('common')
const location = useLocation()
+ const { theme } = useTheme()
const sessionStartTime = dayjs(session.sessionStart)
@@ -131,36 +188,39 @@ export const Session = ({
const startDateTimeStr = sessionStartTime
.toDate()
.toLocaleDateString(language, {
- day: 'numeric',
month: 'short',
- year: 'numeric',
+ day: 'numeric',
hour: 'numeric',
minute: 'numeric',
hourCycle: timeFormat === '12-hour' ? 'h12' : 'h23',
})
if (session.isLive) {
- return startDateTimeStr
- }
-
- let endDisplayTime
- if (session.sdur != null && session.sdur > 0) {
- endDisplayTime = sessionStartTime.add(session.sdur, 'seconds')
- } else {
- endDisplayTime = dayjs(session.lastActivity)
+ return (
+ <span className='flex items-center font-medium text-red-500'>
+ <span className='mr-1.5 h-1.5 w-1.5 animate-pulse rounded-full bg-red-500' />
+ {t('dashboard.live')}
+ </span>
+ )
}
- const endTimeStr = endDisplayTime.toDate().toLocaleTimeString(language, {
- hour: 'numeric',
- minute: 'numeric',
- hourCycle: timeFormat === '12-hour' ? 'h12' : 'h23',
- })
-
const durationDisplay = sessionDurationString
- ? ` (${sessionDurationString})`
+ ? ` • ${sessionDurationString}`
: ''
- return `${startDateTimeStr} - ${endTimeStr}${durationDisplay}`
- }, [session, language, timeFormat, sessionDurationString, sessionStartTime])
+ return (
+ <span className='flex items-center'>
+ {startDateTimeStr}
+ {durationDisplay}
+ </span>
+ )
+ }, [
+ session,
+ language,
+ timeFormat,
+ sessionDurationString,
+ sessionStartTime,
+ t,
+ ])
const onlineStatus = useMemo(
() => getOnlineStatus(session.lastActivity),
@@ -177,173 +237,231 @@ export const Session = ({
params.set('tab', 'sessions')
return (
- <Link to={{ search: params.toString() }}>
- <li className='relative mb-3 flex cursor-pointer justify-between gap-x-6 overflow-hidden rounded-lg border border-gray-200 bg-gray-50 px-4 py-4 transition-colors hover:bg-gray-200/70 sm:px-6 dark:border-slate-800/60 dark:bg-slate-900/25 dark:hover:bg-slate-900/60'>
- <div className='flex min-w-0 gap-x-3'>
- {hideUserDetails ? null : (
- <div className='relative shrink-0'>
- {session.profileId ? (
- <ProfileAvatar
- className='mt-1'
- profileId={session.profileId}
- size={40}
- />
- ) : (
- <div className='flex h-10 w-10 items-center justify-center rounded-full bg-gray-200 dark:bg-slate-600'>
- <span className='text-sm font-medium text-gray-500 dark:text-gray-300'>
- ?
- </span>
- </div>
- )}
- {onlineStatus === 'offline' ? null : (
- <Tooltip
- text={t('project.lastSeenAgo', { time: lastActivityAgo })}
- className='absolute right-0 bottom-2'
- tooltipNode={
- <span
- className={cx(
- 'block h-3 w-3 rounded-full ring-2 ring-gray-50 dark:ring-slate-800',
- onlineStatus === 'online' && 'bg-green-500',
- onlineStatus === 'recently_active' && 'bg-yellow-500',
- )}
- />
- }
- />
- )}
- </div>
- )}
-
- <div className='min-w-0 flex-auto'>
- {hideUserDetails ? null : (
- <p className='flex items-center text-sm leading-6 font-semibold text-gray-900 dark:text-gray-50'>
- <span className='truncate'>{displayName}</span>
- {session.isIdentified ? (
- <Badge
- label={t('project.identified')}
- colour='indigo'
- className='ml-2'
- />
- ) : null}
- {hideNewReturnBadge ? null : (
- <Badge
- label={
- session.isFirstSession
- ? t('project.sessionNew')
- : t('project.sessionReturn')
+ <li className='mb-2'>
+ <Link
+ to={{ search: params.toString() }}
+ className='block rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-slate-900 dark:focus-visible:ring-slate-300'
+ >
+ <div className='relative flex cursor-pointer items-center justify-between gap-x-4 overflow-hidden rounded-lg border border-gray-200 bg-gray-50 px-4 py-3 transition-colors hover:bg-gray-200/70 sm:px-5 dark:border-slate-800/60 dark:bg-slate-900/25 dark:hover:bg-slate-900/60'>
+ <div className='flex min-w-0 flex-1 items-center gap-x-3.5'>
+ {!hideUserDetails && (
+ <div className='relative shrink-0'>
+ {session.profileId ? (
+ <ProfileAvatar profileId={session.profileId} size={32} />
+ ) : (
+ <div className='flex h-8 w-8 items-center justify-center rounded-full bg-gray-100 ring-1 ring-gray-200/50 dark:bg-slate-800 dark:ring-slate-700/50'>
+ <Text size='xs' weight='medium' colour='secondary'>
+ ?
+ </Text>
+ </div>
+ )}
+ {onlineStatus !== 'offline' && (
+ <Tooltip
+ text={t('project.lastSeenAgo', { time: lastActivityAgo })}
+ className='absolute -right-0.5 -bottom-0.5'
+ tooltipNode={
+ <span
+ className={cx(
+ 'block h-2.5 w-2.5 rounded-full ring-2 ring-white dark:ring-slate-900',
+ onlineStatus === 'online'
+ ? 'bg-emerald-500'
+ : 'bg-amber-500',
+ )}
+ />
}
- colour={session.isFirstSession ? 'green' : 'slate'}
- className='ml-2'
/>
)}
- </p>
+ </div>
)}
- <p className='mt-1 flex flex-wrap items-center gap-x-2 text-xs leading-5 text-gray-500 dark:text-gray-300'>
- <span className='flex items-center'>
- {session.cc ? (
- <CCRow size={18} cc={session.cc} language={language} />
+
+ <div className='flex min-w-0 flex-1 flex-col justify-center gap-2'>
+ <div className='flex flex-wrap items-start justify-between gap-2 sm:gap-4'>
+ {!hideUserDetails ? (
+ <div className='flex min-w-0 items-center gap-2'>
+ <Text size='sm' weight='semibold' truncate>
+ {displayName}
+ </Text>
+ {Boolean(session.isIdentified) && (
+ <Badge
+ label={t('project.identified')}
+ colour='indigo'
+ className='text-[0.625rem] leading-3'
+ />
+ )}
+ {!hideNewReturnBadge && (
+ <Badge
+ label={
+ session.isFirstSession
+ ? t('project.sessionNew')
+ : t('project.sessionReturn')
+ }
+ colour={session.isFirstSession ? 'green' : 'slate'}
+ className='text-[0.625rem] leading-3'
+ />
+ )}
+ </div>
) : (
- t('project.unknownCountry')
+ <div className='flex-1' />
)}
- </span>
- <Separator />
- {session.os || t('project.unknown')}
- <Separator />
- {session.br || t('project.unknown')}
- </p>
- <p className='mt-2 flex text-xs leading-5 text-gray-500 sm:hidden dark:text-gray-300'>
- <span
- className='mr-2 flex items-center'
- title={t('dashboard.pageviews')}
- >
- <FileTextIcon className='mr-1 size-4' /> {session.pageviews}
- </span>
- {session.revenue != null && session.revenue !== 0 ? (
- <span
- className={cx('mr-2 flex items-center', {
- 'text-amber-600 dark:text-amber-500': session.revenue > 0,
- 'text-orange-600 dark:text-orange-500': session.revenue < 0,
- })}
- title={t('dashboard.revenue')}
- >
- {session.revenue < 0 ? '-' : ''}
- {currencySymbol}
- {Math.abs(session.revenue).toFixed(2)}
- </span>
- ) : null}
- {session.customEvents > 0 ? (
- <span
- className='mr-2 flex items-center'
- title={t('dashboard.events')}
- >
- <CursorClickIcon className='mr-1 size-4' />{' '}
- {session.customEvents}
- </span>
- ) : null}
- {session.errors > 0 ? (
- <span
- className='flex items-center text-red-400'
- title={t('dashboard.errors')}
- >
- <WarningIcon className='mr-1 size-4' /> {session.errors}
- </span>
- ) : null}
- </p>
+
+ {/* Mobile Date */}
+ <div className='mt-0.5 flex shrink-0 items-center sm:hidden'>
+ <Text size='xs' colour='secondary' className='text-[11px]'>
+ {dateLineString}
+ </Text>
+ </div>
+ </div>
+
+ <div className='flex items-center justify-between gap-4'>
+ <div className='flex flex-wrap items-center gap-x-3 gap-y-2'>
+ <div className='flex items-center gap-1.5'>
+ <Tooltip
+ text={
+ session.cc
+ ? countries.getName(session.cc, language) ||
+ session.cc
+ : t('project.unknownCountry')
+ }
+ tooltipNode={
+ <div className='flex h-[22px] w-[22px] items-center justify-center rounded bg-gray-100/80 ring-1 ring-gray-200/50 dark:bg-slate-800/80 dark:ring-slate-700/50'>
+ <Flag
+ country={session.cc}
+ size={14}
+ className='rounded-[2px]'
+ aria-hidden='true'
+ />
+ </div>
+ }
+ />
+ <Tooltip
+ text={session.os || t('project.unknown')}
+ tooltipNode={
+ <div className='flex h-[22px] w-[22px] items-center justify-center rounded bg-gray-100/80 ring-1 ring-gray-200/50 dark:bg-slate-800/80 dark:ring-slate-700/50'>
+ <OSIcon
+ os={session.os}
+ theme={theme}
+ className='size-3.5'
+ />
+ </div>
+ }
+ />
+ <Tooltip
+ text={session.br || t('project.unknown')}
+ tooltipNode={
+ <div className='flex h-[22px] w-[22px] items-center justify-center rounded bg-gray-100/80 ring-1 ring-gray-200/50 dark:bg-slate-800/80 dark:ring-slate-700/50'>
+ <BrowserIcon
+ browser={session.br}
+ className='size-3.5'
+ />
+ </div>
+ }
+ />
+ </div>
+
+ <div className='h-3 w-px bg-gray-200 dark:bg-slate-700' />
+
+ <div className='flex items-center gap-3'>
+ <Tooltip
+ text={t('dashboard.pageviews')}
+ tooltipNode={
+ <Text
+ as='span'
+ size='xs'
+ colour='secondary'
+ weight='medium'
+ className='flex items-center gap-1'
+ >
+ <FileTextIcon className='size-3.5' />
+ {session.pageviews}
+ </Text>
+ }
+ />
+
+ {session.customEvents > 0 && (
+ <Tooltip
+ text={t('dashboard.events')}
+ tooltipNode={
+ <Text
+ as='span'
+ size='xs'
+ colour='secondary'
+ weight='medium'
+ className='flex items-center gap-1'
+ >
+ <CursorClickIcon className='size-3.5' />
+ {session.customEvents}
+ </Text>
+ }
+ />
+ )}
+
+ {session.revenue != null && session.revenue !== 0 && (
+ <Tooltip
+ text={t('dashboard.revenue')}
+ tooltipNode={
+ <Text
+ as='span'
+ size='xs'
+ weight='medium'
+ colour='inherit'
+ className={cx('flex items-center gap-1', {
+ 'text-emerald-600 dark:text-emerald-500':
+ session.revenue > 0,
+ 'text-amber-600 dark:text-amber-500':
+ session.revenue < 0,
+ })}
+ >
+ {session.revenue < 0 ? '-' : ''}
+ {currencySymbol}
+ {Math.abs(session.revenue).toFixed(2)}
+ </Text>
+ }
+ />
+ )}
+
+ {session.errors > 0 && (
+ <Tooltip
+ text={t('dashboard.errors')}
+ tooltipNode={
+ <Text
+ as='span'
+ size='xs'
+ colour='error'
+ weight='medium'
+ className='flex items-center gap-1'
+ >
+ <WarningIcon className='size-3.5' />
+ {session.errors}
+ </Text>
+ }
+ />
+ )}
+ </div>
+ </div>
+ </div>
+ </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='flex items-center gap-x-3 text-sm leading-6 text-gray-900 dark:text-gray-50'>
- <span
- className='flex items-center'
- title={t('dashboard.xPageviews', { x: session.pageviews })}
- >
- <FileTextIcon className='mr-1 size-5' /> {session.pageviews}
- </span>
- {session.revenue != null && session.revenue !== 0 ? (
- <span
- className={cx('flex items-center', {
- 'text-amber-600 dark:text-amber-500': session.revenue > 0,
- 'text-orange-600 dark:text-orange-500': session.revenue < 0,
- })}
- title={`${session.revenue < 0 ? '-' : ''}${currencySymbol}${Math.abs(session.revenue).toFixed(2)}`}
- >
- {session.revenue < 0 ? '-' : ''}
- {currencySymbol}
- {Math.abs(session.revenue).toFixed(2)}
- </span>
- ) : null}
- {session.customEvents > 0 ? (
- <span
- className='flex items-center'
- title={t('dashboard.xCustomEvents', {
- x: session.customEvents,
- })}
- >
- <CursorClickIcon className='mr-1 size-5' />{' '}
- {session.customEvents}
- </span>
- ) : null}
- {session.errors > 0 ? (
- <span
- className='flex items-center text-red-500'
- title={t('dashboard.xErrors', { x: session.errors })}
- >
- <WarningIcon className='mr-1 size-5' /> {session.errors}
- </span>
- ) : null}
+
+ <div className='hidden shrink-0 items-center gap-x-3 sm:flex'>
+ <div className='flex flex-col items-end'>
+ <Text as='p' size='xs' colour='secondary' className='text-[11px]'>
+ {dateLineString}
+ </Text>
</div>
- <p className='mt-1 flex items-center text-xs leading-5 text-gray-500 dark:text-gray-400'>
- <CalendarDotsIcon className='mr-1 size-3' />
- {dateLineString}
- </p>
+ <CaretRightIcon
+ className='size-4 text-gray-400'
+ aria-hidden='true'
+ />
+ </div>
+ <div className='flex shrink-0 items-center sm:hidden'>
+ <CaretRightIcon
+ className='size-4 text-gray-400'
+ aria-hidden='true'
+ />
</div>
- <CaretRightIcon
- className='h-5 w-5 flex-none text-gray-400'
- aria-hidden='true'
- />
</div>
- </li>
- </Link>
+ </Link>
+ </li>
)
}
@@ -363,7 +481,7 @@ export const Sessions: React.FC<SessionsProps> = ({
}
>
{() => (
- <ul>
+ <ul className='flex flex-col'>
{_map(sessions, (session) => (
<Session
key={session.psid}