Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Enhance Funnel component with improved metrics display and layout

Bill Yangbd5e19e0e6b9
diff --git a/client/src/app/[site]/funnels/components/Funnel.tsx b/client/src/app/[site]/funnels/components/Funnel.tsx
index bdbe544d1..8d65228d9 100644
--- a/client/src/app/[site]/funnels/components/Funnel.tsx
+++ b/client/src/app/[site]/funnels/components/Funnel.tsx
@@ -3,6 +3,7 @@
import { FunnelResponse } from "@/api/analytics/useGetFunnel";
import { DateSelector } from "@/components/DateSelector/DateSelector";
import { Time } from "@/components/DateSelector/types";
+import { round } from "lodash";
import { ArrowDown, ArrowRight, ChevronRight } from "lucide-react";
export type FunnelChartData = {
@@ -49,7 +50,28 @@ export function Funnel({
return (
<div>
- <div className="flex justify-end items-center gap-2 mb-6">
+ <div className="flex justify-between items-center gap-2 mb-6 ml-8">
+ <div className="flex items-center gap-4 mt-3 text-xs text-neutral-400">
+ <div className="flex items-center">
+ <div className="w-3 h-3 bg-emerald-500/70 rounded-sm mr-1"></div>
+ <span>Overall conversion</span>
+ </div>
+ <div className="flex items-center">
+ <div
+ className="w-3 h-3 rounded-sm mr-1"
+ style={{
+ background: `repeating-linear-gradient(
+ 45deg,
+ rgba(16, 185, 129, 0.25),
+ rgba(16, 185, 129, 0.25) 3px,
+ rgba(16, 185, 129, 0.15) 3px,
+ rgba(16, 185, 129, 0.15) 6px
+ )`,
+ }}
+ ></div>
+ <span>Conversion from previous step</span>
+ </div>
+ </div>
<DateSelector time={time} setTime={setTime} />
</div>
@@ -63,105 +85,105 @@ export function Funnel({
</div>
</div>
) : data && chartData.length > 0 ? (
- <div className="space-y-1">
- {/* Overall conversion rate summary */}
- <div className="border border-neutral-800 rounded-md p-4 mb-4 bg-neutral-900/50">
- <div className="text-sm text-neutral-400">Total Conversion</div>
- <div className="text-2xl font-semibold">
- {totalConversionRate.toFixed(2)}%
- </div>
- <div className="text-sm text-neutral-400">
- {lastStep?.visitors.toLocaleString()} out of{" "}
- {firstStep?.visitors.toLocaleString()} users
- </div>
- </div>
-
- {/* Funnel steps list */}
- <div className="space-y-6">
- {chartData.map((step, index) => {
- // Calculate the percentage width for the bar
- const ratio = firstStep?.visitors
- ? step.visitors / firstStep.visitors
- : 0;
- const barWidth = Math.max(ratio * maxBarWidth, 0);
+ <div className="space-y-0">
+ {chartData.map((step, index) => {
+ // Calculate the percentage width for the bar
+ const ratio = firstStep?.visitors
+ ? step.visitors / firstStep.visitors
+ : 0;
+ const barWidth = Math.max(ratio * maxBarWidth, 0);
- // For step 2+, calculate the number of users who dropped off
- const prevStep = index > 0 ? chartData[index - 1] : null;
- const droppedUsers = prevStep
- ? prevStep.visitors - step.visitors
- : 0;
- const dropoffPercent = prevStep
- ? (droppedUsers / prevStep.visitors) * 100
- : 0;
+ // For step 2+, calculate the number of users who dropped off
+ const prevStep = index > 0 ? chartData[index - 1] : null;
+ const droppedUsers = prevStep
+ ? prevStep.visitors - step.visitors
+ : 0;
+ const dropoffPercent = prevStep
+ ? (droppedUsers / prevStep.visitors) * 100
+ : 0;
- return (
- <div key={step.stepNumber} className="relative pb-6">
- {/* Step number indicator */}
- <div className="flex items-center mb-2">
- <div className="flex-shrink-0 w-6 h-6 rounded-full bg-neutral-800 flex items-center justify-center text-xs mr-2">
- {step.stepNumber}
- </div>
- <div className="font-medium text-base">{step.stepName}</div>
+ return (
+ <div key={step.stepNumber} className="relative pb-6">
+ {/* Step number indicator */}
+ <div className="flex items-center mb-2">
+ <div className="flex-shrink-0 w-6 h-6 rounded-full bg-neutral-800 flex items-center justify-center text-xs mr-2">
+ {step.stepNumber}
</div>
+ <div className="font-medium text-base">{step.stepName}</div>
+ </div>
- {/* Bar and metrics */}
- <div className="flex items-center pl-8">
- {/* Metrics */}
- <div className="flex-shrink-0 min-w-[180px] mr-4">
- <div className="flex items-baseline">
- <span className="text-lg font-semibold">
- {step.visitors.toLocaleString()}
- </span>
- <span className="text-sm text-neutral-400 ml-2">
- users
- </span>
- </div>
- <div className="text-sm">
- {index === 0 ? (
- <span className="text-neutral-400">Entry point</span>
- ) : (
- <span className="text-green-500">
- {step.conversionRate.toFixed(2)}% conversion
- </span>
- )}
- </div>
+ {/* Bar and metrics */}
+ <div className="flex items-center pl-8">
+ {/* Metrics */}
+ <div className="flex-shrink-0 min-w-[130px] mr-4">
+ <div className="flex items-baseline">
+ <span className="text-lg font-semibold">
+ {step.visitors.toLocaleString()}
+ </span>
+ <span className="text-sm text-neutral-400 ml-1">
+ users
+ </span>
</div>
+ </div>
- {/* Bar */}
- <div className="flex-grow h-10 bg-neutral-800 rounded-md overflow-hidden">
+ {/* Bar */}
+ <div className="flex-grow h-10 bg-neutral-800 rounded-md overflow-hidden relative">
+ {/* Relative conversion bar (from previous step) */}
+ {index > 0 && prevStep && (
<div
- className="h-full bg-accent-400/70 rounded-md"
- style={{ width: `${barWidth}%` }}
+ className="absolute h-full rounded-md"
+ style={{
+ width: `${
+ (step.visitors / prevStep.visitors) * 100
+ }%`,
+ background: `repeating-linear-gradient(
+ 45deg,
+ rgba(16, 185, 129, 0.25),
+ rgba(16, 185, 129, 0.25) 6px,
+ rgba(16, 185, 129, 0.15) 6px,
+ rgba(16, 185, 129, 0.15) 12px
+ )`,
+ }}
></div>
+ )}
+ {/* Absolute conversion bar (from first step) */}
+ <div
+ className="h-full bg-emerald-500/70 rounded-md relative z-10"
+ style={{ width: `${barWidth}%` }}
+ ></div>
+ <div className="absolute top-2 right-2 z-20">
+ <div className="text-base font-semibold">
+ {round(step.conversionRate, 2)}%
+ </div>
</div>
</div>
+ </div>
- {/* Dropoff indicator */}
- {index < chartData.length - 1 && (
- <div className="absolute left-[11px] -bottom-6 top-6 flex flex-col items-center">
- <div className="h-full w-0.5 bg-neutral-800"></div>
- </div>
- )}
+ {/* Dropoff indicator */}
+ {index < chartData.length - 1 && (
+ <div className="absolute left-[11px] -bottom-6 top-6 flex flex-col items-center">
+ <div className="h-full w-0.5 bg-neutral-800"></div>
+ </div>
+ )}
- {/* Dropoff metrics */}
- {index < chartData.length - 1 && (
- <div className="pl-8 mt-2 flex">
- <div className="min-w-[180px] mr-4">
- <div className="flex items-baseline text-orange-500">
- <span className="text-sm font-medium">
- {droppedUsers.toLocaleString()} dropped off
- </span>
- <span className="text-sm text-neutral-400 ml-1">
+ {/* Dropoff metrics */}
+ {index !== 0 && (
+ <div className="pl-8 flex">
+ <div className="min-w-[180px] mr-4">
+ <div className="flex items-baseline text-orange-500">
+ <span className="text-sm font-medium">
+ {droppedUsers.toLocaleString()} dropped
+ </span>
+ {/* <span className="text-sm text-neutral-400 ml-1">
({dropoffPercent.toFixed(2)}%)
- </span>
- </div>
+ </span> */}
</div>
</div>
- )}
- </div>
- );
- })}
- </div>
+ </div>
+ )}
+ </div>
+ );
+ })}
</div>
) : (
<div className="h-[400px] flex items-center justify-center">