📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
feature: info about live visitors
kruzhambus01785fdbe1af
diff --git a/src/api/index.js b/src/api/index.jsindex d07e78b03..7096cd439 100644--- a/src/api/index.js+++ b/src/api/index.js@@ -435,3 +435,14 @@ export const setTheme = (theme) =>? error.response.data: error.response.data.message})++export const getLiveVisitorsInfo = (pid) =>+ api+ .get(`log/liveVisitors?pid=${pid}`)+ .then((response) => response.data)+ .catch((error) => {+ debug('%s', error)+ throw _isEmpty(error.response.data?.message)+ ? error.response.data+ : error.response.data.message+ })diff --git a/src/pages/Project/View/Panels.jsx b/src/pages/Project/View/Panels.jsxindex 3063854d0..80a32d3fb 100644--- a/src/pages/Project/View/Panels.jsx+++ b/src/pages/Project/View/Panels.jsx@@ -26,6 +26,7 @@ import Progress from 'ui/Progress'import PulsatingCircle from 'ui/icons/PulsatingCircle'import Modal from 'ui/Modal'import Chart from 'ui/Chart'+import LiveVisitorsDropdown from './components/LiveVisitorsDropdown'import InteractiveMap from './components/InteractiveMap'import { iconClassName } from './ViewProject.helpers'@@ -144,7 +145,7 @@ PanelContainer.defaultProps = {// First tab with statsconst Overview = ({- overall, chartData, activePeriod, t, live, sessionDurationAVG,+ overall, chartData, activePeriod, t, live, sessionDurationAVG, projectId,}) => {const pageviewsDidGrowUp = overall.percChange >= 0const uniqueDidGrowUp = overall.percChangeUnique >= 0@@ -164,9 +165,7 @@ const Overview = ({{t('dashboard.liveVisitors')}:</div>- <p className='h-5 mr-2 text-gray-900 dark:text-gray-50 text-xl'>- {live}- </p>+ <LiveVisitorsDropdown projectId={projectId} live={live} /></div>{!_isEmpty(chartData) && (<>diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsxindex 4a965f36c..e4b8d5fb4 100644--- a/src/pages/Project/View/ViewProject.jsx+++ b/src/pages/Project/View/ViewProject.jsx@@ -1002,6 +1002,7 @@ const ViewProject = ({activePeriod={activePeriod}sessionDurationAVG={sessionDurationAVG}live={project.live}+ projectId={id}/>)}{_map(panelsData.types, (type) => {diff --git a/src/pages/Project/View/components/LiveVisitorsDropdown.jsx b/src/pages/Project/View/components/LiveVisitorsDropdown.jsxnew file mode 100644index 000000000..4ce6555cd--- /dev/null+++ b/src/pages/Project/View/components/LiveVisitorsDropdown.jsx@@ -0,0 +1,72 @@+import React, { useState, useEffect } from 'react'+import _map from 'lodash/map'+import { getLiveVisitorsInfo } from 'api'+import {+ ChevronDownIcon, ChevronUpIcon, XMarkIcon,+} from '@heroicons/react/24/outline'+import Flag from 'react-flagkit'++const LiveVisitorsDropdown = ({ live, projectId }) => {+ const [show, setShow] = useState(false)+ const [liveInfo, setLiveInfo] = useState([])+ const [loading, setLoading] = useState(true)++ const getLiveVisitors = async () => {+ await getLiveVisitorsInfo(projectId)+ .then((res) => {+ setLiveInfo(res)+ })+ .catch((err) => {+ console.log(err)+ })+ .finally(() => {+ setLoading(false)+ })+ }++ useEffect(() => {+ getLiveVisitors()+ }, [])++ return (+ <>+ <p className='h-5 mr-2 text-gray-900 dark:text-gray-50 text-xl cursor-pointer' onClick={() => setShow(!show)}>+ {live}+ {' '}+ {show ? <ChevronUpIcon className='inline w-5 h-5' /> : <ChevronDownIcon className='inline w-5 h-5' />}+ </p>+ {show && (+ <div className='absolute z-10 mt-2 right-0 top-20 text-gray-900 bg-white border border-gray-200 rounded-md shadow-lg dark:bg-gray-800 dark:border-gray-700 min-w-[150px] max-h-[200px] overflow-scroll'>+ <div className='flex flex-col w-full p-2'>+ <p className='text-sm font-semibold text-gray-900 dark:text-gray-50'>Live Visitors</p>+ {loading ? (+ <p className='text-sm text-gray-900 dark:text-gray-50'>Loading...</p>+ ) : (+ _map(liveInfo, ({+ dv, br, os, cc,+ }) => (+ <div className='flex flex-row items-center justify-between w-full p-2 mt-2 text-sm text-gray-900 bg-gray-100 rounded-md dark:text-gray-50 dark:bg-gray-700'>+ <div className='flex flex-row items-center'>+ <p className='mr-2'>{dv}</p>+ <p className='mr-2'>{br}</p>+ <p className='mr-2'>{os}</p>+ <Flag+ className='rounded-sm mr-2'+ country={cc}+ size={21}+ alt=''+ />+ </div>+ <p className='text-xs font-semibold text-green-500'>Live</p>+ </div>+ ))+ )}+ </div>+ <XMarkIcon className='absolute top-2 right-2 w-5 h-5 text-gray-900 cursor-pointer dark:text-gray-50' onClick={() => setShow(!show)} />+ </div>+ )}+ </>+ )+}++export default LiveVisitorsDropdown