📈 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
some fixes and improvements
Blue Mouse2b603956e3db
diff --git a/src/api/index.js b/src/api/index.jsindex a9e47bc74..3e3e5d337 100644--- a/src/api/index.js+++ b/src/api/index.js@@ -256,3 +256,14 @@ export const getLiveVisitors = (pids) =>? error.response.data: error.response.data.message})++export const getGeneralStats = () =>+ api+ .get('log/generalStats')+ .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/components/Header/index.jsx b/src/components/Header/index.jsxindex aa5fb145d..572171eba 100644--- a/src/components/Header/index.jsx+++ b/src/components/Header/index.jsx@@ -70,7 +70,7 @@ const Header = ({ authenticated, theme }) => {</div><div className='hidden md:flex justify-center items-center flex-wrap ml-1 md:ml-10 space-y-1 sm:space-y-0 space-x-2 md:space-x-4'>{theme === 'dark' ? (- <SunIcon onClick={switchTheme} className='h-10 w-10 text-gray-200 cursor-pointer' />+ <SunIcon onClick={switchTheme} className='h-10 w-10 text-gray-200 hover:text-gray-300 cursor-pointer' />) : (<MoonIcon onClick={switchTheme} className='h-10 w-10 text-indigo-100 hover:text-indigo-200 cursor-pointer' />)}@@ -121,7 +121,7 @@ const Header = ({ authenticated, theme }) => {</div><div className='md:hidden flex justify-center items-center'>{theme === 'dark' ? (- <SunIcon onClick={switchTheme} className='h-10 w-10 text-gray-200 cursor-pointer' />+ <SunIcon onClick={switchTheme} className='h-10 w-10 text-gray-200 hover:text-gray-300 cursor-pointer' />) : (<MoonIcon onClick={switchTheme} className='h-10 w-10 text-indigo-100 hover:text-indigo-200 cursor-pointer' />)}diff --git a/src/i18n/de.json b/src/i18n/de.jsonindex e78e666bc..d384670bc 100644--- a/src/i18n/de.json+++ b/src/i18n/de.json@@ -79,7 +79,12 @@}],"custSupport": "Ist ihre Frage hier nicht aufgelistet? Wenden Sie sich gerne an unseren <mail>Kundendienst</mail>.",- "whyUs": "Warum uns"+ "whyUs": "Warum uns",+ "ourStats": "Our statistics",+ "statsDesc": "Swetrix is built on users' trust in the service and is also capable of handling thousands of users and websites.",+ "users": "Registrierte Nutzer",+ "websites": "Hinzugefügte Webseiten",+ "pageviews": "Getrackte Aufrufe"},"auth": {"recovery": {diff --git a/src/i18n/en.json b/src/i18n/en.jsonindex 454b25131..4ddb88eb3 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -79,7 +79,12 @@}],"custSupport": "Could not find the answer you’re looking for? Reach out to our <mail>customer support</mail> team.",- "whyUs": "Why us"+ "whyUs": "Why us",+ "ourStats": "Our statistics",+ "statsDesc": "Swetrix is built on users' trust in the service and is also capable of handling thousands of users and websites.",+ "users": "Registered users",+ "websites": "Added websites",+ "pageviews": "Tracked pageviews"},"auth": {"recovery": {diff --git a/src/i18n/ru.json b/src/i18n/ru.jsonindex 536d9ba38..b4dd2b18b 100644--- a/src/i18n/ru.json+++ b/src/i18n/ru.json@@ -77,7 +77,12 @@}],"custSupport": "Не можете найти ответ на интересующий вас вопрос? Обратитесь в нашу <mail>службу поддержки</mail>.",- "whyUs": "Почему мы"+ "whyUs": "Почему мы",+ "ourStats": "Статистика",+ "statsDesc": "Swetrix построен на доверии пользователей к сервису и способен выдерживать нагрузку от тысяч пользователей и вебсайтов.",+ "users": "Пользователей",+ "websites": "Добавленных вебсайтов",+ "pageviews": "Отслеженных событий"},"auth": {"recovery": {diff --git a/src/i18n/uk.json b/src/i18n/uk.jsonindex c5b781e9e..42d454a06 100644--- a/src/i18n/uk.json+++ b/src/i18n/uk.json@@ -77,7 +77,12 @@}],"custSupport": "Чи не можете знайти відповідь на ваше запитання? Зверніться до нашої <mail>служби підтримки</mail>.",- "whyUs": "Чому ми"+ "whyUs": "Чому ми",+ "ourStats": "Статистика",+ "statsDesc": "Swetrix побудований на довірі користувачів до сервісу та має можливість витримувати навантаження з тисяч користувачів та вебсайтів.",+ "users": "Користувачів",+ "websites": "Доданих вебсайтів",+ "pageviews": "Відслідкованих подій"},"auth": {"recovery": {diff --git a/src/pages/MainPage/Pricing.jsx b/src/pages/MainPage/Pricing.jsxindex 373938e4c..9007530c7 100644--- a/src/pages/MainPage/Pricing.jsx+++ b/src/pages/MainPage/Pricing.jsx@@ -22,9 +22,9 @@ const getTiers = (t) => [planCode: 'free',priceMonthly: null,includedFeatures: [- t('pricing.tiers.upToXEVMo', { amount: 3000 }),- t('pricing.tiers.upToXProjects', { amount: 5 }),- t('pricing.tiers.xMoDataRetention', { amount: 3 }),+ t('pricing.tiers.upToXEVMo', { amount: 5000 }),+ t('pricing.tiers.upToXProjects', { amount: 10 }),+ // t('pricing.tiers.xMoDataRetention', { amount: 3 }),t('pricing.tiers.highStandardSec'),],},@@ -35,8 +35,8 @@ const getTiers = (t) => [includedFeatures: [t('pricing.tiers.evXPlanIncl', { plan: t('pricing.tiers.hobby') }),t('pricing.tiers.xEvMo', { amount: '100k' }),- t('pricing.tiers.upToXProjects', { amount: 10 }),- t('pricing.tiers.xMoDataRetention', { amount: 12 }),+ t('pricing.tiers.upToXProjects', { amount: 20 }),+ // t('pricing.tiers.xMoDataRetention', { amount: 12 }),t('pricing.tiers.smallBusiSupport'),t('pricing.tiers.carbonRemoval'),],@@ -48,7 +48,7 @@ const getTiers = (t) => [includedFeatures: [t('pricing.tiers.evXPlanIncl', { plan: t('pricing.tiers.freelancer') }),t('pricing.tiers.xEvMo', { amount: '500k' }),- t('pricing.tiers.xMoDataRetention', { amount: 12 }),+ // t('pricing.tiers.xMoDataRetention', { amount: 12 }),],},{@@ -58,7 +58,8 @@ const getTiers = (t) => [includedFeatures: [t('pricing.tiers.evXPlanIncl', { plan: t('pricing.tiers.startup') }),t('pricing.tiers.xEvMo', { amount: '1m' }),- t('pricing.tiers.xMoDataRetention', { amount: 24 }),+ t('pricing.tiers.upToXProjects', { amount: 30 }),+ // t('pricing.tiers.xMoDataRetention', { amount: 24 }),],},]diff --git a/src/pages/MainPage/index.jsx b/src/pages/MainPage/index.jsxindex 84152a929..e6c503bb5 100644--- a/src/pages/MainPage/index.jsx+++ b/src/pages/MainPage/index.jsx@@ -6,6 +6,7 @@ import { useSelector } from 'react-redux'import _map from 'lodash/map'import routes from 'routes'+// import { nFormatter } from 'utils/generic'import { notAuthenticated } from '../../hoc/protected'import Title from 'components/Title'import SignUp from '../Auth/Signup/BasicSignup'@@ -59,12 +60,12 @@ const FAQs = ({ t }) => (</div><div className='mt-12 lg:mt-0 lg:col-span-2'><dl className='space-y-12'>- {_map(t('main.faq.list', { returnObjects: true }), (faq) => (- <div key={faq.question}>- <dt className='text-lg leading-6 font-medium text-gray-900 dark:text-gray-50'>{faq.question}</dt>- <dd className='mt-2 text-base text-gray-500 dark:text-gray-300 whitespace-pre-line'>{faq.answer}</dd>- </div>- ))}+ {_map(t('main.faq.list', { returnObjects: true }), (faq) => (+ <div key={faq.question}>+ <dt className='text-lg leading-6 font-medium text-gray-900 dark:text-gray-50'>{faq.question}</dt>+ <dd className='mt-2 text-base text-gray-500 dark:text-gray-300 whitespace-pre-line'>{faq.answer}</dd>+ </div>+ ))}</dl></div></div>@@ -95,6 +96,8 @@ const Features = ({ t }) => (const Main = () => {const { t } = useTranslation('common')const { theme } = useSelector(state => state.ui.theme)+ const { stats } = useSelector(state => state.ui.misc)+ console.log(stats)return (<Title title='Privacy Respecting Web Analytics Platform'>@@ -167,6 +170,50 @@ const Main = () => {</div><Features t={t} />++ {/* <div className='py-6 overflow-hidden bg-white'>+ <div className='w-11/12 container mx-auto'>+ <h2 className='text-3xl font-extrabold text-gray-900 dark:text-gray-50 text-center'>+ {t('main.ourStats')}+ </h2>+ <p className='max-w-3xl mx-auto mt-3 text-xl text-center text-gray-500 dark:text-gray-200 sm:mt-4'>+ {t('main.statsDesc')}+ </p>+ <div className='pb-12 mt-10 bg-white sm:pb-16'>+ <div className='relative w-full'>+ <div className='mx-auto'>+ <dl className='bg-white rounded-lg sm:grid sm:grid-cols-3'>+ <div className='flex flex-col p-6 text-center border-b border-gray-100 sm:border-0 sm:border-r'>+ <dt className='order-2 mt-2 text-lg font-medium text-gray-500 leading-6'>+ {t('main.users')}+ </dt>+ <dd className='order-1 text-5xl font-extrabold text-indigo-600'>+ {Number(stats.users).toLocaleString()}+ </dd>+ </div>+ <div className='flex flex-col p-6 text-center border-t border-b border-gray-100 sm:border-0 sm:border-l sm:border-r'>+ <dt className='order-2 mt-2 text-lg font-medium text-gray-500 leading-6'>+ {t('main.websites')}+ </dt>+ <dd className='order-1 text-5xl font-extrabold text-indigo-600'>+ {Number(stats.projects).toLocaleString()}+ </dd>+ </div>+ <div className='flex flex-col p-6 text-center border-t border-gray-100 sm:border-0 sm:border-l'>+ <dt className='order-2 mt-2 text-lg font-medium text-gray-500 leading-6'>+ {t('main.pageviews')}+ </dt>+ <dd className='order-1 text-5xl font-extrabold text-indigo-600'>+ {nFormatter(Number(stats.pageviews), 1)}+ </dd>+ </div>+ </dl>+ </div>+ </div>+ </div>+ </div>+ </div> */}+<div className='bg-indigo-600 dark:bg-indigo-800'><div className='w-11/12 mx-auto pb-16 pt-12 px-4 sm:px-6 lg:px-8 lg:flex lg:items-center lg:justify-between'><h2 className='text-3xl sm:text-4xl font-extrabold tracking-tight'>diff --git a/src/redux/actions/auth/types.js b/src/redux/actions/auth/types.jsindex 303b40991..02e842816 100644--- a/src/redux/actions/auth/types.js+++ b/src/redux/actions/auth/types.js@@ -15,5 +15,5 @@ export const types = {SIGNUP_ASYNC: 'SIGNUP_ASYNC',EMAIL_VERIFY_ASYNC: 'EMAIL_VERIFY_ASYNC',UPDATE_USER_PROFILE_ASYNC: 'UPDATE_USER_PROFILE_ASYNC',- DELETE_ACCOUNT_ASYNC: 'DELETE_ACCOUNT_ASYNC'+ DELETE_ACCOUNT_ASYNC: 'DELETE_ACCOUNT_ASYNC',}diff --git a/src/redux/actions/ui/index.js b/src/redux/actions/ui/index.jsindex 2185ec62d..c06469f6e 100644--- a/src/redux/actions/ui/index.js+++ b/src/redux/actions/ui/index.js@@ -81,6 +81,13 @@ const setTheme = (theme) => ({}})+const setGeneralStats = (stats) => ({+ type: types.SET_GENERAL_STATS,+ payload: {+ stats,+ }+})+const UIActions = {loadProjects,setProjects,@@ -94,6 +101,7 @@ const UIActions = {setLiveStatsForProject,setLiveStats,setTheme,+ setGeneralStats,}export default UIActionsdiff --git a/src/redux/actions/ui/types.js b/src/redux/actions/ui/types.jsindex af8fec137..e15b3ceb0 100644--- a/src/redux/actions/ui/types.js+++ b/src/redux/actions/ui/types.js@@ -11,4 +11,5 @@ export const types = {SET_LIVE_STATS_PROJECT: 'UI_SET_LIVE_STATS_PROJECT',SET_PUBLIC_PROJECT: 'UI_SET_PUBLIC_PROJECT',SET_THEME: 'UI_SET_THEME',+ SET_GENERAL_STATS: 'UI_SET_GENERAL_STATS',}diff --git a/src/redux/constants/index.js b/src/redux/constants/index.jsindex c53d4e674..be92e4cc9 100644--- a/src/redux/constants/index.js+++ b/src/redux/constants/index.js@@ -52,6 +52,7 @@ export const DONATE_URL = 'https://ko-fi.com/andriir'export const isSelfhosted = Boolean(process.env.REACT_APP_SELFHOSTED)export const LIVE_VISITORS_UPDATE_INTERVAL = 40000+export const GENERAL_STATS_UPDATE_INTERVAL = 60000// Functionsexport const getProjectCacheKey = (period, timeBucket) => `${period}${timeBucket}`diff --git a/src/redux/reducers/ui/index.js b/src/redux/reducers/ui/index.jsindex 73aeeb5dd..919a8d968 100644--- a/src/redux/reducers/ui/index.js+++ b/src/redux/reducers/ui/index.js@@ -2,5 +2,6 @@ import { combineReducers } from 'redux'import projects from './projects'import cache from './cache'import theme from './theme'+import misc from './misc'-export default combineReducers({ projects, cache, theme })+export default combineReducers({ projects, cache, theme, misc })diff --git a/src/redux/reducers/ui/misc.js b/src/redux/reducers/ui/misc.jsnew file mode 100644index 000000000..c8db08501--- /dev/null+++ b/src/redux/reducers/ui/misc.js@@ -0,0 +1,28 @@+import { types } from 'redux/actions/ui/types'++const getInitialState = () => {+ return {+ stats: {+ users: 0,+ projects: 0,+ pageviews: 0,+ },+ }+}++const miscReducer = (state = getInitialState(), { type, payload }) => {+ switch (type) {+ case types.SET_GENERAL_STATS: {+ const { stats } = payload+ return {+ ...state,+ stats,+ }+ }++ default:+ return state+ }+}++export default miscReducerdiff --git a/src/redux/sagas/auth/watchers/index.js b/src/redux/sagas/auth/watchers/index.jsindex e1c51b375..ab2fa558f 100644--- a/src/redux/sagas/auth/watchers/index.js+++ b/src/redux/sagas/auth/watchers/index.js@@ -2,6 +2,7 @@ import { takeLatest, all, call } from 'redux-saga/effects'import { types } from 'redux/actions/auth/types'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'@@ -18,6 +19,10 @@ function* watchSignup() {yield takeLatest(types.SIGNUP_ASYNC, signUp)}+// function* watchLogout() {+// yield takeLatest(types.LOGOUT, logout)+// }+function* watchUpdateUserProfile() {yield takeLatest(types.UPDATE_USER_PROFILE_ASYNC, updateUserProfile)}@@ -27,5 +32,9 @@ function* watchDeleteUserProfile() {}export default function* watchAuth() {- yield all([call(watchLogin), call(watchSignup), call(watchVerifyEmail), call(watchUpdateUserProfile), call(watchDeleteUserProfile)])+ yield all([+ call(watchLogin), call(watchSignup), call(watchVerifyEmail),+ call(watchUpdateUserProfile), call(watchDeleteUserProfile),+ // call(watchLogout),+ ])}diff --git a/src/redux/sagas/auth/workers/logout.js b/src/redux/sagas/auth/workers/logout.jsnew file mode 100644index 000000000..86385b363--- /dev/null+++ b/src/redux/sagas/auth/workers/logout.js@@ -0,0 +1,17 @@+import { call, put } from 'redux-saga/effects'+import Debug from 'debug'++import UIActions from 'redux/actions/ui'+import { getGeneralStats } from 'api'++const debug = Debug('swetrix:rx:s:logout')++export default function* logoutWorker() {+ try {+ const stats = yield call(getGeneralStats)++ yield put(UIActions.setGeneralStats(stats))+ } catch (e) {+ debug('Error while getting general stats data: %s', e)+ }+}diff --git a/src/redux/sagas/ui/index.js b/src/redux/sagas/ui/index.jsindex 6b01dc2ca..d7d92985f 100644--- a/src/redux/sagas/ui/index.js+++ b/src/redux/sagas/ui/index.js@@ -5,11 +5,13 @@ import { types as authTypes } from '../../actions/auth/types'import loadProjects from './load_projects'import initialise from './initialise'import liveVisitors from './worker_live_visitors'+// import generalStats from './worker_general_stats'import logout from './logout'function* mainUISaga() {yield fork(initialise)yield fork(liveVisitors)+ // yield fork(generalStats)yield takeEvery(types.LOAD_PROJECTS, loadProjects)yield takeEvery(authTypes.LOGOUT, logout)}diff --git a/src/redux/sagas/ui/worker_general_stats.js b/src/redux/sagas/ui/worker_general_stats.jsnew file mode 100644index 000000000..297d47585--- /dev/null+++ b/src/redux/sagas/ui/worker_general_stats.js@@ -0,0 +1,27 @@+import { put, call, delay, select } from 'redux-saga/effects'+import Debug from 'debug'++import { getGeneralStats } from 'api'+import UIActions from 'redux/actions/ui'+import { GENERAL_STATS_UPDATE_INTERVAL } from 'redux/constants'++const debug = Debug('swetrix:rx:s:general-stats')++export default function* generalStats() {+ while (true) {+ const isAuthenticated = yield select(state => state.auth.authenticated)+ if (isAuthenticated) {+ continue+ }++ try {+ const stats = yield call(getGeneralStats)++ yield put(UIActions.setGeneralStats(stats))+ } catch (e) {+ debug('Error while getting general stats data: %s', e)+ }++ yield delay(GENERAL_STATS_UPDATE_INTERVAL)+ }+}diff --git a/src/utils/generic.js b/src/utils/generic.jsnew file mode 100644index 000000000..bb1897994--- /dev/null+++ b/src/utils/generic.js@@ -0,0 +1,13 @@+const rx = /\.0+$|(\.[0-9]*[1-9])0+$/+export const nFormatter = (num, digits) => {+ const lookup = [+ { value: 1, symbol: '' },+ { value: 1e3, symbol: 'k' },+ { value: 1e6, symbol: 'M' },+ { value: 1e9, symbol: 'B' },+ ]++ const item = lookup.slice().reverse().find((item) => num >= item.value)++ return item ? (num / item.value).toFixed(digits).replace(rx, '$1') + item.symbol : '0'+}