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) Performance load time allocation (#402)

Andrii Romasiun47bb8ae9e65f
diff --git a/app/api/index.ts b/app/api/index.ts
index c90fcce59..e6ba8d6bd 100644
--- a/app/api/index.ts
+++ b/app/api/index.ts
@@ -460,13 +460,14 @@ export const getPerfData = (
from: string = '',
to: string = '',
timezone: string = '',
+ measure: string = '',
password: string | undefined = '',
) =>
api
.get(
`log/performance?pid=${pid}&timeBucket=${tb}&period=${period}&filters=${JSON.stringify(
filters,
- )}&from=${from}&to=${to}&timezone=${timezone}`,
+ )}&from=${from}&to=${to}&timezone=${timezone}&measure=${measure}`,
{
headers: {
'x-password': password,
diff --git a/app/pages/Project/View/ViewProject.helpers.tsx b/app/pages/Project/View/ViewProject.helpers.tsx
index 8bca8af70..86ab9c3af 100644
--- a/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/app/pages/Project/View/ViewProject.helpers.tsx
@@ -195,6 +195,7 @@ const CHART_METRICS_MAPPING = {
const FILTER_CHART_METRICS_MAPPING_FOR_COMPARE = ['bounce', 'viewsPerUnique', 'trendlines', 'customEvents']
const CHART_METRICS_MAPPING_PERF = {
+ quantiles: 'quantiles',
full: 'full',
timing: 'timing',
network: 'network',
@@ -202,6 +203,16 @@ const CHART_METRICS_MAPPING_PERF = {
backend: 'backend',
}
+const CHART_MEASURES_MAPPING_PERF = {
+ // Dependent on metric
+ average: 'average',
+ median: 'median',
+ p95: 'p95',
+
+ // Independent measure that provides it's own metrics
+ quantiles: 'quantiles',
+}
+
// function to filter the data for the chart
const getColumns = (
chart: {
@@ -279,7 +290,19 @@ const getColumnsPerf = (
) => {
const columns: any[] = [['x', ..._map(chart.x, (el) => dayjs(el).toDate())]]
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.full) {
+ if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.quantiles && chart?.p50 && chart?.p75 && chart?.p95) {
+ columns.push(['p50', ...chart.p50])
+ columns.push(['p75', ...chart.p75])
+ columns.push(['p95', ...chart.p95])
+
+ if (compareChart?.p50 && compareChart?.p75 && compareChart?.p95) {
+ columns.push(['p50Compare', ...compareChart.p50])
+ columns.push(['p75Compare', ...compareChart.p75])
+ columns.push(['p95Compare', ...compareChart.p95])
+ }
+ }
+
+ if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.full && chart.dns) {
columns.push(['dns', ...chart.dns])
columns.push(['tls', ...chart.tls])
columns.push(['conn', ...chart.conn])
@@ -307,7 +330,7 @@ const getColumnsPerf = (
}
}
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.timing) {
+ if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.timing && chart.ttfb) {
columns.push(['frontend', ...sumArrays(chart.render, chart.domLoad)])
columns.push(['network', ...sumArrays(chart.dns, chart.tls, chart.conn, chart.response)])
columns.push(['backend', ...chart.ttfb])
@@ -330,7 +353,7 @@ const getColumnsPerf = (
}
}
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.network) {
+ if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.network && chart.dns) {
columns.push(['dns', ...chart.dns])
columns.push(['tls', ...chart.tls])
columns.push(['conn', ...chart.conn])
@@ -344,7 +367,7 @@ const getColumnsPerf = (
}
}
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.frontend) {
+ if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.frontend && chart.render) {
columns.push(['render', ...chart.render])
columns.push(['dom_load', ...chart.domLoad])
@@ -354,7 +377,7 @@ const getColumnsPerf = (
}
}
- if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.backend) {
+ if (activeChartMetrics === CHART_METRICS_MAPPING_PERF.backend && chart.ttfb) {
columns.push(['ttfb', ...chart.ttfb])
if (compareChart?.ttfb) {
@@ -372,6 +395,10 @@ const getValueForTooltipPerfomance = (
id: string,
index: number,
) => {
+ if (id === 'p50' || id === 'p75' || id === 'p95') {
+ return chart[id] ? chart[id][index] : 0
+ }
+
if (id === 'dns' || id === 'tls' || id === 'conn' || id === 'response' || id === 'render' || id === 'ttfb') {
return chart[id] ? chart[id][index] : 0
}
@@ -1047,6 +1074,9 @@ const perfomanceChartCompare = [
'frontendCompare',
'networkCompare',
'backendCompare',
+ 'p50Compare',
+ 'p75Compare',
+ 'p95Compare',
]
const getSettingsPerf = (
@@ -1080,6 +1110,9 @@ const getSettingsPerf = (
frontend: chartType === chartTypes.line ? areaSpline() : bar(),
network: chartType === chartTypes.line ? areaSpline() : bar(),
backend: chartType === chartTypes.line ? areaSpline() : bar(),
+ p50: chartType === chartTypes.line ? areaSpline() : bar(),
+ p75: chartType === chartTypes.line ? areaSpline() : bar(),
+ p95: chartType === chartTypes.line ? areaSpline() : bar(),
dnsCompare: chartType === chartTypes.line ? spline() : bar(),
tlsCompare: chartType === chartTypes.line ? spline() : bar(),
connCompare: chartType === chartTypes.line ? spline() : bar(),
@@ -1090,6 +1123,9 @@ const getSettingsPerf = (
frontendCompare: chartType === chartTypes.line ? spline() : bar(),
networkCompare: chartType === chartTypes.line ? spline() : bar(),
backendCompare: chartType === chartTypes.line ? spline() : bar(),
+ p50Compare: chartType === chartTypes.line ? spline() : bar(),
+ p75Compare: chartType === chartTypes.line ? spline() : bar(),
+ p95Compare: chartType === chartTypes.line ? spline() : bar(),
},
colors: {
dns: '#EC4319',
@@ -1102,6 +1138,12 @@ const getSettingsPerf = (
frontend: '#709775',
network: '#F7A265',
backend: '#00A8E8',
+ p50: '#38bdf8',
+ p75: '#facc15',
+ p95: '#f87171',
+ p50Compare: 'rgba(56, 189, 248, 0.4)',
+ p75Compare: 'rgba(250, 204, 21, 0.4)',
+ p95Compare: 'rgba(248, 113, 113, 0.4)',
dnsCompare: 'rgba(236, 67, 25, 0.4)',
tlsCompare: 'rgba(242, 112, 89, 0.4)',
connCompare: 'rgba(247, 162, 101, 0.4)',
@@ -1114,6 +1156,8 @@ const getSettingsPerf = (
backendCompare: 'rgba(0, 168, 232, 0.4)',
},
groups: [
+ ['p50', 'p75', 'p95'],
+ ['p50Compare', 'p75Compare', 'p95Compare'],
['dns', 'tls', 'conn', 'response', 'render', 'dom_load', 'ttfb', 'frontend', 'network', 'backend'],
[
'dnsCompare',
@@ -1402,4 +1446,5 @@ export {
SHORTCUTS_TABS_LISTENERS,
SHORTCUTS_GENERAL_LISTENERS,
SHORTCUTS_TIMEBUCKETS_LISTENERS,
+ CHART_MEASURES_MAPPING_PERF,
}
diff --git a/app/pages/Project/View/ViewProject.tsx b/app/pages/Project/View/ViewProject.tsx
index 8497e3104..87cf46e7c 100644
--- a/app/pages/Project/View/ViewProject.tsx
+++ b/app/pages/Project/View/ViewProject.tsx
@@ -155,6 +155,7 @@ import {
SHORTCUTS_TABS_MAP,
SHORTCUTS_GENERAL_LISTENERS,
SHORTCUTS_TIMEBUCKETS_LISTENERS,
+ CHART_MEASURES_MAPPING_PERF,
} from './ViewProject.helpers'
import CCRow from './components/CCRow'
import FunnelsList from './components/FunnelsList'
@@ -387,6 +388,7 @@ const ViewProject = ({
})
// similar activeChartMetrics but using for performance tab
const [activeChartMetricsPerf, setActiveChartMetricsPerf] = useState<string>(CHART_METRICS_MAPPING_PERF.timing)
+ const [activePerfMeasure, setActivePerfMeasure] = useState(CHART_MEASURES_MAPPING_PERF.median)
// checkIfAllMetricsAreDisabled when all metrics are disabled, we are hidden chart
const checkIfAllMetricsAreDisabled = useMemo(
() => !_some({ ...activeChartMetrics, ...activeChartMetricsCustomEvents }, (value) => value),
@@ -688,34 +690,59 @@ const ViewProject = ({
// chartMetricsPerf is a list of metrics for dropdown in performance tab
const chartMetricsPerf = useMemo(() => {
return [
+ {
+ id: CHART_METRICS_MAPPING_PERF.quantiles,
+ label: t('dashboard.allocation'),
+ active: activeChartMetricsPerf === CHART_METRICS_MAPPING_PERF.quantiles,
+ },
{
id: CHART_METRICS_MAPPING_PERF.full,
label: t('dashboard.timingFull'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.full),
+ active: activeChartMetricsPerf === CHART_METRICS_MAPPING_PERF.full,
},
{
id: CHART_METRICS_MAPPING_PERF.timing,
label: t('dashboard.timing'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.timing),
+ active: activeChartMetricsPerf === CHART_METRICS_MAPPING_PERF.timing,
},
{
id: CHART_METRICS_MAPPING_PERF.network,
label: t('dashboard.network'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.network),
+ active: activeChartMetricsPerf === CHART_METRICS_MAPPING_PERF.network,
},
{
id: CHART_METRICS_MAPPING_PERF.frontend,
label: t('dashboard.frontend'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.frontend),
+ active: activeChartMetricsPerf === CHART_METRICS_MAPPING_PERF.frontend,
},
{
id: CHART_METRICS_MAPPING_PERF.backend,
label: t('dashboard.backend'),
- active: _includes(activeChartMetricsPerf, CHART_METRICS_MAPPING_PERF.backend),
+ active: activeChartMetricsPerf === CHART_METRICS_MAPPING_PERF.backend,
},
]
}, [t, activeChartMetricsPerf])
+ const chartMeasuresPerf = useMemo(() => {
+ return [
+ {
+ id: CHART_MEASURES_MAPPING_PERF.average,
+ label: t('dashboard.average'),
+ active: activePerfMeasure === CHART_MEASURES_MAPPING_PERF.average,
+ },
+ {
+ id: CHART_MEASURES_MAPPING_PERF.median,
+ label: t('dashboard.median'),
+ active: activePerfMeasure === CHART_MEASURES_MAPPING_PERF.median,
+ },
+ {
+ id: CHART_MEASURES_MAPPING_PERF.p95,
+ label: t('dashboard.xPercentile', { x: 95 }),
+ active: activePerfMeasure === CHART_MEASURES_MAPPING_PERF.p95,
+ },
+ ]
+ }, [t, activePerfMeasure])
+
// chartMetricsCustomEvents is a list of custom events for dropdown
const chartMetricsCustomEvents = useMemo(() => {
if (!_isEmpty(panelsData.customs)) {
@@ -765,6 +792,9 @@ const ViewProject = ({
render: t('dashboard.render'),
dom_load: t('dashboard.domLoad'),
ttfb: t('dashboard.ttfb'),
+ p50: t('dashboard.xPercentile', { x: 50 }),
+ p75: t('dashboard.xPercentile', { x: 75 }),
+ p95: t('dashboard.xPercentile', { x: 95 }),
}),
[t],
)
@@ -1413,7 +1443,13 @@ const ViewProject = ({
if (activePeriod?.period === 'custom' ? diffCompare <= diff : diffCompare <= activePeriod?.countDays) {
fromCompare = getFormatDate(dateRangeCompare[0])
toCompare = getFormatDate(dateRangeCompare[1])
- keyCompare = getProjectCacheCustomKeyPerf(fromCompare, toCompare, timeBucket, newFilters || filtersPerf)
+ keyCompare = getProjectCacheCustomKeyPerf(
+ fromCompare,
+ toCompare,
+ timeBucket,
+ newFilters || filtersPerf,
+ activePerfMeasure,
+ )
} else {
showError(t('project.compareDateRangeError'))
compareDisable()
@@ -1429,7 +1465,13 @@ const ViewProject = ({
if (date) {
fromCompare = date.from
toCompare = date.to
- keyCompare = getProjectCacheCustomKeyPerf(fromCompare, toCompare, timeBucket, newFilters || filtersPerf)
+ keyCompare = getProjectCacheCustomKeyPerf(
+ fromCompare,
+ toCompare,
+ timeBucket,
+ newFilters || filtersPerf,
+ activePerfMeasure,
+ )
}
}
@@ -1445,6 +1487,7 @@ const ViewProject = ({
fromCompare,
toCompare,
timezone,
+ activePerfMeasure,
projectPassword,
)
const compareOverall = await getPerformanceOverallStats(
@@ -1463,12 +1506,17 @@ const ViewProject = ({
setProjectCachePerf(id, dataCompare || {}, keyCompare)
}
+ const measure =
+ activeChartMetricsPerf === CHART_METRICS_MAPPING_PERF.quantiles
+ ? CHART_METRICS_MAPPING_PERF.quantiles
+ : activePerfMeasure
+
if (dateRange) {
from = getFormatDate(dateRange[0])
to = getFormatDate(dateRange[1])
- key = getProjectCacheCustomKey(from, to, timeBucket, mode, newFilters || filtersPerf)
+ key = getProjectCacheCustomKey(from, to, timeBucket, mode, newFilters || filtersPerf, measure)
} else {
- key = getProjectCacheKey(period, timeBucket, mode, newFilters || filtersPerf)
+ key = getProjectCacheKey(period, timeBucket, mode, newFilters || filtersPerf, measure)
}
if (!forced && !_isEmpty(cachePerf[id]) && !_isEmpty(cachePerf[id][key])) {
@@ -1485,6 +1533,7 @@ const ViewProject = ({
from,
to,
timezone,
+ measure,
projectPassword,
)
rawOverall = await getOverallStats([id], period, from, to, timezone, newFilters || filters, projectPassword)
@@ -1497,6 +1546,7 @@ const ViewProject = ({
'',
'',
timezone,
+ measure,
projectPassword,
)
rawOverall = await getPerformanceOverallStats(
@@ -2603,6 +2653,15 @@ const ViewProject = ({
setForecasedChartData({})
}
+ const onMeasureChange = (measure: string) => {
+ setActivePerfMeasure(measure)
+ }
+
+ useEffect(() => {
+ loadAnalyticsPerf()
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [activePerfMeasure, activeChartMetricsPerf])
+
const openSettingsHandler = () => {
navigate(_replace(routes.project_settings, ':id', id))
}
@@ -3258,6 +3317,25 @@ const ViewProject = ({
headless
/>
)}
+ {activeTab === PROJECT_TABS.performance && !isPanelsDataEmptyPerf && (
+ <Dropdown
+ disabled={activeChartMetricsPerf === CHART_METRICS_MAPPING_PERF.quantiles}
+ items={chartMeasuresPerf}
+ className='min-w-[170px] xs:min-w-0'
+ title={
+ <p>
+ {_find(chartMeasuresPerf, ({ id: chartId }) => chartId === activePerfMeasure)?.label}
+ </p>
+ }
+ labelExtractor={(pair) => pair.label}
+ keyExtractor={(pair) => pair.id}
+ onSelect={({ id: pairID }) => {
+ onMeasureChange(pairID)
+ }}
+ chevron='mini'
+ headless
+ />
+ )}
<TBPeriodSelector
activePeriod={activePeriod}
updateTimebucket={updateTimebucket}
diff --git a/app/redux/constants/index.ts b/app/redux/constants/index.ts
index 91ac653cd..1a89ed503 100644
--- a/app/redux/constants/index.ts
+++ b/app/redux/constants/index.ts
@@ -393,7 +393,8 @@ export const getProjectCacheKey = (
timeBucket: string,
mode: 'periodical' | 'cumulative',
filters?: any,
-): string => `${period}${timeBucket}${mode}${filters ? JSON.stringify(filters) : ''}}`
+ meta = '',
+): string => `${period}${timeBucket}${mode}${filters ? JSON.stringify(filters) : ''}${meta}`
export const getProjectCaptchaCacheKey = (period: string, timeBucket: string, filters?: any): string =>
`${period}${timeBucket}captcha${filters ? JSON.stringify(filters) : ''}}`
export const getProjectForcastCacheKey = (
@@ -408,9 +409,15 @@ export const getProjectCacheCustomKey = (
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) : ''}`
+ meta = '',
+): string => `cst${from}${to}${timeBucket}-${mode}${filters ? JSON.stringify(filters) : ''}${meta}`
+export const getProjectCacheCustomKeyPerf = (
+ from: string,
+ to: string,
+ timeBucket: string,
+ filters: any,
+ measure: string,
+): string => `${from}-${to}-${timeBucket}perf${filters ? JSON.stringify(filters) : ''}-${measure}`
export const getUserFlowCacheKey = (pid: string, period: string, filters: any): string =>
`${pid}${period}userflow${filters ? JSON.stringify(filters) : ''}`
export const getFunnelsCacheKey = (pid: string, funnelId: string, period: string): string =>
diff --git a/app/styles/ProjectViewStyle.css b/app/styles/ProjectViewStyle.css
index 5652f98c0..4cf27b2b1 100644
--- a/app/styles/ProjectViewStyle.css
+++ b/app/styles/ProjectViewStyle.css
@@ -75,6 +75,18 @@ html.dark .bb-axis .domain {
stroke: #00a8e8 !important;
}
+.bb-target-p50 .bb-bar {
+ stroke: #0ea5e9 !important;
+}
+
+.bb-target-p75 .bb-bar {
+ stroke: #eab308 !important;
+}
+
+.bb-target-p95 .bb-bar {
+ stroke: #ef4444 !important;
+}
+
.bb-target-events .bb-bar {
stroke: #2563eb !important;
}
diff --git a/app/ui/Dropdown.tsx b/app/ui/Dropdown.tsx
index 460de5e7c..7e07239d7 100644
--- a/app/ui/Dropdown.tsx
+++ b/app/ui/Dropdown.tsx
@@ -27,6 +27,7 @@ interface IDropdown {
header?: string | JSX.Element
chevron?: 'regular' | 'mini'
headless?: boolean
+ disabled?: boolean
}
const Dropdown = ({
@@ -44,6 +45,7 @@ const Dropdown = ({
header,
chevron,
headless,
+ disabled,
}: IDropdown): JSX.Element => (
<Menu as='div' className={cx('relative inline-block text-left', className)}>
{({ open }) => (
@@ -51,13 +53,15 @@ const Dropdown = ({
{!_isEmpty(desc) && <p className='mb-2 text-sm text-gray-900'>{desc}</p>}
<div>
<Menu.Button
+ disabled={disabled}
className={cx(buttonClassName, {
'justify-between': aside,
'justify-center': !aside,
- 'inline-flex w-full rounded-md border border-gray-300 shadow-sm px-3 md:px-4 py-2 bg-white text-sm font-medium text-gray-700 dark:text-gray-50 dark:border-gray-800 dark:bg-slate-800 hover:bg-gray-50 dark:hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500':
+ 'inline-flex w-full rounded-md border border-gray-300 shadow-sm px-3 md:px-4 py-2 bg-white text-sm font-medium dark:border-gray-800 dark:bg-slate-800 hover:bg-gray-50 dark:hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500':
!headless,
- 'inline-flex w-full px-3 md:px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-50 outline-none group':
- headless,
+ 'inline-flex w-full px-3 md:px-4 py-2 text-sm font-medium outline-none group': headless,
+ 'text-gray-700 dark:text-gray-50': !disabled,
+ 'cursor-not-allowed text-gray-500 dark:text-gray-400': disabled,
})}
>
{title}
@@ -137,6 +141,7 @@ Dropdown.propTypes = {
menuItemsClassName: PropTypes.string,
chevron: PropTypes.oneOf(['regular', 'mini']),
headless: PropTypes.bool,
+ disabled: PropTypes.bool,
}
Dropdown.defaultProps = {
@@ -151,6 +156,7 @@ Dropdown.defaultProps = {
menuItemsClassName: '',
chevron: 'regular',
headless: false,
+ disabled: false,
}
export default memo(Dropdown)
diff --git a/public/locales/en.json b/public/locales/en.json
index f2b5d5934..8672314ad 100644
--- a/public/locales/en.json
+++ b/public/locales/en.json
@@ -523,6 +523,7 @@
"network": "Network",
"timing": "Timing breakdown",
"timingFull": "Timing breakdown (full)",
+ "allocation": "Load time allocation",
"dns": "DNS",
"conn": "Connection",
"tls": "TLS Setup",
@@ -530,7 +531,10 @@
"domLoad": "DOM Content Load",
"pageLoad": "Page load time",
"render": "Browser render",
- "response": "Response Time"
+ "response": "Response Time",
+ "average": "Average",
+ "median": "Median",
+ "xPercentile": "{{x}}th percentile"
},
"alert": {
"create": "Create an alert",