π 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
added an indicator that shows how many visitors Project has on the browser tab
Blue Mouse3f46ee79bb26
diff --git a/public/locales/en.json b/public/locales/en.jsonindex e236c4eda..70a6a7c81 100644--- a/public/locales/en.json+++ b/public/locales/en.json@@ -449,7 +449,9 @@"regenerateSecretKey": "Regenerate secret key","regenerateSecretKeyTitle": "Regenerate secret key?","regenerateSecretKeyMessage": "Are you sure you want to regenerate your secret key?\nAll the existing CAPTCHA widgets will stop working and you will need to update them with the new secret key.",- "captchaSecretKeyHint": "This is your secret key, it is used to verify the CAPTCHA response on your server. Keep it secret and do not share it with anyone."+ "captchaSecretKeyHint": "This is your secret key, it is used to verify the CAPTCHA response on your server. Keep it secret and do not share it with anyone.",+ "showVisitorsInTitle": "Show live visitors in the page title",+ "uiSettings": "UI Settings"},"dashboard": {"newProject": "New project",diff --git a/src/api/index.ts b/src/api/index.tsindex fcad268dc..0f0b743ff 100644--- a/src/api/index.ts+++ b/src/api/index.ts@@ -166,6 +166,18 @@ export const changeUserDetails = (data: IUser) =>throw new Error(errorsArray)})+export const setShowLiveVisitorsInTitle = (show: boolean) =>+ api+ .put('/user/live-visitors', { show })+ .then((response): Partial<IUser> => response.data)+ .catch((error) => {+ const errorsArray = error.response.data.message+ if (_isArray(errorsArray)) {+ throw errorsArray+ }+ throw new Error(errorsArray)+ })+export const forgotPassword = (email: {email: string}) =>diff --git a/src/components/__test__/Header.test.tsx b/src/components/__test__/Header.test.tsxindex 6e65af9e7..697e68881 100644--- a/src/components/__test__/Header.test.tsx+++ b/src/components/__test__/Header.test.tsx@@ -52,6 +52,7 @@ describe('Header', () => {registeredWithGithub: false,tierCurrency: 'USD',maxEventsCount: 5000000,+ showLiveVisitorsInTitle: false,}beforeEach(() => {diff --git a/src/pages/Changelog/index.tsx b/src/pages/Changelog/index.tsxindex 43442bce9..5ce0d9be0 100644--- a/src/pages/Changelog/index.tsx+++ b/src/pages/Changelog/index.tsx@@ -16,6 +16,13 @@ const INTEGRATIONS_LINK = `${routes.user_settings}#integrations`// Date format: YYYY-MM-DDconst changelog = [+ {+ date: '2023-05-28',+ changes: [+ 'Added an indicator that shows how many live visitors your Project has at the moment on the browser tab.',+ 'Updated Swetrix logo.',+ ],+ },{date: '2023-05-27',changes: [diff --git a/src/pages/Project/View/ViewProject.tsx b/src/pages/Project/View/ViewProject.tsxindex ec381829f..980fae956 100644--- a/src/pages/Project/View/ViewProject.tsx+++ b/src/pages/Project/View/ViewProject.tsx@@ -298,6 +298,8 @@ const ViewProject = ({const { name } = project+ const pageTitle = user?.showLiveVisitorsInTitle ? `π ${liveStats[id]} - ${name}` : name+const sharedRoles = useMemo(() => _find(user.sharedProjects, p => p.project.id === id)?.role || {}, [user, id])const chartMetrics = useMemo(() => {@@ -1583,7 +1585,7 @@ const ViewProject = ({if (!isLoading) {return (- <Title title={name}>+ <Title title={pageTitle}><EventsRunningOutBanner /><div ref={ref} className='bg-gray-50 dark:bg-slate-900'><divdiff --git a/src/pages/UserSettings/UserSettings.container.tsx b/src/pages/UserSettings/UserSettings.container.tsxindex 42d31c051..8ddf26374 100644--- a/src/pages/UserSettings/UserSettings.container.tsx+++ b/src/pages/UserSettings/UserSettings.container.tsx@@ -141,6 +141,9 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({),)},+ updateShowLiveVisitorsInTitle: (show: boolean, callback: (isSuccess: boolean) => void) => {+ dispatch(sagaActions.updateShowLiveVisitorsInTitle(show, callback))+ },})export default connect(mapStateToProps, mapDispatchToProps)(UserSettings)diff --git a/src/pages/UserSettings/UserSettings.tsx b/src/pages/UserSettings/UserSettings.tsxindex df4e21b0f..d27594a56 100644--- a/src/pages/UserSettings/UserSettings.tsx+++ b/src/pages/UserSettings/UserSettings.tsx@@ -30,6 +30,7 @@ import Button from 'ui/Button'import Modal from 'ui/Modal'import Beta from 'ui/Beta'import Select from 'ui/Select'+import Checkbox from 'ui/Checkbox'import PaidFeature from 'modals/PaidFeature'import TimezonePicker from 'ui/TimezonePicker'import { isValidEmail, isValidPassword, MIN_PASSWORD_CHARS } from 'utils/validator'@@ -71,6 +72,7 @@ interface IProps {linkSSO: (t: (key: string) => string, callback: (e: any) => void, provider: string) => void,unlinkSSO: (t: (key: string) => string, callback: (e: any) => void, provider: string) => void,theme: string,+ updateShowLiveVisitorsInTitle: (show: boolean, callback: (isSuccess: boolean) => void) => void,}interface IForm extends Partial<IUser> {@@ -84,7 +86,7 @@ const UserSettings = ({setProjectsShareData, userSharedUpdate, sharedProjectError, updateUserData,genericError, onGDPRExportFailed, updateProfileFailed, updateUserProfileAsync,accountUpdated, setAPIKey, user, dontRemember, isPaidTierUsed, // setThemeType, themeType,- linkSSO, unlinkSSO, theme,+ linkSSO, unlinkSSO, theme, updateShowLiveVisitorsInTitle,}: IProps): JSX.Element => {const history = useHistory()const { t }: {@@ -115,6 +117,7 @@ const UserSettings = ({const [copied, setCopied] = useState<boolean>(false)const translatedFrequencies: string[] = _map(reportFrequencies, (key) => t(`profileSettings.${key}`)) // useMemo(_map(reportFrequencies, (key) => t(`profileSettings.${key}`)), [t])const translatedTimeFormat: string[] = _map(TimeFormat, (key) => t(`profileSettings.${key}`)) // useMemo(_map(TimeFormat, (key) => t(`profileSettings.${key}`)), [t])+ const [settingUpdating, setSettingUpdating] = useState<boolean>(false)const copyTimerRef = useRef(null)@@ -205,6 +208,26 @@ const UserSettings = ({}}+ const handleShowLiveVisitorsSave = (e: React.ChangeEvent<HTMLInputElement>) => {+ if (settingUpdating) {+ return+ }++ const { checked } = e.target++ setSettingUpdating(true)+ updateShowLiveVisitorsInTitle(checked, (isSuccess: boolean) => {+ setSettingUpdating(false)++ if (isSuccess) {+ accountUpdated(t('profileSettings.updated'))+ return+ }++ genericError(t('apiNotifications.somethingWentWrong'))+ })+ }+const handleIntegrationSave = (data: any, callback = () => { }) => {setBeenSubmitted(true)@@ -466,8 +489,27 @@ const UserSettings = ({<Button className='mt-4' onClick={handleReportSave} primary large>{t('common.save')}</Button>- <hr className='mt-5 border-gray-200 dark:border-gray-600' />+ </>+ )}+ {/* UI Settings */}+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />+ <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>+ {t('profileSettings.uiSettings')}+ </h3>+ <Checkbox+ checked={user.showLiveVisitorsInTitle}+ onChange={handleShowLiveVisitorsSave}+ disabled={settingUpdating}+ name='active'+ id='active'+ className='mt-4'+ label={t('profileSettings.showVisitorsInTitle')}+ />++ {!isSelfhosted && (+ <>+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />{/* Integrations setup */}<h3 id='integrations' className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>{t('profileSettings.integrations')}diff --git a/src/redux/models/IUser.ts b/src/redux/models/IUser.tsindex cc3639c28..6944dfdcc 100644--- a/src/redux/models/IUser.ts+++ b/src/redux/models/IUser.ts@@ -35,4 +35,5 @@ export interface IUser {registeredWithGithub: booleanmaxEventsCount: numbertierCurrency: 'USD' | 'EUR' | 'GBP' | null+ showLiveVisitorsInTitle: boolean}diff --git a/src/redux/reducers/auth.ts b/src/redux/reducers/auth.tsindex 9d0db4e68..c1253377b 100644--- a/src/redux/reducers/auth.ts+++ b/src/redux/reducers/auth.ts@@ -50,6 +50,9 @@ const authSlice = createSlice({updateUserProfileSuccess: (state, { payload }: PayloadAction<IUser>) => {state.user = payload},+ partiallyOverwriteUser: (state, { payload }: PayloadAction<Partial<IUser>>) => {+ state.user = { ...state.user, ...payload }+ },logout: (state) => {state.user = {} as IUserstate.authenticated = falsediff --git a/src/redux/sagas/actions/index.ts b/src/redux/sagas/actions/index.tsindex 2b5fbe3ac..f4899a09b 100644--- a/src/redux/sagas/actions/index.ts+++ b/src/redux/sagas/actions/index.ts@@ -130,6 +130,13 @@ const logout = (basedOn401Error: boolean) => {}}+const updateShowLiveVisitorsInTitle = (show: boolean, callback: (isSuccess: boolean) => void) => ({+ type: types.UPDATE_SHOW_LIVE_VISITORS_IN_TITLE,+ payload: {+ show, callback,+ },+})+const sagaActions = {loadProjects,loadSharedProjects,@@ -148,6 +155,7 @@ const sagaActions = {unlinkSSO,loadMetainfo,loadUsageinfo,+ updateShowLiveVisitorsInTitle,}export default sagaActionsdiff --git a/src/redux/sagas/actions/types.ts b/src/redux/sagas/actions/types.tsindex 96faa5091..d0844c159 100644--- a/src/redux/sagas/actions/types.ts+++ b/src/redux/sagas/actions/types.ts@@ -9,6 +9,7 @@ const sagaTypes = Object.freeze({SIGNUP_ASYNC: 'SIGNUP_ASYNC',EMAIL_VERIFY_ASYNC: 'EMAIL_VERIFY_ASYNC',UPDATE_USER_PROFILE_ASYNC: 'UPDATE_USER_PROFILE_ASYNC',+ UPDATE_SHOW_LIVE_VISITORS_IN_TITLE: 'UPDATE_SHOW_LIVE_VISITORS_IN_TITLE',DELETE_ACCOUNT_ASYNC: 'DELETE_ACCOUNT_ASYNC',SHARE_VERIFY_ASYNC: 'SHARE_VERIFY_ASYNC',LOGOUT: 'LOGOUT',diff --git a/src/redux/sagas/auth/watchers/index.ts b/src/redux/sagas/auth/watchers/index.tsindex 863adf079..4694e9794 100644--- a/src/redux/sagas/auth/watchers/index.ts+++ b/src/redux/sagas/auth/watchers/index.ts@@ -1,13 +1,14 @@import { takeLatest, all, call } from 'redux-saga/effects'-import signIn from 'redux/sagas/auth/workers/signin'-import signUp from 'redux/sagas/auth/workers/signup'-import logout from 'redux/sagas/auth/workers/logout'-import verifyEmail from 'redux/sagas/auth/workers/verifyEmail'-import updateUserProfile from 'redux/sagas/auth/workers/updateUserProfile'-import deleteUserAccount from 'redux/sagas/auth/workers/deleteUserAccount'-import ssoAuth from 'redux/sagas/auth/workers/sso_auth'-import ssoLink from 'redux/sagas/auth/workers/sso_link'-import ssoUnlink from 'redux/sagas/auth/workers/sso_unlink'+import signIn from '../workers/signin'+import signUp from '../workers/signup'+import logout from '../workers/logout'+import verifyEmail from '../workers/verifyEmail'+import updateUserProfile from '../workers/updateUserProfile'+import deleteUserAccount from '../workers/deleteUserAccount'+import ssoAuth from '../workers/sso_auth'+import ssoLink from '../workers/sso_link'+import ssoUnlink from '../workers/sso_unlink'+import updateShowLiveVisitorsInTitle from '../workers/update_show_live_visitors_in_title'import sagaTypes from '../../actions/types'function* watchLogin() {@@ -55,11 +56,16 @@ function* watchUnlinkSSO() {yield takeLatest(sagaTypes.UNLINK_SSO, ssoUnlink)}+function* watchUpdateShowLiveVisitorsInTitle() {+ // @ts-ignore+ yield takeLatest(sagaTypes.UPDATE_SHOW_LIVE_VISITORS_IN_TITLE, updateShowLiveVisitorsInTitle)+}+export default function* watchAuth() {yield all([call(watchLogin), call(watchSignup), call(watchVerifyEmail),call(watchUpdateUserProfile), call(watchDeleteUserProfile),call(watchLogout), call(watchAuthSSO), call(watchLinkSSO),- call(watchUnlinkSSO),+ call(watchUnlinkSSO), call(watchUpdateShowLiveVisitorsInTitle),])}diff --git a/src/redux/sagas/auth/workers/update_show_live_visitors_in_title.ts b/src/redux/sagas/auth/workers/update_show_live_visitors_in_title.tsnew file mode 100644index 000000000..7d27ca0cf--- /dev/null+++ b/src/redux/sagas/auth/workers/update_show_live_visitors_in_title.ts@@ -0,0 +1,32 @@+import { call, put } from 'redux-saga/effects'++import { authActions } from 'redux/reducers/auth'+import { errorsActions } from 'redux/reducers/errors'+import { setShowLiveVisitorsInTitle } from 'api'+import { IUser } from '../../../models/IUser'++interface IPayload {+ show: boolean+ callback: (isSuccess: boolean) => void+}++export default function* updateShowLiveVisitorsInTitle({ payload: { show, callback } }: {+ payload: IPayload+}) {+ let isSuccess = false++ try {+ const user: Partial<IUser> = yield call(setShowLiveVisitorsInTitle, show)++ yield put(authActions.partiallyOverwriteUser(user))+ isSuccess = true+ } catch (e: unknown) {+ const error = e as { message: string } | string[] | string+ yield put(errorsActions.updateUserProfileFailed({+ // @ts-ignore+ message: error?.message || (typeof error === 'string' ? error : error[0]),+ }))+ } finally {+ callback(isSuccess)+ }+}