Skip to content

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

Refactor error, event, funnel, goal, journey, map, page, performance, realtime, replay, retention, session, and user components for improved readability and consistency

Bill Yangf04416948a92
diff --git a/client/src/app/[site]/errors/page.tsx b/client/src/app/[site]/errors/page.tsx
index 9924ff71e..2075f5e2e 100644
--- a/client/src/app/[site]/errors/page.tsx
+++ b/client/src/app/[site]/errors/page.tsx
@@ -1,9 +1,6 @@
"use client";
-import {
- ErrorNameItem,
- useGetErrorNamesPaginated,
-} from "@/api/analytics/errors/useGetErrorNames";
+import { ErrorNameItem, useGetErrorNamesPaginated } from "@/api/analytics/errors/useGetErrorNames";
import { Pagination } from "@/components/pagination";
import { useSetPageTitle } from "@/hooks/useSetPageTitle";
import { useStore } from "@/lib/store";
@@ -63,37 +60,23 @@ export default function Errors() {
return (pagination.pageIndex + 1) * pagination.pageSize < totalCount;
},
getPageCount: () => totalPages,
- setPageIndex: (index: number) =>
- setPagination({ ...pagination, pageIndex: index }),
- previousPage: () =>
- setPagination({ ...pagination, pageIndex: pagination.pageIndex - 1 }),
- nextPage: () =>
- setPagination({ ...pagination, pageIndex: pagination.pageIndex + 1 }),
+ setPageIndex: (index: number) => setPagination({ ...pagination, pageIndex: index }),
+ previousPage: () => setPagination({ ...pagination, pageIndex: pagination.pageIndex - 1 }),
+ nextPage: () => setPagination({ ...pagination, pageIndex: pagination.pageIndex + 1 }),
};
useEffect(() => {
if (!isLoadingErrors && !isPlaceholderData && !isFetching) {
if (totalCount !== undefined) {
setTotalPages(Math.ceil(totalCount / pagination.pageSize));
- } else if (
- errorsDataArray &&
- errorsDataArray.length === 0 &&
- pagination.pageIndex === 0
- ) {
+ } else if (errorsDataArray && errorsDataArray.length === 0 && pagination.pageIndex === 0) {
// Fallback if totalCount is somehow undefined but we have an empty array on page 1
setTotalPages(0);
- } else if (
- errorsDataArray &&
- errorsDataArray.length < pagination.pageSize
- ) {
+ } else if (errorsDataArray && errorsDataArray.length < pagination.pageSize) {
// Fallback: if less than a full page is returned, assume it's the last
setTotalPages(pagination.pageIndex + 1);
}
- } else if (
- pagination.pageIndex === 0 &&
- isLoadingErrors &&
- !errorsDataArray
- ) {
+ } else if (pagination.pageIndex === 0 && isLoadingErrors && !errorsDataArray) {
// Initial load, no data yet
setTotalPages(0);
}
@@ -113,7 +96,7 @@ export default function Errors() {
}
return (
- <DisabledOverlay message="errors">
+ <DisabledOverlay message="errors" featurePath="errors">
<div className="p-2 md:p-4 max-w-[1100px] mx-auto space-y-3">
<SubHeader />
<EnableErrorTracking />
@@ -128,10 +111,7 @@ export default function Errors() {
) : errorsDataArray && errorsDataArray.length > 0 ? (
<>
{errorsDataArray.map((errorItem: ErrorNameItem, index: number) => (
- <ErrorListItem
- key={`${errorItem.value}-${index}-${pagination.pageIndex}`}
- errorData={errorItem}
- />
+ <ErrorListItem key={`${errorItem.value}-${index}-${pagination.pageIndex}`} errorData={errorItem} />
))}
{totalPages > 0 && (
<Pagination
@@ -147,9 +127,7 @@ export default function Errors() {
) : !isLoadingErrors && !isFetching ? (
<NothingFound
title={"No error events found"}
- description={
- "Errors will appear here once error tracking is enabled and errors occur on your site."
- }
+ description={"Errors will appear here once error tracking is enabled and errors occur on your site."}
/>
) : null}
</div>
diff --git a/client/src/app/[site]/events/page.tsx b/client/src/app/[site]/events/page.tsx
index be7483f26..d9c40e6fe 100644
--- a/client/src/app/[site]/events/page.tsx
+++ b/client/src/app/[site]/events/page.tsx
@@ -12,11 +12,10 @@ import { EventLog } from "./components/EventLog";
export default function EventsPage() {
useSetPageTitle("Rybbit · Events");
- const { data: eventNamesData, isLoading: isLoadingEventNames } =
- useGetEventNames();
+ const { data: eventNamesData, isLoading: isLoadingEventNames } = useGetEventNames();
return (
- <DisabledOverlay message="Events">
+ <DisabledOverlay message="Events" featurePath="events">
<div className="p-2 md:p-4 max-w-[1300px] mx-auto space-y-3">
<SubHeader availableFilters={EVENT_FILTERS} />
@@ -25,11 +24,7 @@ export default function EventsPage() {
<CardTitle>Custom Events</CardTitle>
</CardHeader>
<CardContent>
- <EventList
- events={eventNamesData || []}
- isLoading={isLoadingEventNames}
- size="large"
- />
+ <EventList events={eventNamesData || []} isLoading={isLoadingEventNames} size="large" />
</CardContent>
</Card>
diff --git a/client/src/app/[site]/funnels/page.tsx b/client/src/app/[site]/funnels/page.tsx
index e8e3c3a1c..f12212940 100644
--- a/client/src/app/[site]/funnels/page.tsx
+++ b/client/src/app/[site]/funnels/page.tsx
@@ -1,9 +1,6 @@
"use client";
-import {
- SavedFunnel,
- useGetFunnels,
-} from "../../../api/analytics/funnels/useGetFunnels";
+import { SavedFunnel, useGetFunnels } from "../../../api/analytics/funnels/useGetFunnels";
import { Skeleton } from "@/components/ui/skeleton";
import { useStore } from "@/lib/store";
import { ArrowRight, FilterIcon } from "lucide-react";
@@ -86,7 +83,7 @@ export default function FunnelsPage() {
}
return (
- <DisabledOverlay message="Funnels">
+ <DisabledOverlay message="Funnels" featurePath="funnels">
<div className="p-2 md:p-4 max-w-[1300px] mx-auto space-y-3">
<div className="flex justify-between items-center mb-3">
<div>
@@ -97,8 +94,7 @@ export default function FunnelsPage() {
{error ? (
<div className="p-4 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 rounded-lg">
- Failed to load funnels:{" "}
- {error instanceof Error ? error.message : "Unknown error"}
+ Failed to load funnels: {error instanceof Error ? error.message : "Unknown error"}
</div>
) : funnels?.length ? (
<div className="space-y-4">
@@ -109,9 +105,7 @@ export default function FunnelsPage() {
) : (
<NothingFound
title={"No funnels yet"}
- description={
- "Create your first funnel to track conversions through your site's user journey"
- }
+ description={"Create your first funnel to track conversions through your site's user journey"}
action={<CreateFunnelDialog />}
/>
)}
diff --git a/client/src/app/[site]/goals/page.tsx b/client/src/app/[site]/goals/page.tsx
index 9628f5b54..6212cfe1c 100644
--- a/client/src/app/[site]/goals/page.tsx
+++ b/client/src/app/[site]/goals/page.tsx
@@ -49,10 +49,7 @@ export default function GoalsPage() {
}
},
nextPage: () => {
- if (
- goalsData?.meta &&
- pagination.pageIndex + 1 < goalsData.meta.totalPages
- ) {
+ if (goalsData?.meta && pagination.pageIndex + 1 < goalsData.meta.totalPages) {
setPagination((prev) => ({ ...prev, pageIndex: prev.pageIndex + 1 }));
window.scrollTo({ top: 0, behavior: "smooth" });
}
@@ -108,7 +105,7 @@ export default function GoalsPage() {
);
return (
- <DisabledOverlay message="Goals">
+ <DisabledOverlay message="Goals" featurePath="goals">
<div className="p-2 md:p-4 max-w-[1400px] mx-auto space-y-3">
<SubHeader availableFilters={GOALS_PAGE_FILTERS} />
<div className="flex items-center justify-between">
@@ -127,9 +124,7 @@ export default function GoalsPage() {
) : !goalsData || goalsData.data.length === 0 ? (
<NothingFound
title={"No goals found"}
- description={
- "Create your first conversion goal to start tracking important user actions."
- }
+ description={"Create your first conversion goal to start tracking important user actions."}
action={<CreateGoalButton siteId={Number(site)} />}
/>
) : (
diff --git a/client/src/app/[site]/journeys/page.tsx b/client/src/app/[site]/journeys/page.tsx
index f84adaa18..6256f94fe 100644
--- a/client/src/app/[site]/journeys/page.tsx
+++ b/client/src/app/[site]/journeys/page.tsx
@@ -3,13 +3,7 @@
import { useJourneys } from "@/api/analytics/useJourneys";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "@/components/ui/select";
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Skeleton } from "@/components/ui/skeleton";
import * as d3 from "d3";
import { AlertCircle } from "lucide-react";
@@ -83,9 +77,7 @@ export default function JourneysPage() {
const sourceKey = stepKey;
const targetKey = `${i + 1}_${journey.path[i + 1]}`;
- const existingLink = links.find(
- (l) => l.source === sourceKey && l.target === targetKey
- );
+ const existingLink = links.find((l) => l.source === sourceKey && l.target === targetKey);
if (existingLink) {
existingLink.value += journey.count;
@@ -104,9 +96,7 @@ export default function JourneysPage() {
const nodesByStep = d3.group(nodes, (d) => d.step);
// Calculate max nodes per step for height calculation
- const maxNodesInAnyStep = Math.max(
- ...Array.from(nodesByStep.values()).map((stepNodes) => stepNodes.length)
- );
+ const maxNodesInAnyStep = Math.max(...Array.from(nodesByStep.values()).map((stepNodes) => stepNodes.length));
// Width calculation that fills available space but doesn't shrink below minimum
const minStepWidth = 300; // Minimum width per step
@@ -164,22 +154,13 @@ export default function JourneysPage() {
// Find the maximum link value for scaling
const maxLinkValue = d3.max(links, (link) => link.value) || 1;
- const linkWidthScale = d3
- .scaleLinear()
- .domain([0, maxLinkValue])
- .range([1, MAX_LINK_HEIGHT]);
+ const linkWidthScale = d3.scaleLinear().domain([0, maxLinkValue]).range([1, MAX_LINK_HEIGHT]);
// Calculate node heights based on connected links
nodes.forEach((node) => {
// Sum the values of incoming and outgoing links
- const incomingValue = node.incomingLinks.reduce(
- (sum: number, link: any) => sum + link.value,
- 0
- );
- const outgoingValue = node.outgoingLinks.reduce(
- (sum: number, link: any) => sum + link.value,
- 0
- );
+ const incomingValue = node.incomingLinks.reduce((sum: number, link: any) => sum + link.value, 0);
+ const outgoingValue = node.outgoingLinks.reduce((sum: number, link: any) => sum + link.value, 0);
// Use the larger value to determine height
const maxValue = Math.max(incomingValue, outgoingValue);
@@ -209,10 +190,7 @@ export default function JourneysPage() {
// Calculate positions for outgoing links
let currentOutY = 0;
- const totalOutgoing = node.outgoingLinks.reduce(
- (sum: number, link: any) => sum + link.value,
- 0
- );
+ const totalOutgoing = node.outgoingLinks.reduce((sum: number, link: any) => sum + link.value, 0);
node.outgoingLinks.forEach((link: any) => {
const linkHeight = linkWidthScale(link.value);
@@ -225,18 +203,14 @@ export default function JourneysPage() {
// Normalize positions to fit within node height
if (totalOutgoing > 0 && node.outgoingLinks.length > 0) {
node.outgoingLinks.forEach((link: any) => {
- link.sourceY =
- (link.sourceY / currentOutY) * node.height - node.height / 2;
+ link.sourceY = (link.sourceY / currentOutY) * node.height - node.height / 2;
link.sourceY += node.y; // Adjust to node position
});
}
// Calculate positions for incoming links
let currentInY = 0;
- const totalIncoming = node.incomingLinks.reduce(
- (sum: number, link: any) => sum + link.value,
- 0
- );
+ const totalIncoming = node.incomingLinks.reduce((sum: number, link: any) => sum + link.value, 0);
node.incomingLinks.forEach((link: any) => {
const linkHeight = linkWidthScale(link.value);
@@ -249,8 +223,7 @@ export default function JourneysPage() {
// Normalize positions to fit within node height
if (totalIncoming > 0 && node.incomingLinks.length > 0) {
node.incomingLinks.forEach((link: any) => {
- link.targetY =
- (link.targetY / currentInY) * node.height - node.height / 2;
+ link.targetY = (link.targetY / currentInY) * node.height - node.height / 2;
link.targetY += node.y; // Adjust to node position
});
}
@@ -303,9 +276,7 @@ export default function JourneysPage() {
.transition()
.duration(200)
.attr("opacity", function () {
- return d3.select(this).attr("data-id") === hoveredLinkId
- ? 0.9
- : 0.1;
+ return d3.select(this).attr("data-id") === hoveredLinkId ? 0.9 : 0.1;
});
// Make all node bars more transparent except the connected ones
@@ -313,9 +284,7 @@ export default function JourneysPage() {
.transition()
.duration(200)
.attr("opacity", function (nodeData: any) {
- return nodeData.id === source?.id || nodeData.id === target?.id
- ? 1
- : 0.2;
+ return nodeData.id === source?.id || nodeData.id === target?.id ? 1 : 0.2;
});
// Make all node cards more transparent except the connected ones
@@ -323,9 +292,7 @@ export default function JourneysPage() {
.transition()
.duration(200)
.attr("opacity", function (nodeData: any) {
- return nodeData.id === source?.id || nodeData.id === target?.id
- ? 0.9
- : 0.2;
+ return nodeData.id === source?.id || nodeData.id === target?.id ? 0.9 : 0.2;
});
// Highlight connected node text
@@ -333,9 +300,7 @@ export default function JourneysPage() {
.transition()
.duration(200)
.attr("opacity", function (nodeData: any) {
- return nodeData.id === source?.id || nodeData.id === target?.id
- ? 1
- : 0.3;
+ return nodeData.id === source?.id || nodeData.id === target?.id ? 1 : 0.3;
});
})
.on("mouseout", function () {
@@ -344,15 +309,9 @@ export default function JourneysPage() {
d3.selectAll(".node-bar").transition().duration(200).attr("opacity", 1);
- d3.selectAll(".node-card")
- .transition()
- .duration(200)
- .attr("opacity", 0.8);
+ d3.selectAll(".node-card").transition().duration(200).attr("opacity", 0.8);
- d3.selectAll(".node-text")
- .transition()
- .duration(200)
- .attr("opacity", 1);
+ d3.selectAll(".node-text").transition().duration(200).attr("opacity", 1);
})
// Add tooltips showing the exact count
.append("title")
@@ -432,21 +391,14 @@ export default function JourneysPage() {
}, [data, steps, maxJourneys, siteMetadata]);
return (
- <DisabledOverlay message="User Journeys">
+ <DisabledOverlay message="User Journeys" featurePath="journeys">
<div className="container mx-auto p-2 md:p-4">
<div className="md:hidden mb-2">
<MobileSidebar />
</div>
<div className="flex justify-end items-center gap-2 mb-2">
- <DateSelector
- time={time}
- setTime={setTime}
- pastMinutesEnabled={false}
- />
- <Select
- value={steps.toString()}
- onValueChange={(value) => setSteps(Number(value))}
- >
+ <DateSelector time={time} setTime={setTime} pastMinutesEnabled={false} />
+ <Select value={steps.toString()} onValueChange={(value) => setSteps(Number(value))}>
<SelectTrigger className="w-[120px]">
<SelectValue placeholder="Number of steps" />
</SelectTrigger>
@@ -458,10 +410,7 @@ export default function JourneysPage() {
))}
</SelectContent>
</Select>
- <Select
- value={maxJourneys.toString()}
- onValueChange={(value) => setMaxJourneys(Number(value))}
- >
+ <Select value={maxJourneys.toString()} onValueChange={(value) => setMaxJourneys(Number(value))}>
<SelectTrigger className="w-[140px]">
<SelectValue placeholder="Max journeys" />
</SelectTrigger>
@@ -489,9 +438,7 @@ export default function JourneysPage() {
<Alert variant="destructive">
<AlertCircle className="h-4 w-4" />
<AlertTitle>Error</AlertTitle>
- <AlertDescription>
- Failed to load journey data. Please try again.
- </AlertDescription>
+ <AlertDescription>Failed to load journey data. Please try again.</AlertDescription>
</Alert>
)}
@@ -499,9 +446,7 @@ export default function JourneysPage() {
<Alert>
<AlertCircle className="h-4 w-4" />
<AlertTitle>No Data</AlertTitle>
- <AlertDescription>
- No journey data found for the selected criteria.
- </AlertDescription>
+ <AlertDescription>No journey data found for the selected criteria.</AlertDescription>
</Alert>
)}
diff --git a/client/src/app/[site]/map/page.tsx b/client/src/app/[site]/map/page.tsx
index 8c34dac3a..ba6c06b05 100644
--- a/client/src/app/[site]/map/page.tsx
+++ b/client/src/app/[site]/map/page.tsx
@@ -14,34 +14,20 @@ export default function MapPage() {
const [mapMode, setMapMode] = useState<"total" | "perCapita">("total");
return (
- <DisabledOverlay message="Map">
+ <DisabledOverlay message="Map" featurePath="map">
<div className="relative w-full h-[calc(100vh-45px)]">
<div className="p-2 md:p-4 relative z-50">
<SubHeader />
</div>
<div className="absolute bottom-2 md:bottom-4 left-2 md:left-4 z-50">
<div className="flex items-center gap-3 bg-neutral-900 rounded-md px-3 py-2 text-sm">
- <span
- className={cn(
- mapMode === "total" ? "text-white" : "text-neutral-400"
- )}
- >
- Total Visits
- </span>
+ <span className={cn(mapMode === "total" ? "text-white" : "text-neutral-400")}>Total Visits</span>
<Switch
checked={mapMode === "perCapita"}
- onCheckedChange={(checked) =>
- setMapMode(checked ? "perCapita" : "total")
- }
+ onCheckedChange={(checked) => setMapMode(checked ? "perCapita" : "total")}
className="data-[state=checked]:bg-accent-400"
/>
- <span
- className={cn(
- mapMode === "perCapita" ? "text-white" : "text-neutral-400"
- )}
- >
- Per Capita
- </span>
+ <span className={cn(mapMode === "perCapita" ? "text-white" : "text-neutral-400")}>Per Capita</span>
</div>
</div>
<div className="absolute top-0 left-0 right-0 bottom-0 z-10">
diff --git a/client/src/app/[site]/pages/page.tsx b/client/src/app/[site]/pages/page.tsx
index f7fa25fbe..6faed036c 100644
--- a/client/src/app/[site]/pages/page.tsx
+++ b/client/src/app/[site]/pages/page.tsx
@@ -1,9 +1,6 @@
"use client";
-import {
- PageTitleItem,
- useGetPageTitlesPaginated,
-} from "@/api/analytics/useGetPageTitles";
+import { PageTitleItem, useGetPageTitlesPaginated } from "@/api/analytics/useGetPageTitles";
import { Pagination } from "@/components/pagination";
import { useSetPageTitle } from "@/hooks/useSetPageTitle";
import { useStore } from "@/lib/store";
@@ -61,37 +58,23 @@ export default function Pages() {
return (pagination.pageIndex + 1) * pagination.pageSize < totalCount;
},
getPageCount: () => totalPages,
- setPageIndex: (index: number) =>
- setPagination({ ...pagination, pageIndex: index }),
- previousPage: () =>
- setPagination({ ...pagination, pageIndex: pagination.pageIndex - 1 }),
- nextPage: () =>
- setPagination({ ...pagination, pageIndex: pagination.pageIndex + 1 }),
+ setPageIndex: (index: number) => setPagination({ ...pagination, pageIndex: index }),
+ previousPage: () => setPagination({ ...pagination, pageIndex: pagination.pageIndex - 1 }),
+ nextPage: () => setPagination({ ...pagination, pageIndex: pagination.pageIndex + 1 }),
};
useEffect(() => {
if (!isLoadingPages && !isPlaceholderData && !isFetching) {
if (totalCount !== undefined) {
setTotalPages(Math.ceil(totalCount / pagination.pageSize));
- } else if (
- pagesDataArray &&
- pagesDataArray.length === 0 &&
- pagination.pageIndex === 0
- ) {
+ } else if (pagesDataArray && pagesDataArray.length === 0 && pagination.pageIndex === 0) {
// Fallback if totalCount is somehow undefined but we have an empty array on page 1
setTotalPages(0);
- } else if (
- pagesDataArray &&
- pagesDataArray.length < pagination.pageSize
- ) {
+ } else if (pagesDataArray && pagesDataArray.length < pagination.pageSize) {
// Fallback: if less than a full page is returned, assume it's the last
setTotalPages(pagination.pageIndex + 1);
}
- } else if (
- pagination.pageIndex === 0 &&
- isLoadingPages &&
- !pagesDataArray
- ) {
+ } else if (pagination.pageIndex === 0 && isLoadingPages && !pagesDataArray) {
// Initial load, no data yet
setTotalPages(0);
}
@@ -111,7 +94,7 @@ export default function Pages() {
}
return (
- <DisabledOverlay message="pages">
+ <DisabledOverlay message="pages" featurePath="pages">
<div className="p-2 md:p-4 max-w-[1100px] mx-auto space-y-3">
<SubHeader />
diff --git a/client/src/app/[site]/performance/page.tsx b/client/src/app/[site]/performance/page.tsx
index 1d49e59b1..eb638c3db 100644
--- a/client/src/app/[site]/performance/page.tsx
+++ b/client/src/app/[site]/performance/page.tsx
@@ -11,7 +11,7 @@ import { useSetPageTitle } from "../../../hooks/useSetPageTitle";
export default function PerformancePage() {
useSetPageTitle("Rybbit · Performance");
return (
- <DisabledOverlay message="Performance">
+ <DisabledOverlay message="Performance" featurePath="performance">
<div className="p-2 md:p-4 max-w-[1100px] mx-auto space-y-3 ">
<SubHeader />
<EnableWebVitals />
diff --git a/client/src/app/[site]/realtime/page.tsx b/client/src/app/[site]/realtime/page.tsx
index 0fd10d29a..ecf9209f2 100644
--- a/client/src/app/[site]/realtime/page.tsx
+++ b/client/src/app/[site]/realtime/page.tsx
@@ -5,13 +5,7 @@ import { useMeasure } from "@uidotdev/usehooks";
import { useAtom } from "jotai";
import { useGetLiveUsercount } from "../../../api/analytics/useLiveUserCount";
import { MobileSidebar } from "../../../components/MobileSidebar";
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "../../../components/ui/select";
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../components/ui/select";
import { useSetPageTitle } from "../../../hooks/useSetPageTitle";
import { RealtimeChart } from "./RealtimeChart/RealtimeChart";
import { RealtimeEvents } from "./RealtimeEvents/RealtimeEvents";
@@ -28,7 +22,7 @@ export default function RealtimePage() {
const { data } = useGetLiveUsercount(Number(minutes));
return (
- <DisabledOverlay message="Realtime">
+ <DisabledOverlay message="Realtime" featurePath="realtime">
<div className="relative overflow-hidden" ref={ref}>
<World width={width ?? 0} />
@@ -44,10 +38,7 @@ export default function RealtimePage() {
</span>
</div>
Visitors in the last{" "}
- <Select
- value={minutes}
- onValueChange={(value) => setMinutes(value as MinutesType)}
- >
+ <Select value={minutes} onValueChange={(value) => setMinutes(value as MinutesType)}>
<SelectTrigger>
<SelectValue placeholder="Select a time period" />
</SelectTrigger>
@@ -65,12 +56,7 @@ export default function RealtimePage() {
</Select>
</div>
<div className="text-3xl md:text-5xl font-bold flex items-center gap-2">
- {
- <NumberFlow
- respectMotionPreference={false}
- value={data?.count ?? 0}
- />
- }
+ {<NumberFlow respectMotionPreference={false} value={data?.count ?? 0} />}
</div>
</div>
<div className="h-[50px] md:h-[70px]">
diff --git a/client/src/app/[site]/replay/page.tsx b/client/src/app/[site]/replay/page.tsx
index 0ed1da286..a6bde15a5 100644
--- a/client/src/app/[site]/replay/page.tsx
+++ b/client/src/app/[site]/replay/page.tsx
@@ -25,27 +25,20 @@ export default function SessionReplayPage() {
const [ref, { height: resolvedHeight, width: resolvedWidth }] = useMeasure();
return (
- <DisabledOverlay message="Replay">
+ <DisabledOverlay message="Replay" featurePath="replay">
<div className="p-2 md:p-4 max-w-[2000px] mx-auto flex flex-col gap-1 overflow-y-hidden">
<SubHeader availableFilters={SESSION_REPLAY_PAGE_FILTERS} />
<EnableSessionReplay />
{hasNoReplays ? (
<NothingFound
title={"No session replays found"}
- description={
- "Replays will appear here once session replay is enabled."
- }
+ description={"Replays will appear here once session replay is enabled."}
/>
) : (
<div className="grid grid-cols-[200px_1fr_300px] gap-3">
<ReplayList />
<div ref={ref} className="w-[calc(min(100vw, 2000px)-780px)]">
- {resolvedWidth && resolvedHeight && (
- <ReplayPlayer
- width={resolvedWidth}
- height={resolvedHeight - 1}
- />
- )}
+ {resolvedWidth && resolvedHeight && <ReplayPlayer width={resolvedWidth} height={resolvedHeight - 1} />}
</div>
<ReplayBreadcrumbs />
</div>
diff --git a/client/src/app/[site]/retention/page.tsx b/client/src/app/[site]/retention/page.tsx
index 086edd0cf..45ba15242 100644
--- a/client/src/app/[site]/retention/page.tsx
+++ b/client/src/app/[site]/retention/page.tsx
@@ -2,25 +2,11 @@
import { DateTime } from "luxon"; // Import Luxon for date formatting
import { Fragment, useMemo, useState } from "react";
-import {
- RetentionMode,
- useGetRetention,
-} from "../../../api/analytics/useGetRetention";
+import { RetentionMode, useGetRetention } from "../../../api/analytics/useGetRetention";
import { ThreeDotLoader } from "../../../components/Loaders";
import { MobileSidebar } from "../../../components/MobileSidebar";
-import {
- Card,
- CardContent,
- CardHeader,
- CardTitle,
-} from "../../../components/ui/card";
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "../../../components/ui/select";
+import { Card, CardContent, CardHeader, CardTitle } from "../../../components/ui/card";
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../../components/ui/select";
import { Tabs, TabsList, TabsTrigger } from "../../../components/ui/tabs";
import { RetentionChart } from "./RetentionChart";
import { NothingFound } from "../../../components/NothingFound";
@@ -39,9 +25,7 @@ const RANGE_OPTIONS = [
];
// Dynamic color function that creates a smooth gradient based on retention percentage
-const getRetentionColor = (
- percentage: number | null
-): { backgroundColor: string; textColor: string } => {
+const getRetentionColor = (percentage: number | null): { backgroundColor: string; textColor: string } => {
if (percentage === null || isNaN(percentage)) {
return {
backgroundColor: "rgb(38, 38, 38)", // bg-neutral-800
@@ -90,10 +74,7 @@ export default function RetentionPage() {
// Get sorted cohort keys (oldest first)
const cohortKeys = useMemo(
- () =>
- data?.cohorts
- ? Object.keys(data.cohorts).sort((a, b) => a.localeCompare(b))
- : [],
+ () => (data?.cohorts ? Object.keys(data.cohorts).sort((a, b) => a.localeCompare(b)) : []),
[data?.cohorts]
);
@@ -108,19 +89,13 @@ export default function RetentionPage() {
// If same month, don't repeat month name
if (startDate.month === endDate.month) {
- return `${startDate.toFormat("MMM dd")} - ${endDate.toFormat(
- "dd, yyyy"
- )}`;
+ return `${startDate.toFormat("MMM dd")} - ${endDate.toFormat("dd, yyyy")}`;
} else if (startDate.year === endDate.year) {
// Different months, same year
- return `${startDate.toFormat("MMM dd")} - ${endDate.toFormat(
- "MMM dd, yyyy"
- )}`;
+ return `${startDate.toFormat("MMM dd")} - ${endDate.toFormat("MMM dd, yyyy")}`;
} else {
// Different years
- return `${startDate.toFormat("MMM dd, yyyy")} - ${endDate.toFormat(
- "MMM dd, yyyy"
- )}`;
+ return `${startDate.toFormat("MMM dd, yyyy")} - ${endDate.toFormat("MMM dd, yyyy")}`;
}
}
};
@@ -146,11 +121,7 @@ export default function RetentionPage() {
</div>
<div className="flex items-center gap-3 flex-wrap justify-end">
<div className="flex items-center gap-2">
- <Select
- value={timeRange.toString()}
- onValueChange={handleRangeChange}
- disabled={isLoading}
- >
+ <Select value={timeRange.toString()} onValueChange={handleRangeChange} disabled={isLoading}>
<SelectTrigger id="time-range">
<SelectValue />
</SelectTrigger>
@@ -184,12 +155,9 @@ export default function RetentionPage() {
<Card>
<CardContent>
<div className="p-8 text-center">
- <div className="text-red-500 mb-2 font-medium">
- Error loading retention data
- </div>
+ <div className="text-red-500 mb-2 font-medium">Error loading retention data</div>
<p className="text-neutral-500 text-sm">
- There was a problem fetching the retention data. Please try
- again later.
+ There was a problem fetching the retention data. Please try again later.
</p>
</div>
</CardContent>
@@ -204,21 +172,17 @@ export default function RetentionPage() {
<div className="p-2 md:p-4 max-w-[1300px] mx-auto flex flex-col gap-3">
<NothingFound
title={"No retention data available"}
- description={
- "Try selecting a different time range or make sure you have tracking data in the system."
- }
+ description={"Try selecting a different time range or make sure you have tracking data in the system."}
/>
</div>
);
}
const periodHeaders =
- !isLoading && data
- ? Array.from({ length: data.maxPeriods + 1 }, (_, i) => getPeriodLabel(i))
- : [];
+ !isLoading && data ? Array.from({ length: data.maxPeriods + 1 }, (_, i) => getPeriodLabel(i)) : [];
return (
- <DisabledOverlay message="Retention">
+ <DisabledOverlay message="Retention" featurePath="retention">
<div className="p-2 md:p-4 max-w-[1300px] mx-auto flex flex-col gap-3">
{/* Single Card containing both chart and grid */}
<FilterControls />
@@ -244,9 +208,7 @@ export default function RetentionPage() {
<div
className="inline-grid gap-px bg-neutral-900 rounded-lg shadow-lg"
style={{
- gridTemplateColumns: `minmax(120px, auto) repeat(${
- data.maxPeriods + 1
- }, minmax(80px, auto))`,
+ gridTemplateColumns: `minmax(120px, auto) repeat(${data.maxPeriods + 1}, minmax(80px, auto))`,
}}
>
{/* Header Row */}
@@ -267,35 +229,27 @@ export default function RetentionPage() {
<Fragment key={cohortPeriod}>
{/* Cohort Info Cell */}
<div className="py-2 px-2 bg-neutral-900 text-sm sticky left-0 z-10 border-r border-neutral-800">
- <div className="whitespace-nowrap text-neutral-100">
- {formatDate(cohortPeriod)}
- </div>
+ <div className="whitespace-nowrap text-neutral-100">{formatDate(cohortPeriod)}</div>
<div className="text-xs text-neutral-300 mt-1 whitespace-nowrap">
- {data.cohorts[cohortPeriod].size.toLocaleString()}{" "}
- users
+ {data.cohorts[cohortPeriod].size.toLocaleString()} users
</div>
</div>
{/* Retention Cells */}
- {data.cohorts[cohortPeriod].percentages.map(
- (percentage: number | null, index: number) => {
- const { backgroundColor, textColor } =
- getRetentionColor(percentage);
- return (
- <div
- key={`${cohortPeriod}-period-${index}`}
- className="m-[2px] text-center flex items-center justify-center font-medium transition-colors duration-150 bg-neutral-900 rounded-md"
- style={{
- backgroundColor,
- color: textColor,
- }}
- >
- {percentage !== null
- ? `${percentage.toFixed(1)}%`
- : "-"}
- </div>
- );
- }
- )}
+ {data.cohorts[cohortPeriod].percentages.map((percentage: number | null, index: number) => {
+ const { backgroundColor, textColor } = getRetentionColor(percentage);
+ return (
+ <div
+ key={`${cohortPeriod}-period-${index}`}
+ className="m-[2px] text-center flex items-center justify-center font-medium transition-colors duration-150 bg-neutral-900 rounded-md"
+ style={{
+ backgroundColor,
+ color: textColor,
+ }}
+ >
+ {percentage !== null ? `${percentage.toFixed(1)}%` : "-"}
+ </div>
+ );
+ })}
</Fragment>
))}
</div>
diff --git a/client/src/app/[site]/sessions/page.tsx b/client/src/app/[site]/sessions/page.tsx
index 842e08e7c..73880116b 100644
--- a/client/src/app/[site]/sessions/page.tsx
+++ b/client/src/app/[site]/sessions/page.tsx
@@ -10,7 +10,7 @@ export default function SessionsPage() {
useSetPageTitle("Rybbit · Sessions");
return (
- <DisabledOverlay message="Sessions">
+ <DisabledOverlay message="Sessions" featurePath="sessions">
<div className="p-2 md:p-4 max-w-[1300px] mx-auto space-y-3">
<SubHeader availableFilters={SESSION_PAGE_FILTERS} />
<SessionsList />
diff --git a/client/src/app/[site]/users/page.tsx b/client/src/app/[site]/users/page.tsx
index a14e6114a..4a7e1a014 100644
--- a/client/src/app/[site]/users/page.tsx
+++ b/client/src/app/[site]/users/page.tsx
@@ -9,14 +9,7 @@ import {
SortingState,
useReactTable,
} from "@tanstack/react-table";
-import {
- ArrowDown,
- ArrowUp,
- ArrowUpDown,
- Monitor,
- Smartphone,
- Tablet,
-} from "lucide-react";
+import { ArrowDown, ArrowUp, ArrowUpDown, Monitor, Smartphone, Tablet } from "lucide-react";
import { DateTime } from "luxon";
import Link from "next/link";
import { useParams } from "next/navigation";
@@ -24,12 +17,7 @@ import { useState } from "react";
import { useGetUsers, UsersResponse } from "../../../api/analytics/users";
import { Button } from "../../../components/ui/button";
import { Pagination } from "../../../components/pagination";
-import {
- Tooltip,
- TooltipContent,
- TooltipProvider,
- TooltipTrigger,
-} from "../../../components/ui/tooltip";
+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../../../components/ui/tooltip";
import { useSetPageTitle } from "../../../hooks/useSetPageTitle";
import { USER_PAGE_FILTERS } from "../../../lib/store";
import { getCountryName } from "../../../lib/utils";
@@ -77,9 +65,7 @@ export default function UsersPage() {
pageIndex: 0,
pageSize: 50,
});
- const [sorting, setSorting] = useState<SortingState>([
- { id: "last_seen", desc: true },
- ]);
+ const [sorting, setSorting] = useState<SortingState>([{ id: "last_seen", desc: true }]);
// Convert page index to 1-based for the API
const page = pagination.pageIndex + 1;
@@ -131,16 +117,10 @@ export default function UsersPage() {
<CountryFlag country={info.getValue() || ""} />
</TooltipTrigger>
<TooltipContent>
- <p>
- {info.getValue()
- ? getCountryName(info.getValue())
- : "Unknown"}
- </p>
+ <p>{info.getValue() ? getCountryName(info.getValue()) : "Unknown"}</p>
</TooltipContent>
</Tooltip>
- {info.row.original.city ||
- info.row.original.region ||
- getCountryName(info.getValue())}
+ {info.row.original.city || info.row.original.region || getCountryName(info.getValue())}
</div>
);
},
@@ -177,35 +157,19 @@ export default function UsersPage() {
},
}),
columnHelper.accessor("pageviews", {
- header: ({ column }) => (
- <SortHeader column={column}>Pageviews</SortHeader>
- ),
- cell: (info) => (
- <div className="whitespace-nowrap">
- {info.getValue().toLocaleString()}
- </div>
- ),
+ header: ({ column }) => <SortHeader column={column}>Pageviews</SortHeader>,
+ cell: (info) => <div className="whitespace-nowrap">{info.getValue().toLocaleString()}</div>,
}),
columnHelper.accessor("events", {
header: ({ column }) => <SortHeader column={column}>Events</SortHeader>,
- cell: (info) => (
- <div className="whitespace-nowrap">
- {info.getValue().toLocaleString()}
- </div>
- ),
+ cell: (info) => <div className="whitespace-nowrap">{info.getValue().toLocaleString()}</div>,
}),
columnHelper.accessor("sessions", {
header: ({ column }) => <SortHeader column={column}>Sessions</SortHeader>,
- cell: (info) => (
- <div className="whitespace-nowrap">
- {info.getValue().toLocaleString()}
- </div>
- ),
+ cell: (info) => <div className="whitespace-nowrap">{info.getValue().toLocaleString()}</div>,
}),
columnHelper.accessor("last_seen", {
- header: ({ column }) => (
- <SortHeader column={column}>Last Seen</SortHeader>
- ),
+ header: ({ column }) => <SortHeader column={column}>Last Seen</SortHeader>,
cell: (info) => {
const date = DateTime.fromSQL(info.getValue(), {
zone: "utc",
@@ -228,9 +192,7 @@ export default function UsersPage() {
},
}),
columnHelper.accessor("first_seen", {
- header: ({ column }) => (
- <SortHeader column={column}>First Seen</SortHeader>
- ),
+ header: ({ column }) => <SortHeader column={column}>First Seen</SortHeader>,
cell: (info) => {
const date = DateTime.fromSQL(info.getValue(), {
zone: "utc",
@@ -258,9 +220,7 @@ export default function UsersPage() {
const table = useReactTable({
data: data?.data || [],
columns,
- pageCount: data?.totalCount
- ? Math.ceil(data.totalCount / pagination.pageSize)
- : -1,
+ pageCount: data?.totalCount ? Math.ceil(data.totalCount / pagination.pageSize) : -1,
state: {
pagination,
sorting,
@@ -276,15 +236,11 @@ export default function UsersPage() {
});
if (isError) {
- return (
- <div className="p-8 text-center text-red-500">
- An error occurred while fetching users data.
- </div>
- );
+ return <div className="p-8 text-center text-red-500">An error occurred while fetching users data.</div>;
}
return (
- <DisabledOverlay>
+ <DisabledOverlay message="Users" featurePath="users">
<div className="p-2 md:p-4 max-w-[1400px] mx-auto space-y-3">
<SubHeader availableFilters={USER_PAGE_FILTERS} />
<div className="rounded-md border border-neutral-800 bg-neutral-900">
@@ -302,12 +258,7 @@ export default function UsersPage() {
minWidth: header.id === "user_id" ? "100px" : "auto",
}}
>
- {header.isPlaceholder
- ? null
- : flexRender(
- header.column.columnDef.header,
- header.getContext()
- )}
+ {header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
</th>
))}
</tr>
@@ -316,25 +267,17 @@ export default function UsersPage() {
<tbody>
{isLoading ? (
Array.from({ length: 15 }).map((_, index) => (
- <tr
- key={index}
- className="border-b border-neutral-800 animate-pulse"
- >
- {Array.from({ length: columns.length }).map(
- (_, cellIndex) => (
- <td key={cellIndex} className="px-3 py-3">
- <div className="h-4 bg-neutral-800 rounded"></div>
- </td>
- )
- )}
+ <tr key={index} className="border-b border-neutral-800 animate-pulse">
+ {Array.from({ length: columns.length }).map((_, cellIndex) => (
+ <td key={cellIndex} className="px-3 py-3">
+ <div className="h-4 bg-neutral-800 rounded"></div>
+ </td>
+ ))}
</tr>
))
) : table.getRowModel().rows.length === 0 ? (
<tr>
- <td
- colSpan={columns.length}
- className="px-3 py-8 text-center text-neutral-400"
- >
+ <td colSpan={columns.length} className="px-3 py-8 text-center text-neutral-400">
No users found
</td>
</tr>
@@ -344,10 +287,7 @@ export default function UsersPage() {
const href = `/${site}/user/${userId}`;
return (
- <tr
- key={row.id}
- className="border-b border-neutral-800 group"
- >
+ <tr key={row.id} className="border-b border-neutral-800 group">
{row.getVisibleCells().map((cell) => (
<td key={cell.id} className="px-3 py-3 relative">
{/* <Link
@@ -358,10 +298,7 @@ export default function UsersPage() {
<span className="sr-only">View user details</span>
</Link> */}
<span className="relative z-0">
- {flexRender(
- cell.column.columnDef.cell,
- cell.getContext()
- )}
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
</span>
</td>
))}
diff --git a/client/src/components/DisabledOverlay.tsx b/client/src/components/DisabledOverlay.tsx
index 37d4533d0..f4ec5b9b0 100644
--- a/client/src/components/DisabledOverlay.tsx
+++ b/client/src/components/DisabledOverlay.tsx
@@ -1,4 +1,4 @@
-import { ArrowRight, Crown } from "lucide-react";
+import { ArrowRight, Crown, ExternalLink } from "lucide-react";
import Link from "next/link";
import React, { ReactNode } from "react";
import { useCurrentSite } from "../api/admin/sites";
@@ -9,39 +9,64 @@ import { authClient } from "../lib/auth";
interface DisabledOverlayProps {
children: ReactNode;
message?: string;
+ featurePath?: string;
blur?: number;
borderRadius?: number;
showMessage?: boolean;
style?: React.CSSProperties;
}
-function ownerMessage(message: string) {
+function ownerMessage(message: string, featurePath?: string) {
return (
- <div className="bg-neutral-900 rounded-lg border border-neutral-700 shadow-xl flex items-center gap-3 p-4">
- <Crown className="h-5 w-5 text-amber-500 flex-shrink-0" />
- <div className="flex-1">
- <p className="text-sm text-muted-foreground">
- Upgrade to <span className="font-medium text-foreground">Pro</span> to unlock {message}
- </p>
+ <div className="bg-neutral-900 rounded-lg border border-neutral-700 shadow-xl flex flex-col gap-3 p-4">
+ <div className="flex gap-3">
+ <Crown className="h-5 w-5 text-amber-500 flex-shrink-0" />
+ <div className="flex-1 space-y-1">
+ <p className="text-sm text-muted-foreground">
+ Upgrade to <span className="font-medium text-foreground">Pro</span> to unlock {message}
+ </p>
+ {featurePath && (
+ <Link
+ href={`https://demo.rybbit.io/21/${featurePath}`}
+ target="_blank"
+ className="text-sm text-neutral-100 hover:underline flex items-center gap-1"
+ >
+ See a demo of this feature
+ <ExternalLink className="ml-1 h-4 w-4" />
+ </Link>
+ )}
+ </div>
+ <Button asChild size="sm" variant="success">
+ <Link href="/subscribe">
+ Upgrade <ArrowRight className="h-3 w-3" />
+ </Link>
+ </Button>
</div>
- <Button asChild size="sm" variant="success">
- <Link href="/subscribe">
- Upgrade <ArrowRight className="ml-1 h-3 w-3" />
- </Link>
- </Button>
</div>
);
}
-function userMessage(message: string) {
+function userMessage(message: string, featurePath?: string) {
return (
- <div className="bg-neutral-900 rounded-lg border border-neutral-700 shadow-xl flex items-center gap-3 p-4">
- <Crown className="h-5 w-5 text-amber-500 flex-shrink-0" />
- <div className="flex-1">
- <p className="text-sm text-muted-foreground">
- Ask your organization owner to upgrade to <span className="font-medium text-foreground">Pro</span> to unlock{" "}
- {message}
- </p>
+ <div className="bg-neutral-900 rounded-lg border border-neutral-700 shadow-xl flex flex-col gap-3 p-4">
+ <div className="flex gap-3">
+ <Crown className="h-5 w-5 text-amber-500 flex-shrink-0" />
+ <div className="flex-1 space-y-1">
+ <p className="text-sm text-muted-foreground">
+ Ask your organization owner to upgrade to <span className="font-medium text-foreground">Pro</span> to unlock{" "}
+ {message}
+ </p>
+ {featurePath && (
+ <Link
+ href={`https://demo.rybbit.io/21/${featurePath}`}
+ target="_blank"
+ className="text-sm text-neutral-100 hover:underline flex items-center gap-1"
+ >
+ See a demo of this feature
+ <ExternalLink className="h-4 w-4" />
+ </Link>
+ )}
+ </div>
</div>
</div>
);
@@ -50,6 +75,7 @@ function userMessage(message: string) {
export const DisabledOverlay: React.FC<DisabledOverlayProps> = ({
children,
message = "this feature",
+ featurePath,
blur = 10,
borderRadius = 0,
showMessage = true,
@@ -75,7 +101,7 @@ export const DisabledOverlay: React.FC<DisabledOverlayProps> = ({
<div className="absolute inset-0 flex items-center justify-center z-10" style={borderRadiusStyle}>
{showMessage && (
<div className="flex items-center justify-center">
- {site?.isOwner ? ownerMessage(message) : userMessage(message)}
+ {site?.isOwner ? ownerMessage(message, featurePath) : userMessage(message, featurePath)}
</div>
)}
</div>