Skip to content

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

Enhance session replay functionality with minDuration filter and UI improvements

Bill Yange93ae6c8060f
diff --git a/client/src/api/analytics/sessionReplay/useGetSessionReplays.ts b/client/src/api/analytics/sessionReplay/useGetSessionReplays.ts
index 380b93158..6011dbf34 100644
--- a/client/src/api/analytics/sessionReplay/useGetSessionReplays.ts
+++ b/client/src/api/analytics/sessionReplay/useGetSessionReplays.ts
@@ -29,21 +29,24 @@ export interface SessionReplayListResponse {
type UseGetSessionReplaysOptions = {
limit?: number;
+ minDuration?: number;
};
export function useGetSessionReplays({
limit = 20,
+ minDuration = 30,
}: UseGetSessionReplaysOptions = {}) {
const { time, site, filters } = useStore();
return useInfiniteQuery({
- queryKey: ["session-replays", site, time, filters, limit],
+ queryKey: ["session-replays", site, time, filters, limit, minDuration],
queryFn: async ({ pageParam = 0 }) => {
const queryParams = {
...getQueryParams(time),
limit,
offset: pageParam,
filters,
+ minDuration,
};
const response = await authedFetch<SessionReplayListResponse>(
@@ -63,4 +66,4 @@ export function useGetSessionReplays({
staleTime: 1000 * 60 * 5, // 5 minutes
refetchOnWindowFocus: false,
});
-}
\ No newline at end of file
+}
diff --git a/client/src/app/[site]/replay/components/EnableSessionReplay.tsx b/client/src/app/[site]/replay/components/EnableSessionReplay.tsx
index bba7f6d7f..257ee09f1 100644
--- a/client/src/app/[site]/replay/components/EnableSessionReplay.tsx
+++ b/client/src/app/[site]/replay/components/EnableSessionReplay.tsx
@@ -15,7 +15,7 @@ export function EnableSessionReplay() {
data: replayData,
isLoading,
isError,
- } = useGetSessionReplays({ limit: 1 });
+ } = useGetSessionReplays({ limit: 1, minDuration: 0 });
// Don't show banner while loading or if there's an error
if (isLoading || isError) return null;
diff --git a/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx b/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx
index b3e7d946a..e6a986bdd 100644
--- a/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx
+++ b/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx
@@ -190,23 +190,40 @@ export function ReplayBreadcrumbs() {
// Special icons for specific incremental snapshot types
if (eventTypeStr === "3" && event.data?.source !== undefined) {
switch (event.data.source) {
- case 0: return FileEdit; // Mutation
- case 1: return Mouse; // Mouse Move
- case 2: return MousePointerClick; // Mouse Interaction
- case 3: return ScrollText; // Scroll
- case 4: return Maximize2; // Viewport Resize
- case 5: return Keyboard; // Input
- case 6: return Smartphone; // Touch Move
- case 7: return Play; // Media Interaction
- case 8: return Palette; // Style Sheet Rule
- case 9: return Brush; // Canvas Mutation
- case 10: return Type; // Font
- case 11: return Terminal; // Log
- case 12: return Move; // Drag
- case 13: return PaintBucket; // Style Declaration
- case 14: return TextSelect; // Selection
- case 15: return FileCode; // Adopted Style Sheet
- default: return MousePointer; // Fallback
+ case 0:
+ return FileEdit; // Mutation
+ case 1:
+ return Mouse; // Mouse Move
+ case 2:
+ return MousePointerClick; // Mouse Interaction
+ case 3:
+ return ScrollText; // Scroll
+ case 4:
+ return Maximize2; // Viewport Resize
+ case 5:
+ return Keyboard; // Input
+ case 6:
+ return Smartphone; // Touch Move
+ case 7:
+ return Play; // Media Interaction
+ case 8:
+ return Palette; // Style Sheet Rule
+ case 9:
+ return Brush; // Canvas Mutation
+ case 10:
+ return Type; // Font
+ case 11:
+ return Terminal; // Log
+ case 12:
+ return Move; // Drag
+ case 13:
+ return PaintBucket; // Style Declaration
+ case 14:
+ return TextSelect; // Selection
+ case 15:
+ return FileCode; // Adopted Style Sheet
+ default:
+ return MousePointer; // Fallback
}
}
diff --git a/client/src/app/[site]/replay/components/ReplayList.tsx b/client/src/app/[site]/replay/components/ReplayList.tsx
index c67c9e855..ac24d40c1 100644
--- a/client/src/app/[site]/replay/components/ReplayList.tsx
+++ b/client/src/app/[site]/replay/components/ReplayList.tsx
@@ -9,9 +9,11 @@ import {
} from "../../../../api/analytics/sessionReplay/useGetSessionReplays";
import { useReplayStore } from "./replayStore";
import { ScrollArea } from "../../../../components/ui/scroll-area";
+import { Input } from "../../../../components/ui/input";
export function ReplayList() {
- const { sessionId, setSessionId } = useReplayStore();
+ const { sessionId, setSessionId, minDuration, setMinDuration } =
+ useReplayStore();
const {
data,
@@ -20,7 +22,7 @@ export function ReplayList() {
fetchNextPage,
hasNextPage,
isFetchingNextPage,
- } = useGetSessionReplays();
+ } = useGetSessionReplays({ minDuration });
// Use the intersection observer hook for infinite scroll
const [ref, entry] = useIntersectionObserver({
@@ -65,45 +67,62 @@ export function ReplayList() {
}
return (
- <div className="rounded-lg border border-neutral-800 flex flex-col">
- <ScrollArea className="h-[calc(100vh-123px)]">
- {isLoading ? (
- Array.from({ length: 20 }).map((_, index) => (
- <ReplayCardSkeleton key={`loading-${index}`} />
- ))
- ) : flattenedData.length === 0 ? (
- <NothingFound
- title={"No session replays found"}
- description={"Try a different date range or filter"}
- />
- ) : (
- <>
- {flattenedData.map((replay: SessionReplayListItem, index) => (
- <ReplayCard
- key={`${replay.session_id}-${index}`}
- replay={replay}
- />
- ))}
+ <div className="flex flex-col gap-2">
+ <div className="rounded-lg border border-neutral-800 bg-neutral-900 flex flex-col">
+ <div className="flex items-center gap-2 p-2">
+ <div className="text-xs text-neutral-400">Min Duration</div>
+ <div className="flex items-center gap-1">
+ <Input
+ type="number"
+ value={minDuration}
+ inputSize="sm"
+ onChange={(e) => setMinDuration(Number(e.target.value))}
+ className="w-16"
+ />
+ <div className="text-xs text-neutral-400">s</div>
+ </div>
+ </div>
+ </div>
+ <div className="rounded-lg border border-neutral-800 flex flex-col">
+ <ScrollArea className="h-[calc(100vh-178px)]">
+ {isLoading ? (
+ Array.from({ length: 20 }).map((_, index) => (
+ <ReplayCardSkeleton key={`loading-${index}`} />
+ ))
+ ) : flattenedData.length === 0 ? (
+ <NothingFound
+ title={"No session replays found"}
+ description={"Try a different date range or filter"}
+ />
+ ) : (
+ <>
+ {flattenedData.map((replay: SessionReplayListItem, index) => (
+ <ReplayCard
+ key={`${replay.session_id}-${index}`}
+ replay={replay}
+ />
+ ))}
- {/* Infinite scroll anchor and loading indicator */}
- <div ref={ref} className="py-3 flex justify-center">
- {isFetchingNextPage && (
- <div className="flex items-center gap-2 text-neutral-400 text-xs">
- <Loader2 className="h-4 w-4 animate-spin" />
- Loading more replays...
- </div>
- )}
- {!hasNextPage &&
- !isFetchingNextPage &&
- flattenedData.length > 0 && (
- <div className="text-neutral-500 text-xs">
- All replays loaded
+ {/* Infinite scroll anchor and loading indicator */}
+ <div ref={ref} className="py-3 flex justify-center">
+ {isFetchingNextPage && (
+ <div className="flex items-center gap-2 text-neutral-400 text-xs">
+ <Loader2 className="h-4 w-4 animate-spin" />
+ Loading more replays...
</div>
)}
- </div>
- </>
- )}
- </ScrollArea>
+ {!hasNextPage &&
+ !isFetchingNextPage &&
+ flattenedData.length > 0 && (
+ <div className="text-neutral-500 text-xs">
+ All replays loaded
+ </div>
+ )}
+ </div>
+ </>
+ )}
+ </ScrollArea>
+ </div>
</div>
);
}
diff --git a/client/src/app/[site]/replay/components/player/ReplayPlayer.tsx b/client/src/app/[site]/replay/components/player/ReplayPlayer.tsx
index 166e35c64..125d31568 100644
--- a/client/src/app/[site]/replay/components/player/ReplayPlayer.tsx
+++ b/client/src/app/[site]/replay/components/player/ReplayPlayer.tsx
@@ -117,7 +117,7 @@ export function ReplayPlayer({
}
return (
- <div
+ <div
className="flex flex-col bg-neutral-950 overflow-hidden"
style={{ width: width, height: height }}
>
diff --git a/client/src/app/[site]/replay/components/replayStore.ts b/client/src/app/[site]/replay/components/replayStore.ts
index 8edfaaf1f..8c5b6cfc5 100644
--- a/client/src/app/[site]/replay/components/replayStore.ts
+++ b/client/src/app/[site]/replay/components/replayStore.ts
@@ -6,64 +6,71 @@ interface ActivityPeriod {
}
export const useReplayStore = create<{
+ minDuration: number;
+ setMinDuration: (minDuration: number) => void;
+
// Session selection
sessionId: string;
setSessionId: (sessionId: string) => void;
-
+
// Player state
player: any;
setPlayer: (player: any) => void;
-
+
// Playback state
isPlaying: boolean;
setIsPlaying: (isPlaying: boolean) => void;
-
+
currentTime: number;
setCurrentTime: (currentTime: number) => void;
-
+
duration: number;
setDuration: (duration: number) => void;
-
+
playbackSpeed: string;
setPlaybackSpeed: (speed: string) => void;
-
+
activityPeriods: ActivityPeriod[];
setActivityPeriods: (periods: ActivityPeriod[]) => void;
-
+
// Reset all player state when session changes
resetPlayerState: () => void;
}>((set) => ({
+ minDuration: 30,
+ setMinDuration: (minDuration) => set({ minDuration }),
+
// Session selection
sessionId: "",
setSessionId: (sessionId) => set({ sessionId }),
-
+
// Player state
player: null,
setPlayer: (player) => set({ player }),
-
+
// Playback state
isPlaying: false,
setIsPlaying: (isPlaying) => set({ isPlaying }),
-
+
currentTime: 0,
setCurrentTime: (currentTime) => set({ currentTime }),
-
+
duration: 0,
setDuration: (duration) => set({ duration }),
-
+
playbackSpeed: "1",
setPlaybackSpeed: (playbackSpeed) => set({ playbackSpeed }),
-
+
activityPeriods: [],
setActivityPeriods: (activityPeriods) => set({ activityPeriods }),
-
+
// Reset all player state when session changes
- resetPlayerState: () => set({
- player: null,
- isPlaying: false,
- currentTime: 0,
- duration: 0,
- playbackSpeed: "1",
- activityPeriods: [],
- }),
+ resetPlayerState: () =>
+ set({
+ player: null,
+ isPlaying: false,
+ currentTime: 0,
+ duration: 0,
+ playbackSpeed: "1",
+ activityPeriods: [],
+ }),
}));
diff --git a/client/src/app/[site]/replay/page.tsx b/client/src/app/[site]/replay/page.tsx
index 22fa586a9..0ed1da286 100644
--- a/client/src/app/[site]/replay/page.tsx
+++ b/client/src/app/[site]/replay/page.tsx
@@ -11,11 +11,14 @@ import { ReplayList } from "./components/ReplayList";
import { ReplayPlayer } from "./components/player/ReplayPlayer";
import { NothingFound } from "../../../components/NothingFound";
import { ReplayBreadcrumbs } from "./components/ReplayBreadcrumbs";
+import { useReplayStore } from "./components/replayStore";
export default function SessionReplayPage() {
useSetPageTitle("Rybbit · Session Replay");
- const { data, isLoading } = useGetSessionReplays();
+ const { minDuration } = useReplayStore();
+
+ const { data, isLoading } = useGetSessionReplays({ minDuration });
const hasNoReplays = !isLoading && !data?.pages[0].data?.length;
@@ -23,7 +26,7 @@ export default function SessionReplayPage() {
return (
<DisabledOverlay message="Replay">
- <div className="p-2 md:p-4 max-w-[2000px] mx-auto flex flex-col gap-1 overflow-hidden h-full">
+ <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 ? (
@@ -38,7 +41,10 @@ export default function SessionReplayPage() {
<ReplayList />
<div ref={ref} className="w-[calc(min(100vw, 2000px)-780px)]">
{resolvedWidth && resolvedHeight && (
- <ReplayPlayer width={resolvedWidth} height={resolvedHeight} />
+ <ReplayPlayer
+ width={resolvedWidth}
+ height={resolvedHeight - 1}
+ />
)}
</div>
<ReplayBreadcrumbs />
diff --git a/client/src/components/ui/input.tsx b/client/src/components/ui/input.tsx
index d9245ddbd..c1496013d 100644
--- a/client/src/components/ui/input.tsx
+++ b/client/src/components/ui/input.tsx
@@ -1,16 +1,33 @@
import * as React from "react"
+import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
-const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
- ({ className, type, ...props }, ref) => {
+const inputVariants = cva(
+ "flex w-full rounded-md border border-neutral-200 bg-transparent shadow-sm transition-colors file:border-0 file:bg-transparent file:font-medium file:text-neutral-950 placeholder:text-neutral-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-neutral-800 dark:file:text-neutral-50 dark:placeholder:text-neutral-400 dark:focus-visible:ring-neutral-300",
+ {
+ variants: {
+ inputSize: {
+ default: "h-9 px-3 py-1 text-base md:text-sm file:text-sm",
+ sm: "h-7 px-2 py-0.5 text-xs file:text-xs",
+ },
+ },
+ defaultVariants: {
+ inputSize: "default",
+ },
+ }
+)
+
+export interface InputProps
+ extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">,
+ VariantProps<typeof inputVariants> {}
+
+const Input = React.forwardRef<HTMLInputElement, InputProps>(
+ ({ className, type, inputSize, ...props }, ref) => {
return (
<input
type={type}
- className={cn(
- "flex h-9 w-full rounded-md border border-neutral-200 bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-neutral-950 placeholder:text-neutral-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:border-neutral-800 dark:file:text-neutral-50 dark:placeholder:text-neutral-400 dark:focus-visible:ring-neutral-300",
- className
- )}
+ className={cn(inputVariants({ inputSize, className }))}
ref={ref}
{...props}
/>
diff --git a/server/src/api/sessionReplay/getSessionReplays.ts b/server/src/api/sessionReplay/getSessionReplays.ts
index 6591866eb..ad77446ad 100644
--- a/server/src/api/sessionReplay/getSessionReplays.ts
+++ b/server/src/api/sessionReplay/getSessionReplays.ts
@@ -9,19 +9,21 @@ export async function getSessionReplays(
limit?: string;
offset?: string;
userId?: string;
+ minDuration?: string;
}>;
}>,
reply: FastifyReply
) {
try {
const siteId = Number(request.params.site);
- const { limit, offset, userId, filters } = request.query;
+ const { limit, offset, userId, minDuration, filters } = request.query;
const sessionReplayService = new SessionReplayQueryService();
const replays = await sessionReplayService.getSessionReplayList(siteId, {
limit: limit ? Number(limit) : 50,
offset: offset ? Number(offset) : 0,
userId: userId || undefined,
+ minDuration: minDuration ? Number(minDuration) : undefined,
startDate: request.query.startDate,
endDate: request.query.endDate,
timeZone: request.query.timeZone,
diff --git a/server/src/services/replay/sessionReplayQueryService.ts b/server/src/services/replay/sessionReplayQueryService.ts
index 9f28f35d9..d69d140f9 100644
--- a/server/src/services/replay/sessionReplayQueryService.ts
+++ b/server/src/services/replay/sessionReplayQueryService.ts
@@ -22,6 +22,7 @@ export class SessionReplayQueryService {
limit?: number;
offset?: number;
userId?: string;
+ minDuration?: number;
} & Pick<
FilterParams,
| "startDate"
@@ -32,7 +33,7 @@ export class SessionReplayQueryService {
| "filters"
>
): Promise<SessionReplayListItem[]> {
- const { limit = 50, offset = 0, userId } = options;
+ const { limit = 50, offset = 0, userId, minDuration } = options;
const timeStatement = getTimeStatement(options).replace(
/timestamp/g,
@@ -49,6 +50,11 @@ export class SessionReplayQueryService {
queryParams.userId = userId;
}
+ if (minDuration !== undefined) {
+ whereConditions.push(`duration_ms >= {minDuration:UInt32}`);
+ queryParams.minDuration = minDuration * 1000; // Convert seconds to milliseconds
+ }
+
// Build the base query for session IDs that have replay events
let sessionIdsSubquery = `
SELECT DISTINCT session_id