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!

Native 'Go back' support for sessions

Blue Mousec5fd485f69d3
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index a91e77552..13587c5e6 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -380,7 +380,9 @@ const ViewProject = () => {
const [sessionsLoading, setSessionsLoading] = useState<boolean | null>(null) // null - not loaded, true - loading, false - loaded
const [activeSession, setActiveSession] = useState<any>(null)
const [sessionLoading, setSessionLoading] = useState(false)
- const [activePSID, setActivePSID] = useState<string | null>(null)
+ const activePSID = useMemo(() => {
+ return searchParams.get('psid')
+ }, [searchParams])
// errors
const [errorsSkip, setErrorsSkip] = useState(0)
@@ -1426,14 +1428,6 @@ const ViewProject = () => {
setActiveEID(eid)
}
}
-
- if (tab === PROJECT_TABS.sessions) {
- const psid = searchParams.get('psid') as string
-
- if (psid) {
- setActivePSID(psid)
- }
- }
}, [authLoading])
useEffect(() => {
@@ -2946,7 +2940,9 @@ const ViewProject = () => {
<LiveVisitorsDropdown
onSessionSelect={(psid) => {
setDashboardTab(PROJECT_TABS.sessions)
- setActivePSID(psid)
+ const newSearchParams = new URLSearchParams(searchParams.toString())
+ newSearchParams.set('psid', psid)
+ setSearchParams(newSearchParams)
}}
live={liveVisitors}
/>
@@ -3576,13 +3572,7 @@ const ViewProject = () => {
resetActiveTabFilters={resetActiveTabFilters}
/>
) : null}
- <Sessions
- sessions={sessions}
- onClick={(psid) => {
- setActivePSID(psid)
- }}
- timeFormat={timeFormat}
- />
+ <Sessions sessions={sessions} timeFormat={timeFormat} />
{canLoadMoreSessions ? (
<button
type='button'
@@ -3608,9 +3598,9 @@ const ViewProject = () => {
type='button'
onClick={() => {
setActiveSession(null)
- setActivePSID(null)
- searchParams.delete('psid')
- setSearchParams(searchParams)
+ const newSearchParams = new URLSearchParams(searchParams.toString())
+ newSearchParams.delete('psid')
+ setSearchParams(newSearchParams)
}}
className='mx-auto mt-2 mb-4 flex items-center font-mono text-sm text-gray-900 underline decoration-dashed hover:decoration-solid lg:mx-0 dark:text-gray-100'
>
diff --git a/web/app/pages/Project/View/components/Sessions.tsx b/web/app/pages/Project/View/components/Sessions.tsx
index 1306a7ab0..10c5b6211 100644
--- a/web/app/pages/Project/View/components/Sessions.tsx
+++ b/web/app/pages/Project/View/components/Sessions.tsx
@@ -18,13 +18,11 @@ dayjs.extend(duration)
interface SessionsProps {
sessions: SessionType[]
- onClick: (psid: string) => void
timeFormat: '12-hour' | '24-hour'
}
interface SessionProps {
session: SessionType
- onClick: (psid: string) => void
timeFormat: '12-hour' | '24-hour'
}
@@ -34,7 +32,7 @@ const Separator = () => (
</svg>
)
-const Session = ({ session, onClick, timeFormat }: SessionProps) => {
+const Session = ({ session, timeFormat }: SessionProps) => {
const {
t,
i18n: { language },
@@ -101,15 +99,7 @@ const Session = ({ session, onClick, timeFormat }: SessionProps) => {
session.pageviews === 1 ? t('dashboard.onePageview') : t('dashboard.xPageviews', { x: session.pageviews })
return (
- <Link
- onClick={(e: React.MouseEvent<HTMLAnchorElement>) => {
- e.preventDefault()
- e.stopPropagation()
- window.history.pushState({}, '', stringifiedUrl)
- onClick(session.psid)
- }}
- to={stringifiedUrl}
- >
+ <Link to={stringifiedUrl}>
<li className='relative mb-4 flex cursor-pointer justify-between gap-x-6 rounded-lg bg-gray-200/60 px-4 py-4 font-mono hover:bg-gray-200 sm:px-6 dark:bg-[#162032] dark:hover:bg-slate-800'>
<div className='flex min-w-0 gap-x-4'>
<div className='min-w-0 flex-auto'>
@@ -147,7 +137,7 @@ const Session = ({ session, onClick, timeFormat }: SessionProps) => {
)
}
-export const Sessions: React.FC<SessionsProps> = ({ sessions, onClick, timeFormat }) => {
+export const Sessions: React.FC<SessionsProps> = ({ sessions, timeFormat }) => {
return (
<ClientOnly
fallback={
@@ -159,7 +149,7 @@ export const Sessions: React.FC<SessionsProps> = ({ sessions, onClick, timeForma
{() => (
<ul className='mt-4'>
{_map(sessions, (session) => (
- <Session key={session.psid} session={session} onClick={onClick} timeFormat={timeFormat} />
+ <Session key={session.psid} session={session} timeFormat={timeFormat} />
))}
</ul>
)}