🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance FunnelForm component layout and functionality
Bill Yangfb31a0c16038
diff --git a/client/src/app/[site]/funnels/components/FunnelForm.tsx b/client/src/app/[site]/funnels/components/FunnelForm.tsxindex c216527dd..2a81c1d37 100644--- a/client/src/app/[site]/funnels/components/FunnelForm.tsx+++ b/client/src/app/[site]/funnels/components/FunnelForm.tsx@@ -156,7 +156,7 @@ export function FunnelForm({return (<>- <div className="grid grid-cols-[550px_3fr] gap-6 my-4">+ <div className="grid grid-cols-[600px_3fr] gap-6 my-4">{/* Left side: Funnel configuration form */}<div className="space-y-4"><div>@@ -172,14 +172,17 @@ export function FunnelForm({{/* Funnel Steps in a boxed container */}<Card className="border border-neutral-200 dark:border-neutral-800">- <CardHeader className="px-4 py-3">+ <CardHeader className="p-3"><CardTitle className="text-base">Funnel Steps</CardTitle></CardHeader>- <CardContent className="px-4 py-3 space-y-4">+ <CardContent className="p-3 space-y-4">{steps.map((step, index) => (- <div key={index} className="flex flex-col space-y-2">- <div className="flex items-center gap-2">- <div className="flex-shrink-0 w-6 h-6 rounded-full bg-neutral-800 flex items-center justify-center text-xs">+ <div+ key={index}+ className="flex flex-col space-y-2 border border-neutral-750 p-4 rounded-lg bg-neutral-850"+ >+ <div className="flex items-start gap-2">+ <div className="flex-shrink-0 w-6 h-6 rounded-full border border-neutral-400 bg-neutral-750 flex items-center justify-center text-xs mt-2">{index + 1}</div><Select@@ -188,29 +191,40 @@ export function FunnelForm({updateStepType(index, value as "page" | "event")}>- <SelectTrigger className="w-[120px]">+ <SelectTrigger className="min-w-[80px] max-w-[80px] dark:border-neutral-700"><SelectValue placeholder="Type" /></SelectTrigger><SelectContent>- <SelectItem value="page">Page Path</SelectItem>+ <SelectItem value="page">Path</SelectItem><SelectItem value="event">Event</SelectItem></SelectContent></Select>- <div className="flex-grow flex gap-2">- <Input- placeholder={- step.type === "page"- ? "Path (e.g. /pricing)"- : "Event name"- }- value={step.value}- onChange={(e) =>- updateStep(index, "value", e.target.value)- }- />+ <div className="flex-grow space-y-2">+ <div>+ <Input+ placeholder={+ step.type === "page"+ ? "Path (e.g. /pricing)"+ : "Event name"+ }+ value={step.value}+ className="dark:border-neutral-700"+ onChange={(e) =>+ updateStep(index, "value", e.target.value)+ }+ />+ {step.type === "page" && (+ <div className="text-xs text-neutral-500 mt-1">+ Use * to match a single path segment (e.g., /blog/*)+ or ** to match multiple segments (e.g.,+ /docs/**/intro)+ </div>+ )}+ </div><Inputplaceholder="Label (optional)"+ className="dark:border-neutral-700"value={step.name || ""}onChange={(e) =>updateStep(index, "name", e.target.value)@@ -230,7 +244,7 @@ export function FunnelForm({</div>))}- <Button variant="outline" onClick={addStep} className="w-full">+ <Button onClick={addStep} className="w-full"><Plus className="mr-2 h-4 w-4" /> Add Step</Button></CardContent>@@ -238,7 +252,7 @@ export function FunnelForm({{/* Filters Section */}<Card className="border border-neutral-200 dark:border-neutral-800">- <CardHeader className="px-4 py-3 flex flex-row justify-between items-center">+ <CardHeader className="p-3 flex flex-row justify-between items-center"><CardTitle className="text-base">Funnel Filters</CardTitle>{!showFilters && (<Button variant="outline" size="sm" onClick={addFilter}>@@ -248,7 +262,7 @@ export function FunnelForm({)}</CardHeader>{showFilters && (- <CardContent className="px-4 py-3 space-y-4">+ <CardContent className="p-3 space-y-4"><div className="flex flex-col gap-2">{filters.map((filter, index) => (<FilterComponentdiff --git a/client/src/app/[site]/goals/page.tsx b/client/src/app/[site]/goals/page.tsxindex 9a15fa470..1d2ffdfaa 100644--- a/client/src/app/[site]/goals/page.tsx+++ b/client/src/app/[site]/goals/page.tsx@@ -7,7 +7,6 @@ import { SESSION_PAGE_FILTERS, useStore } from "../../../lib/store";import { SubHeader } from "../components/SubHeader/SubHeader";import CreateGoalButton from "./components/CreateGoalButton";import GoalsList from "./components/GoalsList";-import { ThreeDotLoader } from "../../../components/Loaders";export default function GoalsPage() {const { time, filters, site, setTime } = useStore();diff --git a/server/src/api/analytics/getFunnel.ts b/server/src/api/analytics/getFunnel.tsindex 363f7d525..4c3c91af6 100644--- a/server/src/api/analytics/getFunnel.ts+++ b/server/src/api/analytics/getFunnel.ts@@ -5,6 +5,7 @@ import {getTimeStatement,processResults,getFilterStatement,+ patternToRegex,} from "./utils.js";import { getUserHasAccessToSitePublic } from "../../lib/auth-utils.js";import SqlString from "sqlstring";@@ -78,7 +79,10 @@ export async function getFunnel(// Build conditional statements for each stepconst stepConditions = steps.map((step) => {if (step.type === "page") {- return `pathname = ${SqlString.escape(step.value)}`;+ // Use pattern matching for page paths to support wildcards+ return `type = 'pageview' AND match(pathname, ${SqlString.escape(+ patternToRegex(step.value)+ )})`;} else {return `type = 'custom_event' AND event_name = ${SqlString.escape(step.valuediff --git a/server/src/api/analytics/getGoal.ts b/server/src/api/analytics/getGoal.tsindex 27ac62568..a490658e0 100644--- a/server/src/api/analytics/getGoal.ts+++ b/server/src/api/analytics/getGoal.ts@@ -8,27 +8,10 @@ import {getFilterStatement,getTimeStatement,processResults,+ patternToRegex,} from "./utils.js";import SqlString from "sqlstring";-// Helper to convert wildcard patterns to ClickHouse regex (same as in getGoals.ts)-function patternToRegex(pattern: string): string {- // Escape special regex characters except * which we'll handle specially- const escapedPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");-- // Replace ** with a temporary marker- const withDoubleStar = escapedPattern.replace(/\*\*/g, "{{DOUBLE_STAR}}");-- // Replace * with [^/]+ (any characters except /)- const withSingleStar = withDoubleStar.replace(/\*/g, "[^/]+");-- // Replace the double star marker with .* (any characters including /)- const finalRegex = withSingleStar.replace(/{{DOUBLE_STAR}}/g, ".*");-- // Anchor the regex to start/end of string for exact matches- return `^${finalRegex}$`;-}-export async function getGoal(request: FastifyRequest<{Params: {diff --git a/server/src/api/analytics/getGoals.ts b/server/src/api/analytics/getGoals.tsindex af3a04e4e..247d6c1ae 100644--- a/server/src/api/analytics/getGoals.ts+++ b/server/src/api/analytics/getGoals.ts@@ -8,27 +8,10 @@ import {getFilterStatement,getTimeStatement,processResults,+ patternToRegex,} from "./utils.js";import SqlString from "sqlstring";-// Helper to convert wildcard patterns to ClickHouse regex-function patternToRegex(pattern: string): string {- // Escape special regex characters except * which we'll handle specially- const escapedPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");-- // Replace ** with a temporary marker- const withDoubleStar = escapedPattern.replace(/\*\*/g, "{{DOUBLE_STAR}}");-- // Replace * with [^/]+ (any characters except /)- const withSingleStar = withDoubleStar.replace(/\*/g, "[^/]+");-- // Replace the double star marker with .* (any characters including /)- const finalRegex = withSingleStar.replace(/{{DOUBLE_STAR}}/g, ".*");-- // Anchor the regex to start/end of string for exact matches- return `^${finalRegex}$`;-}-// Types for the responseinterface GoalWithConversions {goalId: number;diff --git a/server/src/api/analytics/utils.ts b/server/src/api/analytics/utils.tsindex 62e07d2ca..37e17431b 100644--- a/server/src/api/analytics/utils.ts+++ b/server/src/api/analytics/utils.ts@@ -214,3 +214,27 @@ export function getFilterStatement(filters: string) {.join(" AND "));}++/**+ * Converts wildcard path patterns to ClickHouse regex pattern+ * - Supports * for matching a single path segment (not including /)+ * - Supports ** for matching multiple path segments (including /)+ * @param pattern Path pattern with wildcards+ * @returns ClickHouse-compatible regex string+ */+export function patternToRegex(pattern: string): string {+ // Escape special regex characters except * which we'll handle specially+ const escapedPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");++ // Replace ** with a temporary marker+ const withDoubleStar = escapedPattern.replace(/\*\*/g, "{{DOUBLE_STAR}}");++ // Replace * with [^/]+ (any characters except /)+ const withSingleStar = withDoubleStar.replace(/\*/g, "[^/]+");++ // Replace the double star marker with .* (any characters including /)+ const finalRegex = withSingleStar.replace(/{{DOUBLE_STAR}}/g, ".*");++ // Anchor the regex to start/end of string for exact matches+ return `^${finalRegex}$`;+}