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!

Display more useful info in the funnel tooltip

Blue Moused0bb02ebedb3
diff --git a/web/app/api/api.server.ts b/web/app/api/api.server.ts
index 18f3e5ea5..56452bad0 100644
--- a/web/app/api/api.server.ts
+++ b/web/app/api/api.server.ts
@@ -1431,6 +1431,8 @@ export interface FunnelDataResponse {
dropoff: number
dropoffPerc: number
dropoffPercStep: number
+ topCountries: Record<string, number>
+ topSources: Record<string, number>
}[]
totalPageviews: number
}
diff --git a/web/app/lib/models/Project.ts b/web/app/lib/models/Project.ts
index e032a881e..6d986c2f2 100644
--- a/web/app/lib/models/Project.ts
+++ b/web/app/lib/models/Project.ts
@@ -170,6 +170,8 @@ export interface AnalyticsFunnel {
dropoff: number
dropoffPerc: number
dropoffPercStep: number
+ topCountries: Record<string, number>
+ topSources: Record<string, number>
}
export const IMPORT_PROVIDERS = ['umami', 'simple-analytics', 'fathom'] as const
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsx
index da78a4403..ecc2c3fa4 100644
--- a/web/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx
@@ -64,6 +64,7 @@ import {
getStringFromTime,
sumArrays,
nFormatter,
+ escapeHtml,
} from '~/utils/generic'
import countries from '~/utils/isoCountries'
@@ -1718,91 +1719,161 @@ const getSettingsFunnels = (
},
},
tooltip: {
- contents: (items: any, _: any, __: any, color: any) => {
+ contents: (items: any) => {
const { index = 0 } = items[0] || {}
const step = funnel[index]
- const stepTitle = values[index]
- const prevStepTitle = values[index - 1]
-
- const prevStepHtml = prevStepTitle
- ? `
- <span>${prevStepTitle}</span>
- `
- : ''
-
- const title = `
- <p class='font-semibold flex items-center gap-1 tracking-tight'>
- ${prevStepHtml}
- <span class='opacity-70'>→</span>
- <span>${stepTitle}</span>
- </p>
- `
- const events = `
- <tr class='tracking-tight'>
- <td class='pr-4'>
- <div class='flex items-center gap-1.5'>
- <div class='w-2.5 h-2.5 rounded-xs shrink-0' style=background-color:${color('events')}></div>
- <span class='font-semibold'>
- ${_startsWith(step.value, '/') ? t('project.visitors') : t('project.events')}
- </span>
+ const stepTitle = escapeHtml(values[index] ?? '')
+ const prevStep = index > 0 ? funnel[index - 1] : null
+ const prevStepTitle = escapeHtml(values[index - 1] ?? '')
+
+ const topSourcesEntries = Object.entries(step.topSources || {})
+ const topCountriesEntries = Object.entries(step.topCountries || {})
+
+ const primary = 'text-gray-900 dark:text-gray-50'
+ const secondary = 'text-gray-700 dark:text-gray-200'
+ const success = 'text-green-600 dark:text-green-400'
+ const error = 'text-red-600 dark:text-red-400'
+
+ let headerHtml = ''
+
+ if (index === 0) {
+ const neverEntered = totalPageviews - step.events
+ headerHtml = `
+ <div class='flex items-center justify-between gap-6'>
+ <div class='flex items-center gap-1.5 min-w-0'>
+ <span class='${secondary}'>↳</span>
+ <span class='font-semibold truncate ${primary}'>${stepTitle}</span>
</div>
- </td>
- <td class='pr-2 font-semibold text-right font-mono'>
- ${step.events}
- </td>
- <td class='text-right font-mono'>
- ${step.eventsPercStep}%
- </td>
- </tr>
- `
-
- const dropoff = `
- <tr class='tracking-tight'>
- <td class='pr-4'>
- <div class='flex items-center gap-1.5'>
- <div class='w-2.5 h-2.5 rounded-xs shrink-0' style="background-color:${color('dropoff')}"></div>
- <span class='font-semibold'>
- ${index === 0 ? t('project.neverEnteredTheFunnel') : t('project.dropoff')}
- </span>
+ <span class='font-mono font-semibold tabular-nums shrink-0 ${primary}'>${nFormatter(step.events, 1)}</span>
+ </div>
+ ${
+ neverEntered > 0
+ ? `
+ <div class='flex items-center justify-between gap-6 mt-1'>
+ <span class='${secondary}'>${t('project.neverEnteredTheFunnel')}</span>
+ <span class='font-mono tabular-nums ${error}'>-${nFormatter(neverEntered, 1)}</span>
</div>
- </td>
- <td class='pr-2 font-semibold text-right font-mono'>
- ${index === 0 ? totalPageviews - step.events : step.dropoff}
- </td>
- <td class='text-right font-mono'>
- ${
- index === 0
- ? _round(
- ((totalPageviews - step.events) / totalPageviews) * 100,
- 2,
- )
- : step.dropoffPercStep
- }%
- </td>
- </tr>
- `
+ `
+ : ''
+ }
+ `
+ } else {
+ headerHtml = `
+ <div class='flex items-center justify-between gap-6'>
+ <div class='flex items-center gap-1.5 min-w-0'>
+ <span class='${secondary}'>↳</span>
+ <span class='font-medium truncate ${secondary}'>${prevStepTitle}</span>
+ </div>
+ <span class='font-mono font-medium tabular-nums shrink-0 ${secondary}'>${nFormatter(prevStep!.events, 1)}</span>
+ </div>
+ <div class='flex items-center justify-between gap-6 mt-1'>
+ <span class='${secondary}'>${t('project.dropoff')}</span>
+ <span class='font-mono tabular-nums ${error}'>-${nFormatter(step.dropoff, 1)}</span>
+ </div>
+ <div class='flex items-center justify-between gap-6 mt-1'>
+ <div class='flex items-center gap-1.5 min-w-0 pl-4'>
+ <span class='${secondary}'>↳</span>
+ <span class='font-semibold truncate ${primary}'>${stepTitle}</span>
+ </div>
+ <span class='font-mono font-semibold tabular-nums shrink-0 ${primary}'>${nFormatter(step.events, 1)}</span>
+ </div>
+ `
+ }
- const conversionFromStart = `
- <tr class='tracking-tight'>
- <td class='pr-4'>
- <span class='font-semibold'>${t('project.conversionFromStart')}</span>
- </td>
- <td class='pr-2 font-semibold text-right font-mono'>${step.eventsPerc}%</td>
- <td class='text-right'></td>
- </tr>
+ const conversionHtml = `
+ <div class='border-t border-gray-200 dark:border-slate-700/80 mt-2 pt-2'>
+ <div class='flex items-center justify-between gap-6'>
+ <span class='font-semibold ${primary}'>${t('project.conversion')}</span>
+ <span class='font-mono tabular-nums font-semibold ${success}'>${step.eventsPercStep}%</span>
+ </div>
+ <div class='flex items-center justify-between gap-6 mt-0.5'>
+ <span class='${secondary}'>${t('project.conversionFromStart')}</span>
+ <span class='font-mono tabular-nums ${success}'>${step.eventsPerc}%</span>
+ </div>
+ </div>
`
+ let detailsHtml = ''
+ if (topSourcesEntries.length > 0 || topCountriesEntries.length > 0) {
+ const sourcesHtml =
+ topSourcesEntries.length > 0
+ ? `
+ <div class='flex-1 min-w-0'>
+ <p class='text-[10px] font-semibold uppercase tracking-wider ${secondary} mb-1.5'>
+ ${t('project.topSources')}
+ </p>
+ ${topSourcesEntries
+ .map(([domain, count]) => {
+ const perc =
+ step.events > 0
+ ? Math.round((count / step.events) * 100)
+ : 0
+ const isDirect = domain === 'Direct / None'
+ const safeDomain = escapeHtml(domain)
+ const iconHtml = isDirect
+ ? `
+ <img src='/assets/icons/chain.svg' class='size-3.5 shrink-0 dark:hidden' alt='' />
+ <img src='/assets/icons/chain-light.svg' class='size-3.5 shrink-0 hidden dark:inline' alt='' />
+ `
+ : `<img src='https://icons.duckduckgo.com/ip3/${encodeURIComponent(domain)}.ico' class='size-3.5 rounded-sm shrink-0' loading='lazy' alt='' />`
+ return `
+ <div class='flex items-center justify-between gap-2 mt-1'>
+ <div class='flex items-center gap-1.5 min-w-0'>
+ ${iconHtml}
+ <span class='truncate ${primary}'>${safeDomain}</span>
+ </div>
+ <span class='font-mono tabular-nums shrink-0 ${primary}'>${perc}%</span>
+ </div>
+ `
+ })
+ .join('')}
+ </div>
+ `
+ : ''
+
+ const countriesHtml =
+ topCountriesEntries.length > 0
+ ? `
+ <div class='flex-1 min-w-0'>
+ <p class='text-[10px] font-semibold uppercase tracking-wider ${secondary} mb-1.5'>
+ ${t('project.topCountries')}
+ </p>
+ ${topCountriesEntries
+ .map(([cc, count]) => {
+ const perc =
+ step.events > 0
+ ? Math.round((count / step.events) * 100)
+ : 0
+ const safeName = escapeHtml(countries.getName(cc, 'en') || cc)
+ const safeCC = encodeURIComponent(cc.toLowerCase())
+ return `
+ <div class='flex items-center justify-between gap-2 mt-1'>
+ <div class='flex items-center gap-1.5 min-w-0'>
+ <img src='/assets/flags/${safeCC}.svg' width='16' height='12' class='shrink-0 rounded-[2px]' loading='lazy' alt='' />
+ <span class='truncate ${primary}'>${safeName}</span>
+ </div>
+ <span class='font-mono tabular-nums shrink-0 ${primary}'>${perc}%</span>
+ </div>
+ `
+ })
+ .join('')}
+ </div>
+ `
+ : ''
+
+ detailsHtml = `
+ <div class='border-t border-gray-200 dark:border-slate-700/80 mt-2 pt-2 flex gap-5'>
+ ${sourcesHtml}
+ ${countriesHtml}
+ </div>
+ `
+ }
+
return `
- <div class='bg-gray-50 dark:text-gray-50 dark:bg-slate-900 rounded-md ring-1 ring-black/10 px-2 py-1 text-xs md:text-sm max-w-xs md:max-w-sm max-h-[300px] md:max-h-[400px] overflow-y-auto shadow-md z-50'>
- ${title}
- <div class='border-b border-gray-200 dark:border-slate-800 my-1'></div>
- <table class='w-auto'>
- <tbody>
- ${events}
- ${dropoff}
- ${conversionFromStart}
- </tbody>
- </table>
+ <div class='bg-gray-50 dark:bg-slate-900 rounded-lg ring-1 ring-black/10 dark:ring-white/10 px-3 py-2.5 text-xs md:text-sm max-w-sm md:max-w-md shadow-lg z-50'>
+ ${headerHtml}
+ ${conversionHtml}
+ ${detailsHtml}
</div>
`
},
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 312354666..df4e63823 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -1091,9 +1091,13 @@ const ViewProjectContent = () => {
}
// 'Keyboard shortcuts' help modal
- useHotkeys('shift+?', () => {
- setIsHotkeysHelpOpened((val) => !val)
- }, { useKey: true })
+ useHotkeys(
+ 'shift+?',
+ () => {
+ setIsHotkeysHelpOpened((val) => !val)
+ },
+ { useKey: true },
+ )
// 'Tabs switching' shortcuts
useHotkeys(SHORTCUTS_TABS_LISTENERS, ({ key }) => {
diff --git a/web/public/assets/icons/chain-light.svg b/web/public/assets/icons/chain-light.svg
new file mode 100644
index 000000000..6960a4825
--- /dev/null
+++ b/web/public/assets/icons/chain-light.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" fill="#e5e7eb" viewBox="0 0 256 256"><path d="M240,88.23a54.43,54.43,0,0,1-16,37L189.25,160a54.27,54.27,0,0,1-38.63,16h-.05A54.63,54.63,0,0,1,96,119.84a8,8,0,0,1,16,.45A38.62,38.62,0,0,0,150.58,160h0a38.39,38.39,0,0,0,27.31-11.31l34.75-34.75a38.63,38.63,0,0,0-54.63-54.63l-11,11A8,8,0,0,1,135.7,59l11-11A54.65,54.65,0,0,1,224,48,54.86,54.86,0,0,1,240,88.23ZM109,185.66l-11,11A38.41,38.41,0,0,1,70.6,208h0a38.63,38.63,0,0,1-27.29-65.94L78,107.31A38.63,38.63,0,0,1,144,135.71a8,8,0,0,0,16,.45A54.86,54.86,0,0,0,144,96a54.65,54.65,0,0,0-77.27,0L32,130.75A54.62,54.62,0,0,0,70.56,224h0a54.28,54.28,0,0,0,38.64-16l11-11A8,8,0,0,0,109,185.66Z"></path></svg>
diff --git a/web/public/assets/icons/chain.svg b/web/public/assets/icons/chain.svg
new file mode 100644
index 000000000..149c07587
--- /dev/null
+++ b/web/public/assets/icons/chain.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" fill="#374151" viewBox="0 0 256 256"><path d="M240,88.23a54.43,54.43,0,0,1-16,37L189.25,160a54.27,54.27,0,0,1-38.63,16h-.05A54.63,54.63,0,0,1,96,119.84a8,8,0,0,1,16,.45A38.62,38.62,0,0,0,150.58,160h0a38.39,38.39,0,0,0,27.31-11.31l34.75-34.75a38.63,38.63,0,0,0-54.63-54.63l-11,11A8,8,0,0,1,135.7,59l11-11A54.65,54.65,0,0,1,224,48,54.86,54.86,0,0,1,240,88.23ZM109,185.66l-11,11A38.41,38.41,0,0,1,70.6,208h0a38.63,38.63,0,0,1-27.29-65.94L78,107.31A38.63,38.63,0,0,1,144,135.71a8,8,0,0,0,16,.45A54.86,54.86,0,0,0,144,96a54.65,54.65,0,0,0-77.27,0L32,130.75A54.62,54.62,0,0,0,70.56,224h0a54.28,54.28,0,0,0,38.64-16l11-11A8,8,0,0,0,109,185.66Z"></path></svg>
diff --git a/web/public/locales/de.json b/web/public/locales/de.json
index d59541313..7943c6e74 100644
--- a/web/public/locales/de.json
+++ b/web/public/locales/de.json
@@ -1566,8 +1566,10 @@
"changeInSettings": "Ändern Sie dies in Ihren Kontoeinstellungen",
"events": "Ereignisse",
"dropoff": "Dropoff",
- "conversionFromStart": "Konversion ab Start",
+ "conversionFromStart": "Seit Beginn",
"neverEnteredTheFunnel": "Nie den Trichter betreten",
+ "topSources": "Top-Quellen",
+ "topCountries": "Top-Länder",
"aggregation": "Aggregation",
"locked": {
"title": "Dashboard gesperrt",
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index 6c0d38f07..8f32f3d71 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -1566,8 +1566,10 @@
"changeInSettings": "Change this in your account settings",
"events": "Events",
"dropoff": "Dropoff",
- "conversionFromStart": "Conversion from start",
+ "conversionFromStart": "from start",
"neverEnteredTheFunnel": "Never entered the funnel",
+ "topSources": "Top sources",
+ "topCountries": "Top countries",
"aggregation": "Aggregation",
"locked": {
"title": "Dashboard locked",
diff --git a/web/public/locales/fr.json b/web/public/locales/fr.json
index 90c43eaf7..075443a5f 100644
--- a/web/public/locales/fr.json
+++ b/web/public/locales/fr.json
@@ -1566,8 +1566,10 @@
"changeInSettings": "Modifiez cela dans les paramètres de votre compte",
"events": "Événements",
"dropoff": "Abandon",
- "conversionFromStart": "Conversion depuis le début",
+ "conversionFromStart": "Depuis le début",
"neverEnteredTheFunnel": "Jamais entré dans le tunnel",
+ "topSources": "Principales sources",
+ "topCountries": "Principaux pays",
"aggregation": "Agrégation",
"locked": {
"title": "Tableau de bord verrouillé",
diff --git a/web/public/locales/pl.json b/web/public/locales/pl.json
index 2818c8378..78853ff49 100644
--- a/web/public/locales/pl.json
+++ b/web/public/locales/pl.json
@@ -1566,8 +1566,10 @@
"changeInSettings": "Zmień to w ustawieniach konta",
"events": "Zdarzenia",
"dropoff": "Rezygnacja",
- "conversionFromStart": "Konwersja od początku",
+ "conversionFromStart": "Od początku",
"neverEnteredTheFunnel": "Nigdy nie wszedł do lejka",
+ "topSources": "Główne źródła",
+ "topCountries": "Główne kraje",
"aggregation": "Agregacja",
"locked": {
"title": "Panel kontrolny zablokowany",
diff --git a/web/public/locales/uk.json b/web/public/locales/uk.json
index 15e4f5821..13e3b0276 100644
--- a/web/public/locales/uk.json
+++ b/web/public/locales/uk.json
@@ -1566,8 +1566,10 @@
"changeInSettings": "Змініть це в налаштуваннях свого профілю",
"events": "Події",
"dropoff": "Випадання",
- "conversionFromStart": "Конверсія від початку",
+ "conversionFromStart": "Від початку",
"neverEnteredTheFunnel": "Ніколи не попав у воронку",
+ "topSources": "Головні джерела",
+ "topCountries": "Головні країни",
"aggregation": "Агрегація",
"locked": {
"title": "Панель заблоковано",