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!

Custom events chart: display as a line graph, show top-x events selector

Blue Mousedbd799a59307
diff --git a/web/app/lib/constants/index.ts b/web/app/lib/constants/index.ts
index 11b6af252..539f1948f 100644
--- a/web/app/lib/constants/index.ts
+++ b/web/app/lib/constants/index.ts
@@ -346,8 +346,6 @@ export const ERROR_TRACKING_DOCS_URL = 'https://docs.swetrix.com/error-tracking'
export const isBrowser =
typeof window !== 'undefined' && typeof document !== 'undefined'
-export const isIframe = isBrowser && window.self !== window.top
-
export type ThemeType = 'dark' | 'light'
export const SUPPORTED_THEMES = ['light', 'dark']
diff --git a/web/app/pages/Project/View/Panels.tsx b/web/app/pages/Project/View/Panels.tsx
index d4f076e1f..0b352fb59 100644
--- a/web/app/pages/Project/View/Panels.tsx
+++ b/web/app/pages/Project/View/Panels.tsx
@@ -61,6 +61,7 @@ import {
const ENTRIES_PER_PANEL = 8
const ENTRIES_PER_CUSTOM_EVENTS_PANEL = 7
+const CUSTOM_EVENTS_TOP_LIMITS = [1, 3, 5, 10] as const
const PanelEmptyState = ({ message }: { message: string }) => (
<div className='flex flex-col items-center justify-center py-8 text-center'>
@@ -483,6 +484,8 @@ const CustomEvents = ({
x: string[]
events: Record<string, Array<number | string>>
} | null>(null)
+ const [chartTopLimit, setChartTopLimit] =
+ useState<(typeof CUSTOM_EVENTS_TOP_LIMITS)[number]>(5)
const keys = _keys(eventsData)
const keysToDisplay = useMemo(
@@ -509,8 +512,8 @@ const CustomEvents = ({
'desc',
)
- return _map(_slice(sorted, 0, 15), 'event') as string[]
- }, [customs])
+ return _map(_slice(sorted, 0, chartTopLimit), 'event') as string[]
+ }, [customs, chartTopLimit])
const [sort, setSort] = useState<SortRows>({
label: 'quantity',
@@ -951,7 +954,24 @@ const CustomEvents = ({
type='customEventsChart'
hideHeader
>
- {renderStackedChart()}
+ <div className='flex h-full flex-col'>
+ <div className='mb-2 flex justify-end'>
+ <Dropdown
+ title={t('project.topX', { x: chartTopLimit })}
+ items={[...CUSTOM_EVENTS_TOP_LIMITS]}
+ keyExtractor={(item) => item}
+ labelExtractor={(item) => t('project.topX', { x: item })}
+ onSelect={(item, _e, close) => {
+ setChartTopLimit(item)
+ close()
+ }}
+ chevron='mini'
+ buttonClassName='min-w-[96px] items-center px-2 py-1.5 text-sm leading-none font-medium md:px-2 [&_svg]:h-4 [&_svg]:w-4'
+ menuItemsClassName='w-24'
+ />
+ </div>
+ <div className='min-h-0 flex-1'>{renderStackedChart()}</div>
+ </div>
</PanelContainer>
</div>
)
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsx
index 69e5a8618..efedbd28c 100644
--- a/web/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx
@@ -562,6 +562,19 @@ const stringToColour = (str: string) => {
return colour
}
+const CUSTOM_EVENTS_CHART_COLORS = [
+ '#7C3AED',
+ '#2563EB',
+ '#0891B2',
+ '#0D9488',
+ '#16A34A',
+ '#CA8A04',
+ '#EA580C',
+ '#DC2626',
+ '#DB2777',
+ '#7C2D12',
+]
+
// setting the default values for the time period dropdown
const noRegionPeriods = ['custom', 'yesterday']
@@ -1094,26 +1107,39 @@ const getSettingsCustomEventsStacked = (
const types: Record<string, any> = _reduce(
eventIds,
(acc: Record<string, any>, id: string) => {
- acc[id] = bar()
+ acc[id] = line()
return acc
},
{},
)
+ const eventSeriesStyles = _reduce(
+ eventIds,
+ (acc: Record<string, { fill: string }>, id: string, index: number) => {
+ const fill =
+ CUSTOM_EVENTS_CHART_COLORS[index % CUSTOM_EVENTS_CHART_COLORS.length]
+ acc[id] = { fill }
+ return acc
+ },
+ {},
+ )
const colors: Record<string, string> = _reduce(
eventIds,
(acc: Record<string, string>, id: string) => {
- acc[id] = stringToColour(id)
+ acc[id] = eventSeriesStyles[id].fill
return acc
},
{},
)
- // Calculate optimal Y axis ticks based on all event series
- const allYValues: number[] = []
- eventIds.forEach((id) => {
- allYValues.push(..._map(chart.events[id] || [], (v) => Number(v) || 0))
- })
+ const allYValues: number[] = _reduce(
+ eventIds,
+ (acc: number[], id: string) => {
+ acc.push(..._map(chart.events[id] || [], (v) => Number(v) || 0))
+ return acc
+ },
+ [],
+ )
const optimalTicks =
allYValues.length > 0 ? calculateOptimalTicks(allYValues) : undefined
@@ -1123,9 +1149,6 @@ const getSettingsCustomEventsStacked = (
columns,
types,
colors,
- groups: [eventIds],
- // Keep stack order stable (avoid per-x sorting)
- order: null,
},
grid: {
y: {
@@ -1211,11 +1234,12 @@ const getSettingsCustomEventsStacked = (
},
},
},
- bar: {
- linearGradient: false,
- radius: {
- ratio: 0.15,
+ point: {
+ focus: {
+ only: _size(chart.x) > 1,
},
+ pattern: ['circle'],
+ r: 2,
},
}
}
diff --git a/web/app/styles/ProjectViewStyle.css b/web/app/styles/ProjectViewStyle.css
index 5ca653c4b..eb373c612 100644
--- a/web/app/styles/ProjectViewStyle.css
+++ b/web/app/styles/ProjectViewStyle.css
@@ -80,10 +80,9 @@ body.dark .bb-ygrid {
stroke-width: 1.5;
}
-/* Custom events stacked chart: remove outlines (dynamic series) */
+/* Custom events stacked chart: keep stronger fill for dynamic series */
.custom-events-stacked-chart .bb-bar {
fill-opacity: 0.85 !important;
- stroke-width: 0 !important;
}
.bb-target-unique .bb-bar {
diff --git a/web/public/locales/de.json b/web/public/locales/de.json
index a8f312df9..f24a029ee 100644
--- a/web/public/locales/de.json
+++ b/web/public/locales/de.json
@@ -1518,6 +1518,7 @@
"noAffectedSessions": "Keine betroffenen Sitzungen gefunden",
"viewSession": "Sitzung anzeigen",
"topPages": "Top-Seiten",
+ "topX": "Top {{x}}",
"locationAndDevice": "Standort & Gerät",
"sessionInfo": "Sitzungsinformationen",
"goToProfile": "Zum Profil gehen",
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index d4adb185f..1cbe2e47d 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -1518,6 +1518,7 @@
"noAffectedSessions": "No affected sessions found",
"viewSession": "View session",
"topPages": "Top pages",
+ "topX": "Top {{x}}",
"locationAndDevice": "Location & Device",
"sessionInfo": "Session info",
"goToProfile": "Go to profile",
diff --git a/web/public/locales/fr.json b/web/public/locales/fr.json
index 5a7e0e160..73de05923 100644
--- a/web/public/locales/fr.json
+++ b/web/public/locales/fr.json
@@ -1518,6 +1518,7 @@
"noAffectedSessions": "Aucune session affectée trouvée",
"viewSession": "Voir la session",
"topPages": "Pages principales",
+ "topX": "Top {{x}}",
"locationAndDevice": "Localisation et appareil",
"sessionInfo": "Infos de session",
"goToProfile": "Aller au profil",
diff --git a/web/public/locales/pl.json b/web/public/locales/pl.json
index e084ab06a..acf98f531 100644
--- a/web/public/locales/pl.json
+++ b/web/public/locales/pl.json
@@ -1518,6 +1518,7 @@
"noAffectedSessions": "Nie znaleziono dotkniętych sesji",
"viewSession": "Wyświetl sesję",
"topPages": "Najpopularniejsze strony",
+ "topX": "Najlepsze {{x}}",
"locationAndDevice": "Lokalizacja i urządzenie",
"sessionInfo": "Informacje o sesji",
"goToProfile": "Przejdź do profilu",
diff --git a/web/public/locales/uk.json b/web/public/locales/uk.json
index c0d583c8a..0fc0a7077 100644
--- a/web/public/locales/uk.json
+++ b/web/public/locales/uk.json
@@ -1518,6 +1518,7 @@
"noAffectedSessions": "Залучених сесій не знайдено",
"viewSession": "Переглянути сесію",
"topPages": "Найпопулярніші сторінки",
+ "topX": "Топ {{x}}",
"locationAndDevice": "Місцезнаходження та пристрій",
"sessionInfo": "Інформація про сесію",
"goToProfile": "Перейти до профілю",