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!

Link online users to sessions

Blue Mousec5c70822e5e1
diff --git a/web/app/api/index.ts b/web/app/api/index.ts
index f0fdccc60..5d69b00e3 100644
--- a/web/app/api/index.ts
+++ b/web/app/api/index.ts
@@ -912,6 +912,7 @@ export const getInstalledExtensions = (limit = 100, offset = 0) =>
})
export interface IGetLiveVisitorsInfo {
+ psid: string
dv: string
br: string
os: string
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 8f39f6e18..7981debb8 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -3908,9 +3908,11 @@ const ViewProject = ({
</h2>
{activeTab !== PROJECT_TABS.funnels && (
<LiveVisitorsDropdown
- projectId={project.id}
+ onSessionSelect={(psid) => {
+ setActiveTab(PROJECT_TABS.sessions)
+ setActivePSID(psid)
+ }}
live={liveStats[id]}
- projectPassword={projectPassword}
/>
)}
</div>
diff --git a/web/app/pages/Project/View/components/CountryDropdown.tsx b/web/app/pages/Project/View/components/CountryDropdown.tsx
index e790f4ebe..bc349c714 100644
--- a/web/app/pages/Project/View/components/CountryDropdown.tsx
+++ b/web/app/pages/Project/View/components/CountryDropdown.tsx
@@ -1,7 +1,6 @@
import React, { useState } from 'react'
import _map from 'lodash/map'
import { useTranslation } from 'react-i18next'
-// @ts-ignore
import OutsideClickHandler from 'react-outside-click-handler'
import { ChevronDownIcon, ChevronUpIcon, XMarkIcon } from '@heroicons/react/24/outline'
diff --git a/web/app/pages/Project/View/components/CustomEventsDropdown.tsx b/web/app/pages/Project/View/components/CustomEventsDropdown.tsx
index b5c1695d6..c4677ef7c 100644
--- a/web/app/pages/Project/View/components/CustomEventsDropdown.tsx
+++ b/web/app/pages/Project/View/components/CustomEventsDropdown.tsx
@@ -1,7 +1,6 @@
import React, { useState } from 'react'
import _map from 'lodash/map'
import { useTranslation } from 'react-i18next'
-// @ts-ignore
import OutsideClickHandler from 'react-outside-click-handler'
import { ChevronDownIcon, ChevronUpIcon, XMarkIcon } from '@heroicons/react/24/outline'
diff --git a/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx b/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx
index 2ca72b599..9f3925e11 100644
--- a/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx
+++ b/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx
@@ -1,25 +1,26 @@
import React, { useState, useEffect } from 'react'
import _map from 'lodash/map'
import { useTranslation } from 'react-i18next'
-// @ts-ignore
import OutsideClickHandler from 'react-outside-click-handler'
import { ChevronDownIcon, ChevronUpIcon, XMarkIcon } from '@heroicons/react/24/outline'
import { getLiveVisitorsInfo, IGetLiveVisitorsInfo } from 'api'
import PulsatingCircle from 'ui/icons/PulsatingCircle'
import Flag from 'ui/Flag'
+import { useViewProjectContext } from '../ViewProject'
+import { Link } from '@remix-run/react'
interface ILiveVisitorsDropdown {
live: number | string
- projectId: string
- projectPassword?: string
+ onSessionSelect: (psid: string) => void
}
-const LiveVisitorsDropdown = ({ live, projectId, projectPassword = '' }: ILiveVisitorsDropdown): JSX.Element => {
+const LiveVisitorsDropdown = ({ live, onSessionSelect }: ILiveVisitorsDropdown): JSX.Element => {
+ const { projectId, projectPassword } = useViewProjectContext()
const { t } = useTranslation()
- const [show, setShow] = useState<boolean>(false)
+ const [show, setShow] = useState(false)
+ const [loading, setLoading] = useState(true)
const [liveInfo, setLiveInfo] = useState<IGetLiveVisitorsInfo[]>([])
- const [loading, setLoading] = useState<boolean>(true)
const getLiveVisitors = async () => {
try {
@@ -40,7 +41,7 @@ const LiveVisitorsDropdown = ({ live, projectId, projectPassword = '' }: ILiveVi
return (
<OutsideClickHandler onOutsideClick={() => setShow(false)}>
- <p
+ <div
className='relative flex h-5 cursor-pointer items-center text-base text-gray-900 dark:text-gray-50'
onClick={() => setShow(!show)}
>
@@ -49,9 +50,9 @@ const LiveVisitorsDropdown = ({ live, projectId, projectPassword = '' }: ILiveVi
amount: live || 0,
})}{' '}
{show ? <ChevronUpIcon className='ml-1 inline h-4 w-4' /> : <ChevronDownIcon className='ml-1 inline h-4 w-4' />}
- {show && (
+ {show ? (
<div
- className={`scrollbar-thin absolute right-0 top-3 z-10 mt-2 max-h-[200px] overflow-y-auto rounded-md border border-gray-200 bg-white text-gray-900 shadow-lg dark:border-slate-700/50 dark:bg-slate-900 ${
+ className={`scrollbar-thin absolute right-0 top-3 z-10 mt-2 max-h-[200px] cursor-auto overflow-y-auto rounded-md border border-gray-200 bg-white text-gray-900 shadow-lg dark:border-slate-700/50 dark:bg-slate-900 ${
liveInfo.length === 0 ? 'min-w-[200px]' : 'min-w-max'
}`}
>
@@ -60,25 +61,43 @@ const LiveVisitorsDropdown = ({ live, projectId, projectPassword = '' }: ILiveVi
{loading ? (
<p className='text-sm text-gray-900 dark:text-gray-50'>{t('common.loading')}</p>
) : (
- <table className='border-separate border-spacing-y-2'>
- <tbody>
- {_map(liveInfo, ({ dv, br, os, cc }, index) => (
- <tr
- key={`${dv}${br}${os}${cc}${index}`}
- className='rounded-md text-sm text-gray-900 dark:text-gray-50'
- >
- <td className='rounded-l-lg bg-gray-100 pr-2 dark:bg-slate-800'>
- <Flag className='m-2 rounded-sm' country={cc} size={21} alt='' aria-hidden='true' />
- </td>
- <td className='bg-gray-100 pr-2 dark:bg-slate-800'>{os}</td>
- <td className='bg-gray-100 pr-2 dark:bg-slate-800'>{br}</td>
- <td className='rounded-r-lg bg-gray-100 pr-2 dark:bg-slate-800'>
- <p className='capitalize'>{dv}</p>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
+ <div className='table w-full border-separate border-spacing-y-2'>
+ <div className='table-row-group'>
+ {_map(liveInfo, ({ psid, dv, br, os, cc }) => {
+ const psidUrl = new URL(window.location.href)
+ psidUrl.searchParams.set('psid', psid)
+ const stringifiedUrl = psidUrl.toString()
+
+ return (
+ <Link
+ key={psid}
+ className='group table-row cursor-pointer text-sm text-gray-900 dark:text-gray-50'
+ onClick={(e: React.MouseEvent<HTMLAnchorElement>) => {
+ e.preventDefault()
+ e.stopPropagation()
+ window.history.pushState({}, '', stringifiedUrl)
+
+ onSessionSelect(psid)
+ }}
+ to={stringifiedUrl}
+ >
+ <div className='table-cell rounded-l-lg bg-gray-100 pr-2 align-middle group-hover:bg-gray-200 dark:bg-slate-800 dark:group-hover:bg-slate-700'>
+ <Flag className='m-2 rounded-sm' country={cc} size={21} alt='' aria-hidden='true' />
+ </div>
+ <div className='table-cell bg-gray-100 pr-2 align-middle group-hover:bg-gray-200 dark:bg-slate-800 dark:group-hover:bg-slate-700'>
+ {os}
+ </div>
+ <div className='table-cell bg-gray-100 pr-2 align-middle group-hover:bg-gray-200 dark:bg-slate-800 dark:group-hover:bg-slate-700'>
+ {br}
+ </div>
+ <div className='table-cell rounded-r-lg bg-gray-100 pr-2 align-middle group-hover:bg-gray-200 dark:bg-slate-800 dark:group-hover:bg-slate-700'>
+ <p className='capitalize'>{dv}</p>
+ </div>
+ </Link>
+ )
+ })}
+ </div>
+ </div>
)}
</div>
<XMarkIcon
@@ -86,8 +105,8 @@ const LiveVisitorsDropdown = ({ live, projectId, projectPassword = '' }: ILiveVi
onClick={() => setShow(!show)}
/>
</div>
- )}
- </p>
+ ) : null}
+ </div>
</OutsideClickHandler>
)
}
diff --git a/web/app/pages/Project/View/components/MetricCards.tsx b/web/app/pages/Project/View/components/MetricCards.tsx
index 9244a2053..1fdb71299 100644
--- a/web/app/pages/Project/View/components/MetricCards.tsx
+++ b/web/app/pages/Project/View/components/MetricCards.tsx
@@ -1,7 +1,6 @@
import React, { memo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import cx from 'clsx'
-// @ts-ignore
import OutsideClickHandler from 'react-outside-click-handler'
import _round from 'lodash/round'
import _isEmpty from 'lodash/isEmpty'
diff --git a/web/app/pages/Project/View/components/Pageflow.tsx b/web/app/pages/Project/View/components/Pageflow.tsx
index c75205324..0f271f1c1 100644
--- a/web/app/pages/Project/View/components/Pageflow.tsx
+++ b/web/app/pages/Project/View/components/Pageflow.tsx
@@ -30,8 +30,8 @@ const TransValue = ({ metadata, children }: { metadata?: IMetadata[]; children:
<p className='font-medium'>{children}</p>
{metadata ? (
<ul className='mt-1'>
- {_map(metadata, ({ key, value }) => (
- <KeyValue key={key} evKey={key} evValue={value} />
+ {_map(metadata, ({ key, value }, index) => (
+ <KeyValue key={`${key}${value}${index}`} evKey={key} evValue={value} />
))}
</ul>
) : null}
diff --git a/web/app/pages/Project/View/components/UTMDropdown.tsx b/web/app/pages/Project/View/components/UTMDropdown.tsx
index 298aa07cc..64434d3d9 100644
--- a/web/app/pages/Project/View/components/UTMDropdown.tsx
+++ b/web/app/pages/Project/View/components/UTMDropdown.tsx
@@ -1,7 +1,6 @@
import React, { useState } from 'react'
import _map from 'lodash/map'
import { useTranslation } from 'react-i18next'
-// @ts-ignore
import OutsideClickHandler from 'react-outside-click-handler'
import { ChevronDownIcon, ChevronUpIcon, XMarkIcon } from '@heroicons/react/24/outline'
diff --git a/web/package.json b/web/package.json
index b9e567a9c..4ce6b599c 100644
--- a/web/package.json
+++ b/web/package.json
@@ -144,6 +144,7 @@
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@types/react-flatpickr": "^3.8.11",
+ "@types/react-outside-click-handler": "^1.3.4",
"@typescript-eslint/parser": "^8.8.0",
"@typescript-eslint/typescript-estree": "^8.8.0",
"autoprefixer": "^10.4.20",