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!

feature: set color for interactive map, add cache and panels

kruzhambus20b7a192e856
diff --git a/public/index.html b/public/index.html
index 2814d3b4f..ee58262ae 100644
--- a/public/index.html
+++ b/public/index.html
@@ -37,7 +37,7 @@
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
- swetrix.init('5iUTk0QaunIt', {
+ swetrix.init('fbLxmqT4d3Du', {
debug: true,
heartbeatOnBackground: true,
apiURL: 'http://localhost:5005/log'
diff --git a/src/pages/Project/View/ViewProject.container.jsx b/src/pages/Project/View/ViewProject.container.jsx
index 33966843c..63e859a3d 100644
--- a/src/pages/Project/View/ViewProject.container.jsx
+++ b/src/pages/Project/View/ViewProject.container.jsx
@@ -13,12 +13,14 @@ const mapStateToProps = (state) => {
sharedProjects: state.ui.projects.sharedProjects,
isLoading: state.ui.projects.isLoadingShared,
cache: state.ui.cache.analytics,
+ cachePerf: state.ui.cache.analyticsPerf,
projectViewPrefs: state.ui.cache.projectViewPrefs,
authenticated: state.auth.authenticated,
timezone: state.auth.user.timezone,
isPaidTierUsed: state.auth.isPaidTierUsed,
extensions: state.ui.misc.extensions,
user: state.auth.user,
+ projectTab: state.ui.projects.projectTab,
}
}
@@ -27,12 +29,14 @@ const mapStateToProps = (state) => {
sharedProjects: state.ui.projects.sharedProjects,
isLoading: state.ui.projects.isLoading,
cache: state.ui.cache.analytics,
+ cachePerf: state.ui.cache.analyticsPerf,
projectViewPrefs: state.ui.cache.projectViewPrefs,
authenticated: state.auth.authenticated,
timezone: state.auth.user.timezone,
isPaidTierUsed: state.auth.isPaidTierUsed,
extensions: state.ui.misc.extensions,
user: state.auth.user,
+ projectTab: state.ui.projects.projectTab,
}
}
@@ -58,6 +62,9 @@ const mapDispatchToProps = (dispatch) => ({
generateAlert: (message, type) => {
dispatch(alertsActions.generateAlerts(message, type))
},
+ setProjectTab: (tabs) => {
+ dispatch(UIActions.setProjectTab(tabs))
+ },
})
export default connect(mapStateToProps, mapDispatchToProps)(ViewProject)
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index 756c8ab69..d54fb5c42 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -59,11 +59,10 @@ import NoEvents from './components/NoEvents'
import Filters from './components/Filters'
import './styles.css'
-const DEFAULT_TAB = 'traffic'
-
const ViewProject = ({
- projects, isLoading: _isLoading, showError, cache, setProjectCache, projectViewPrefs, setProjectViewPrefs, setPublicProject,
+ projects, isLoading: _isLoading, showError, cache, cachePerf, setProjectCache, projectViewPrefs, setProjectViewPrefs, setPublicProject,
setLiveStatsForProject, authenticated, timezone, user, sharedProjects, isPaidTierUsed, extensions, generateAlert, setProjectCachePerf,
+ projectTab, setProjectTab,
}) => {
const { t, i18n: { language } } = useTranslation('common')
const [periodPairs, setPeriodPairs] = useState(tbPeriodPairs(t))
@@ -112,11 +111,10 @@ const ViewProject = ({
const refCalendar = useRef(null)
const localStorageDateRange = projectViewPrefs[id]?.rangeDate
const [dateRange, setDateRange] = useState(localStorageDateRange ? [new Date(localStorageDateRange[0]), new Date(localStorageDateRange[1])] : null)
- const [activeTab, setActiveTab] = useState(DEFAULT_TAB)
+ const [activeTab, setActiveTab] = useState(projectTab)
const [chartDataPerf, setChartDataPerf] = useState({})
const [isPanelsDataEmptyPerf, setIsPanelsDataEmptyPerf] = useState(false)
- const [perfData, setPerfData] = useState({})
const [panelsDataPerf, setPanelsDataPerf] = useState({})
const tabs = useMemo(() => {
@@ -309,6 +307,9 @@ const ViewProject = ({
if (!forced && !_isEmpty(cache[id]) && !_isEmpty(cache[id][key])) {
data = cache[id][key]
+ if (!_isEmpty(cachePerf[id]) && !_isEmpty(cachePerf[id][key])) {
+ dataPerf = cachePerf[id][key]
+ }
} else {
if (period === 'custom' && dateRange) {
data = await getProjectData(id, timeBucket, '', newFilters || filters, from, to, timezone)
@@ -393,7 +394,6 @@ const ViewProject = ({
const applyRegions = !_includes(noRegionPeriods, activePeriod.period)
const bbSettings = getSettings(chartPerf, timeBucket, activeChartMetricsPerf, applyRegions)
setChartDataPerf(chartPerf)
- setPerfData(dataPerf)
setPanelsDataPerf({
types: _keys(dataPerf.params),
@@ -1021,6 +1021,7 @@ const ViewProject = ({
onSelect={(label) => {
const selected = _find(tabs, (tab) => tab.label === label)
setActiveTab(selected.id)
+ setProjectTab(selected.id)
}}
title={activeTabLabel}
/>
@@ -1034,7 +1035,10 @@ const ViewProject = ({
return (
<div
key={tab.id}
- onClick={() => setActiveTab(tab.id)}
+ onClick={() => {
+ setProjectTab(tab.id)
+ setActiveTab(tab.id)
+ }}
className={cx(
isCurrent
? 'border-indigo-700 text-indigo-700 dark:text-indigo-500 dark:border-indigo-500'
@@ -1146,16 +1150,16 @@ const ViewProject = ({
</div>
</div>
<div className='flex flex-row flex-wrap items-center justify-center md:justify-end h-10 mt-16 md:mt-5 mb-4'>
- {!isPanelsDataEmpty && (
- <Dropdown
- items={activeTab === tabs[0].id ? chartMetrics : chartMetricsPerf}
- title={t('project.metricVis')}
- labelExtractor={(pair) => {
- const {
- label, id: pairID, active, conflicts,
- } = pair
+ {activeTab === tabs[0].id ? (
+ !isPanelsDataEmpty && (
+ <Dropdown
+ items={chartMetrics}
+ title={t('project.metricVis')}
+ labelExtractor={(pair) => {
+ const {
+ label, id: pairID, active, conflicts,
+ } = pair
- if (activeTab === tabs[0].id) {
const conflicted = isConflicted(conflicts)
return (
@@ -1167,18 +1171,34 @@ const ViewProject = ({
checked={active}
/>
)
- }
+ }}
+ keyExtractor={(pair) => pair.id}
+ onSelect={({ id: pairID, conflicts }) => {
+ if (isConflicted(conflicts)) {
+ generateAlert(t('project.conflictMetric'), 'error')
+ return
+ }
+ switchActiveChartMetric(pairID)
+ }}
+ />
+ )) : (
+ !isPanelsDataEmptyPerf && (
+ <Dropdown
+ items={chartMetricsPerf}
+ title={t('project.metricVis')}
+ labelExtractor={(pair) => {
+ const {
+ label,
+ } = pair
+
return label
}}
keyExtractor={(pair) => pair.id}
- onSelect={({ id: pairID, conflicts }) => {
- if (isConflicted(conflicts)) {
- generateAlert(t('project.conflictMetric'), 'error')
- return
- }
+ onSelect={({ id: pairID }) => {
switchActiveChartMetric(pairID)
}}
/>
+ )
)}
<Dropdown
items={[...exportTypes, ...customExportTypes]}
@@ -1325,7 +1345,7 @@ const ViewProject = ({
</div>
</div>
)}
- {activeTab === 'performance' && (
+ {activeTab === tabs[1].id && (
<div className={cx('pt-4 md:pt-0', { hidden: isPanelsDataEmpty || analyticsLoading })}>
<div
className={cx('h-80', {
@@ -1349,22 +1369,11 @@ const ViewProject = ({
</div>
)}
<div className='mt-5 grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3'>
- {!_isEmpty(project.overall) && (
- <Overview
- t={t}
- overall={project.overall}
- chartData={chartData}
- activePeriod={activePeriod}
- sessionDurationAVG={sessionDurationAVG}
- live={project.live}
- projectId={id}
- />
- )}
- {_map(panelsData.types, (type) => {
+ {_map(panelsDataPerf.types, (type) => {
const panelName = tnMapping[type]
const panelIcon = panelIconMapping[type]
const customTabs = _filter(customPanelTabs, tab => tab.panelID === type)
-
+ console.log(panelsDataPerf)
if (type === 'cc') {
return (
<Panel
@@ -1374,7 +1383,7 @@ const ViewProject = ({
id={type}
onFilter={filterHandler}
name={panelName}
- data={panelsData.data[type]}
+ data={panelsDataPerf.data[type]}
customTabs={customTabs}
rowMapper={(rowName) => (
<CCRow rowName={rowName} language={language} />
@@ -1392,9 +1401,8 @@ const ViewProject = ({
id={type}
onFilter={filterHandler}
name={panelName}
- data={panelsData.data[type]}
+ data={panelsDataPerf.data[type]}
customTabs={customTabs}
- capitalize
/>
)
}
@@ -1408,7 +1416,7 @@ const ViewProject = ({
id={type}
onFilter={filterHandler}
name={panelName}
- data={panelsData.data[type]}
+ data={panelsDataPerf.data[type]}
customTabs={customTabs}
rowMapper={(rowName) => (
<RefRow rowName={rowName} showIcons={showIcons} />
@@ -1425,18 +1433,11 @@ const ViewProject = ({
id={type}
onFilter={filterHandler}
name={panelName}
- data={panelsData.data[type]}
+ data={panelsDataPerf.data[type]}
customTabs={customTabs}
/>
)
})}
- {!_isEmpty(panelsData.customs) && (
- <CustomEvents
- t={t}
- customs={panelsData.customs}
- chartData={chartData}
- />
- )}
</div>
</div>
)}
diff --git a/src/pages/Project/View/components/InteractiveMap.jsx b/src/pages/Project/View/components/InteractiveMap.jsx
index e435815b7..8aa947ca6 100644
--- a/src/pages/Project/View/components/InteractiveMap.jsx
+++ b/src/pages/Project/View/components/InteractiveMap.jsx
@@ -4,8 +4,10 @@ import _map from 'lodash/map'
import { useTranslation } from 'react-i18next'
import PropTypes from 'prop-types'
import countries from 'utils/isoCountries'
+import { projectTabs } from 'redux/constants'
import countriesList from 'utils/countries'
+import { useSelector } from 'react-redux'
const InteractiveMap = ({ data, onClickCountry, total }) => {
const { t, i18n: { language } } = useTranslation('common')
@@ -13,6 +15,8 @@ const InteractiveMap = ({ data, onClickCountry, total }) => {
const [dataHover, setDataHover] = useState(null)
const [cursorPosition, setCursorPosition] = useState(null)
+ const projectTab = useSelector((state) => state.ui.projects.projectTab)
+
const onMouseMove = (e) => {
const rect = e.currentTarget.getBoundingClientRect()
const pageX = e.clientX - rect.left
@@ -32,15 +36,24 @@ const InteractiveMap = ({ data, onClickCountry, total }) => {
<path
key={index}
id={index}
- className={cx({
- 'hover:opacity-90': perc > 0,
- 'fill-[#cfd1d4] dark:fill-[#465d7e46]': perc === 0,
- 'fill-[#92b2e7] dark:fill-[#292d77]': perc > 0 && perc < 3,
- 'fill-[#6f9be3] dark:fill-[#363391]': perc >= 3 && perc < 10,
- 'fill-[#5689db] dark:fill-[#4842be]': perc >= 10 && perc < 20,
- 'fill-[#3b82f6] dark:fill-[#6357ff]': perc >= 20,
- 'cursor-pointer': Boolean(visitors),
- })}
+ className={projectTabs.traffic === projectTab
+ ? cx({
+ 'hover:opacity-90': perc > 0,
+ 'fill-[#cfd1d4] dark:fill-[#465d7e46]': perc === 0,
+ 'fill-[#92b2e7] dark:fill-[#292d77]': perc > 0 && perc < 3,
+ 'fill-[#6f9be3] dark:fill-[#363391]': perc >= 3 && perc < 10,
+ 'fill-[#5689db] dark:fill-[#4842be]': perc >= 10 && perc < 20,
+ 'fill-[#3b82f6] dark:fill-[#6357ff]': perc >= 20,
+ 'cursor-pointer': Boolean(visitors),
+ }) : cx({
+ 'hover:opacity-90': perc > 0,
+ 'fill-[#cfd1d4] dark:fill-[#465d7e46]': perc === 0,
+ 'fill-[#f7a8a8]': perc > 0 && perc < 3,
+ 'fill-[#f78a8a]': perc >= 3 && perc < 10,
+ 'fill-[#f76b6b]': perc >= 10 && perc < 20,
+ 'fill-[#f74b4b]': perc >= 20,
+ 'cursor-pointer': Boolean(visitors),
+ })}
d={item.d}
onClick={() => perc !== 0 && onClickCountry(index)}
onMouseEnter={() => {
diff --git a/src/redux/actions/ui/index.js b/src/redux/actions/ui/index.js
index 4f4768fa5..0879f0469 100644
--- a/src/redux/actions/ui/index.js
+++ b/src/redux/actions/ui/index.js
@@ -196,6 +196,11 @@ const setThemeType = (theme) => ({
payload: { theme },
})
+const setProjectTab = (tab) => ({
+ type: types.SET_PROJECT_TAB,
+ payload: { tab },
+})
+
const UIActions = {
loadProjects,
loadSharedProjects,
@@ -226,6 +231,7 @@ const UIActions = {
setThemeType,
setProjectCachePerf,
deleteProjectCachePerf,
+ setProjectTab,
}
export default UIActions
diff --git a/src/redux/actions/ui/types.js b/src/redux/actions/ui/types.js
index c363c2a97..1bdcc2a69 100644
--- a/src/redux/actions/ui/types.js
+++ b/src/redux/actions/ui/types.js
@@ -28,4 +28,5 @@ export const types = {
SET_THEME_TYPE: 'UI_SET_THEME_TYPE',
SET_PROJECT_CACHE_PERF: 'UI_SET_PROJECT_CACHE_PERF',
DELETE_PROJECT_CACHE_PERF: 'UI_DELETE_PROJECT_CACHE_PERF',
+ SET_PROJECT_TAB: 'UI_SET_PROJECT_TAB',
}
diff --git a/src/redux/constants/index.js b/src/redux/constants/index.js
index 6a5afa72b..eb4cd9519 100644
--- a/src/redux/constants/index.js
+++ b/src/redux/constants/index.js
@@ -194,6 +194,11 @@ export const tabsForDashboard = [
},
]
+export const projectTabs = {
+ traffic: 'traffic',
+ performance: 'performance',
+}
+
export const INVITATION_EXPIRES_IN = 48 // hours
export const ENTRIES_PER_PAGE_DASHBOARD = 10
diff --git a/src/redux/reducers/ui/projects.js b/src/redux/reducers/ui/projects.js
index 232bb3597..8249462b6 100644
--- a/src/redux/reducers/ui/projects.js
+++ b/src/redux/reducers/ui/projects.js
@@ -2,7 +2,7 @@ import { types } from 'redux/actions/ui/types'
import _filter from 'lodash/filter'
import _findIndex from 'lodash/findIndex'
import _map from 'lodash/map'
-import { tabForOwnedProject } from 'redux/constants'
+import { tabForOwnedProject, projectTabs } from 'redux/constants'
import { setItem, getItem } from 'utils/localstorage'
const getInitialState = () => {
@@ -18,6 +18,7 @@ const getInitialState = () => {
dashboardPaginationPage: 1,
dashboardPaginationPageShared: 1,
dashboardTabs: getItem('dashboardTabs') || tabForOwnedProject,
+ projectTab: projectTabs.traffic,
}
}
@@ -257,6 +258,15 @@ const projectsReducer = (state = getInitialState(), { type, payload }) => {
}
}
+ case types.SET_PROJECT_TAB: {
+ const { tab } = payload
+
+ return {
+ ...state,
+ projectTab: tab,
+ }
+ }
+
default:
return state
}