📈 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) Cumulative mode (#373)
Andrii Romasiune9245d174ce3
diff --git a/app/api/index.ts b/app/api/index.tsindex 00d98131f..6a0411434 100644--- a/app/api/index.ts+++ b/app/api/index.ts@@ -416,10 +416,11 @@ export const getProjectData = (to: string = '',timezone: string = '',password: string | undefined = '',+ mode: 'periodical' | 'cumulative' = 'periodical',) =>api.get(- `log?pid=${pid}&timeBucket=${tb}&period=${period}&filters=${JSON.stringify(filters)}&from=${from}&to=${to}&timezone=${timezone}`,+ `log?pid=${pid}&timeBucket=${tb}&period=${period}&filters=${JSON.stringify(filters)}&from=${from}&to=${to}&timezone=${timezone}&mode=${mode}`,{headers: {'x-password': password,@@ -470,10 +471,11 @@ export const getProjectCompareData = (to: string = '',timezone: string = '',password: string | undefined = '',+ mode: 'periodical' | 'cumulative' = 'periodical',) =>api.get(- `log/chart?pid=${pid}&timeBucket=${tb}&period=${period}&filters=${JSON.stringify(filters)}&from=${from}&to=${to}&timezone=${timezone}`,+ `log/chart?pid=${pid}&timeBucket=${tb}&period=${period}&filters=${JSON.stringify(filters)}&from=${from}&to=${to}&timezone=${timezone}&mode=${mode}`,{headers: {'x-password': password,diff --git a/app/pages/Changelog/index.tsx b/app/pages/Changelog/index.tsxindex edaaedd44..b55ac8891 100644--- a/app/pages/Changelog/index.tsx+++ b/app/pages/Changelog/index.tsx@@ -14,6 +14,12 @@ const INTEGRATIONS_LINK = `${routes.user_settings}#integrations`// Date format: YYYY-MM-DDconst changelog = [+ {+ date: '2023-10-17',+ changes: [+ 'Added support for cumulative mode visualisation.',+ ],+ },{date: '2023-10-14',changes: [diff --git a/app/pages/Project/View/ViewProject.helpers.tsx b/app/pages/Project/View/ViewProject.helpers.tsxindex 4aef943f9..d88a4b085 100644--- a/app/pages/Project/View/ViewProject.helpers.tsx+++ b/app/pages/Project/View/ViewProject.helpers.tsx@@ -180,6 +180,7 @@ const CHART_METRICS_MAPPING = {trendlines: 'trendlines',sessionDuration: 'sessionDuration',customEvents: 'customEvents',+ cumulativeMode: 'cumulativeMode',}const FILTER_CHART_METRICS_MAPPING_FOR_COMPARE = ['bounce', 'viewsPerUnique', 'trendlines', 'customEvents']diff --git a/app/pages/Project/View/ViewProject.tsx b/app/pages/Project/View/ViewProject.tsxindex b9371396b..2684bc373 100644--- a/app/pages/Project/View/ViewProject.tsx+++ b/app/pages/Project/View/ViewProject.tsx@@ -241,6 +241,7 @@ const ViewProject = ({[CHART_METRICS_MAPPING.bounce]: false,[CHART_METRICS_MAPPING.viewsPerUnique]: false,[CHART_METRICS_MAPPING.trendlines]: false,+ [CHART_METRICS_MAPPING.cumulativeMode]: false,})// similar activeChartMetrics but using for performance tabconst [activeChartMetricsPerf, setActiveChartMetricsPerf] = useState<string>(CHART_METRICS_MAPPING_PERF.timing)@@ -276,6 +277,8 @@ const ViewProject = ({return projectTab || PROJECT_TABS.traffic})+ const mode = activeChartMetrics[CHART_METRICS_MAPPING.cumulativeMode] ? 'cumulative' : 'periodical'+useEffect(() => {// @ts-ignoreconst url = new URL(window.location)@@ -423,6 +426,11 @@ const ViewProject = ({label: t('dashboard.trendlines'),active: activeChartMetrics[CHART_METRICS_MAPPING.trendlines],},+ {+ id: CHART_METRICS_MAPPING.cumulativeMode,+ label: t('dashboard.cumulativeMode'),+ active: activeChartMetrics[CHART_METRICS_MAPPING.cumulativeMode],+ },{id: CHART_METRICS_MAPPING.customEvents,label: t('project.customEv'),@@ -704,7 +712,7 @@ const ViewProject = ({if (activePeriod?.period === 'custom' ? diffCompare <= diff : diffCompare <= activePeriod?.countDays) {fromCompare = getFormatDate(dateRangeCompare[0])toCompare = getFormatDate(dateRangeCompare[1])- keyCompare = getProjectCacheCustomKey(fromCompare, toCompare, timeBucket, newFilters || filters)+ keyCompare = getProjectCacheCustomKey(fromCompare, toCompare, timeBucket, mode, newFilters || filters)} else {showError(t('project.compareDateRangeError'))compareDisable()@@ -720,7 +728,7 @@ const ViewProject = ({if (date) {fromCompare = date.fromtoCompare = date.to- keyCompare = getProjectCacheCustomKey(fromCompare, toCompare, timeBucket, newFilters || filters)+ keyCompare = getProjectCacheCustomKey(fromCompare, toCompare, timeBucket, mode, newFilters || filters)}}@@ -728,7 +736,7 @@ const ViewProject = ({if (!_isEmpty(cache[id]) && !_isEmpty(cache[id][keyCompare])) {dataCompare = cache[id][keyCompare]} else {- dataCompare = await getProjectCompareData(id, timeBucket, '', newFilters || filters, fromCompare, toCompare, timezone, projectPassword)+ dataCompare = await getProjectCompareData(id, timeBucket, '', newFilters || filters, fromCompare, toCompare, timezone, projectPassword, mode)}}@@ -743,9 +751,9 @@ const ViewProject = ({if (dateRange) {from = getFormatDate(dateRange[0])to = getFormatDate(dateRange[1])- key = getProjectCacheCustomKey(from, to, timeBucket, newFilters || filters)+ key = getProjectCacheCustomKey(from, to, timeBucket, mode, newFilters || filters)} else {- key = getProjectCacheKey(period, timeBucket, newFilters || filters)+ key = getProjectCacheKey(period, timeBucket, mode, newFilters || filters)}// check if we need to load new date or we have data in redux/localstorage@@ -753,10 +761,10 @@ const ViewProject = ({data = cache[id][key]} else {if (period === 'custom' && dateRange) {- data = await getProjectData(id, timeBucket, '', newFilters || filters, from, to, timezone, projectPassword)+ data = await getProjectData(id, timeBucket, '', newFilters || filters, from, to, timezone, projectPassword, mode)customEventsChart = await getProjectDataCustomEvents(id, timeBucket, '', filters, from, to, timezone, activeChartMetricsCustomEvents, projectPassword)} else {- data = await getProjectData(id, timeBucket, period, newFilters || filters, '', '', timezone, projectPassword)+ data = await getProjectData(id, timeBucket, period, newFilters || filters, '', '', timezone, projectPassword, mode)customEventsChart = await getProjectDataCustomEvents(id, timeBucket, period, filters, '', '', timezone, activeChartMetricsCustomEvents, projectPassword)}@@ -936,9 +944,9 @@ const ViewProject = ({if (dateRange) {from = getFormatDate(dateRange[0])to = getFormatDate(dateRange[1])- key = getProjectCacheCustomKey(from, to, timeBucket, newFilters || filtersPerf)+ key = getProjectCacheCustomKey(from, to, timeBucket, mode, newFilters || filtersPerf)} else {- key = getProjectCacheKey(period, timeBucket, newFilters || filtersPerf)+ key = getProjectCacheKey(period, timeBucket, mode, newFilters || filtersPerf)}if (!forced && !_isEmpty(cachePerf[id]) && !_isEmpty(cachePerf[id][key])) {@@ -1287,7 +1295,7 @@ const ViewProject = ({useEffect(() => {loadAnalytics()// eslint-disable-next-line react-hooks/exhaustive-deps- }, [forecasedChartData])+ }, [forecasedChartData, mode])// this useEffect is used for parsing tab from url and set activeTabuseEffect(() => {diff --git a/app/redux/constants/index.ts b/app/redux/constants/index.tsindex 74bcf088d..151ec7c48 100644--- a/app/redux/constants/index.ts+++ b/app/redux/constants/index.ts@@ -267,10 +267,10 @@ export const isSelfhosted = Boolean()// Functions-export const getProjectCacheKey = (period: string, timeBucket: string, filters?: any): string => `${period}${timeBucket}${filters ? JSON.stringify(filters) : ''}}`+export const getProjectCacheKey = (period: string, timeBucket: string, mode: 'periodical' | 'cumulative', filters?: any): string => `${period}${timeBucket}${mode}${filters ? JSON.stringify(filters) : ''}}`export const getProjectCaptchaCacheKey = (period: string, timeBucket: string, filters?: any): string => `${period}${timeBucket}captcha${filters ? JSON.stringify(filters) : ''}}`export const getProjectForcastCacheKey = (period: string, timeBucket: string, periodToForecast: string, filters: any): string => `${period}${timeBucket}${periodToForecast}forecast${filters ? JSON.stringify(filters) : ''}`-export const getProjectCacheCustomKey = (from: string, to: string, timeBucket: string, filters: any): string => `${from}-${to}-${timeBucket}${filters ? JSON.stringify(filters) : ''}}`+export const getProjectCacheCustomKey = (from: string, to: string, timeBucket: string, mode: 'periodical' | 'cumulative', filters: any): string => `cst${from}${to}${timeBucket}-${mode}${filters ? JSON.stringify(filters) : ''}}`export const getProjectCacheCustomKeyPerf = (from: string, to: string, timeBucket: string, filters: any): string => `${from}-${to}-${timeBucket}perf${filters ? JSON.stringify(filters) : ''}`export const getUserFlowCacheKey = (pid: string, period: string, filters: any): string => `${pid}${period}userflow${filters ? JSON.stringify(filters) : ''}`diff --git a/public/locales/en.json b/public/locales/en.jsonindex 57fb30286..628ded1dd 100644--- a/public/locales/en.json+++ b/public/locales/en.json@@ -486,6 +486,7 @@"invitationFor": "Invitation for {{project}}","invitationDesc": "You have been invited to join the project {{project}}.\nYou can either accept the invitation here or reject it in your account settings.","sessionDuration": "Session duration",+ "cumulativeMode": "Cumulative mode","traffic": "Traffic","performance": "Performance","alerts": "Alerts",