🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Multi hostname (#646)
Bill Yang496c192deeda
diff --git a/client/src/api/analytics/funnels/useGetFunnel.ts b/client/src/api/analytics/funnels/useGetFunnel.tsindex 09a81ac9c..f45a8fda1 100644--- a/client/src/api/analytics/funnels/useGetFunnel.ts+++ b/client/src/api/analytics/funnels/useGetFunnel.ts@@ -9,6 +9,7 @@ export type FunnelStep = {value: string;name?: string;type: "page" | "event";+ hostname?: string;eventPropertyKey?: string;eventPropertyValue?: string | number | boolean;};diff --git a/client/src/app/[site]/funnels/components/FunnelForm.tsx b/client/src/app/[site]/funnels/components/FunnelForm.tsxindex e5faab410..adf49eeb8 100644--- a/client/src/app/[site]/funnels/components/FunnelForm.tsx+++ b/client/src/app/[site]/funnels/components/FunnelForm.tsx@@ -50,7 +50,7 @@ export function FunnelForm({steps.map(step => !!step.eventPropertyKey && step.eventPropertyValue !== undefined));- // Fetch suggestions for paths and events+ // Fetch suggestions for paths, events, and hostnamesconst { data: pathsData } = useSingleCol({parameter: "pathname",limit: 1000,@@ -63,6 +63,12 @@ export function FunnelForm({useFilters: false,});+ const { data: hostnamesData } = useSingleCol({+ parameter: "hostname",+ limit: 1000,+ useFilters: false,+ });+// Transform data into SuggestionOption formatconst pathSuggestions: SuggestionOption[] =pathsData?.data?.map(item => ({@@ -76,6 +82,12 @@ export function FunnelForm({label: item.value,})) || [];+ const hostnameSuggestions: SuggestionOption[] =+ hostnamesData?.data?.map(item => ({+ value: item.value,+ label: item.value,+ })) || [];+// Handle adding a new stepconst addStep = () => {setSteps([...steps, { type: "page", value: "", name: "" }]);@@ -166,7 +178,7 @@ export function FunnelForm({return (<>- <div className="grid grid-cols-[600px_3fr] gap-6 my-4">+ <div className="grid grid-cols-[600px_3fr] gap-6">{/* Left side: Funnel configuration form */}<div className="space-y-4"><div>@@ -178,18 +190,18 @@ export function FunnelForm({<Card className="border border-neutral-200 dark:border-neutral-800"><CardHeader className="p-3 flex flex-row justify-between items-center"><CardTitle className="text-base">Funnel Steps</CardTitle>- <Button onClick={addStep}>+ <Button onClick={addStep} size="sm"><Plus className="mr-2 h-4 w-4" /> Add Step</Button></CardHeader>- <CardContent className="p-3 space-y-4 max-h-[calc(100vh-440px)] overflow-y-auto">+ <CardContent className="p-3 space-y-4 max-h-[calc(100vh-340px)] overflow-y-auto">{steps.map((step, index) => (<divkey={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">+ <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-1.5">{index + 1}</div><Select value={step.type} onValueChange={value => updateStepType(index, value as "page" | "event")}>@@ -203,28 +215,38 @@ export function FunnelForm({</Select><div className="flex-grow space-y-2">- <div>+ <div className="flex gap-2">+ <InputWithSuggestions+ suggestions={hostnameSuggestions}+ placeholder="Hostname (optional)"+ value={step.hostname || ""}+ className="dark:border-neutral-700 w-30"+ onChange={e => updateStep(index, "hostname", e.target.value)}+ /><InputWithSuggestionssuggestions={step.type === "page" ? pathSuggestions : eventSuggestions}placeholder={step.type === "page" ? "Path (e.g. /pricing)" : "Event name"}value={step.value}- className="dark:border-neutral-700"+ className="dark:border-neutral-700 w-56"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>- <Input- placeholder="Label (optional)"- className="dark:border-neutral-700"- value={step.name || ""}- onChange={e => updateStep(index, "name", e.target.value)}- />-+ <div className="flex items-center gap-2">+ <Input+ placeholder="Label (optional)"+ className="dark:border-neutral-700"+ value={step.name || ""}+ onChange={e => updateStep(index, "name", e.target.value)}+ />+ <Button+ variant="ghost"+ size="icon"+ onClick={() => removeStep(index)}+ disabled={steps.length <= 2}+ >+ <Trash2 className="h-4 w-4" />+ </Button>+ </div>{/* Property filtering for event steps */}{step.type === "event" && (<div className="mt-2 space-y-2">@@ -256,10 +278,6 @@ export function FunnelForm({</div>)}</div>-- <Button variant="ghost" size="icon" onClick={() => removeStep(index)} disabled={steps.length <= 2}>- <Trash2 className="h-4 w-4" />- </Button></div></div>))}@@ -270,6 +288,9 @@ export function FunnelForm({</div><div className="flex justify-between items-center">+ <span className="text-xs text-neutral-500 ">+ Use * to match a single path segment (e.g., /blog/*) or ** to match multiple segments (e.g., /docs/**/intro)+ </span><div className="text-sm text-red-500">{(() => {if (isError) {diff --git a/client/src/app/layout.tsx b/client/src/app/layout.tsxindex 29f04e658..8fbc653be 100644--- a/client/src/app/layout.tsx+++ b/client/src/app/layout.tsx@@ -92,7 +92,7 @@ fbq('track', 'PageView');`,<><Scriptsrc="https://demo.rybbit.io/api/script.js"- data-site-id="22"+ data-site-id="21"strategy="afterInteractive"data-web-vitals="true"data-track-errors="true"diff --git a/client/src/components/ui/input-with-suggestions.tsx b/client/src/components/ui/input-with-suggestions.tsxindex c22d802f7..4e859e709 100644--- a/client/src/components/ui/input-with-suggestions.tsx+++ b/client/src/components/ui/input-with-suggestions.tsx@@ -63,7 +63,7 @@ export const InputWithSuggestions = React.forwardRef<HTMLInputElement, InputWith};return (- <div ref={wrapperRef} className="relative w-full">+ <div ref={wrapperRef} className="relative"><Inputref={ref}value={value}diff --git a/client/src/components/ui/label.tsx b/client/src/components/ui/label.tsxindex 25487ccf8..a5af96bfc 100644--- a/client/src/components/ui/label.tsx+++ b/client/src/components/ui/label.tsx@@ -7,7 +7,7 @@ import { cva, type VariantProps } from "class-variance-authority";import { cn } from "@/lib/utils";const labelVariants = cva(- "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 text-neutral-500"+ "text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 text-neutral-400");const Label = React.forwardRef<diff --git a/server/src/api/analytics/funnels/getFunnel.ts b/server/src/api/analytics/funnels/getFunnel.tsindex d16e495eb..13d342744 100644--- a/server/src/api/analytics/funnels/getFunnel.ts+++ b/server/src/api/analytics/funnels/getFunnel.ts@@ -9,6 +9,7 @@ type FunnelStep = {value: string;name?: string;type: "page" | "event";+ hostname?: string;eventPropertyKey?: string;eventPropertyValue?: string | number | boolean;};@@ -55,12 +56,14 @@ export async function getFunnel(// Build conditional statements for each stepconst stepConditions = steps.map(step => {+ let condition = "";+if (step.type === "page") {// Use pattern matching for page paths to support wildcards- return `type = 'pageview' AND match(pathname, ${SqlString.escape(patternToRegex(step.value))})`;+ condition = `type = 'pageview' AND match(pathname, ${SqlString.escape(patternToRegex(step.value))})`;} else {// Start with the base event match condition- let eventClause = `type = 'custom_event' AND event_name = ${SqlString.escape(step.value)}`;+ condition = `type = 'custom_event' AND event_name = ${SqlString.escape(step.value)}`;// Add property matching if both key and value are providedif (step.eventPropertyKey && step.eventPropertyValue !== undefined) {@@ -70,19 +73,24 @@ export async function getFunnel(// Comparison needs to handle the dynamic type returned// Let ClickHouse handle the comparison based on the provided value typeif (typeof step.eventPropertyValue === "string") {- eventClause += ` AND toString(${propValueAccessor}) = ${SqlString.escape(step.eventPropertyValue)}`;+ condition += ` AND toString(${propValueAccessor}) = ${SqlString.escape(step.eventPropertyValue)}`;} else if (typeof step.eventPropertyValue === "number") {// Use toFloat64 or toInt* depending on expected number type- eventClause += ` AND toFloat64OrNull(${propValueAccessor}) = ${SqlString.escape(step.eventPropertyValue)}`;+ condition += ` AND toFloat64OrNull(${propValueAccessor}) = ${SqlString.escape(step.eventPropertyValue)}`;} else if (typeof step.eventPropertyValue === "boolean") {// Booleans might be stored as 0/1 or true/false in JSON// Comparing toUInt8 seems robust- eventClause += ` AND toUInt8OrNull(${propValueAccessor}) = ${step.eventPropertyValue ? 1 : 0}`;+ condition += ` AND toUInt8OrNull(${propValueAccessor}) = ${step.eventPropertyValue ? 1 : 0}`;}}+ }- return eventClause;+ // Add hostname filtering if specified+ if (step.hostname) {+ condition += ` AND hostname = ${SqlString.escape(step.hostname)}`;}++ return condition;});// Build the funnel query - first part to calculate visitors at each step@@ -96,7 +104,8 @@ export async function getFunnel(pathname,event_name,type,- props+ props,+ hostnameFROM eventsWHEREsite_id = {siteId:Int32}