Skip to content

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

Handle errors in the session timeline. These were previously treated … (#505)

Chris Rimmerb6f7eb3736bc
diff --git a/client/src/api/analytics/userSessions.ts b/client/src/api/analytics/userSessions.ts
index eedcf508a..50edf9d60 100644
--- a/client/src/api/analytics/userSessions.ts
+++ b/client/src/api/analytics/userSessions.ts
@@ -36,6 +36,7 @@ export type GetSessionsResponse = {
exit_page: string;
pageviews: number;
events: number;
+ errors: number;
}[];
export function useGetSessionsInfinite(userId?: string) {
@@ -112,6 +113,14 @@ export interface SessionDetails {
exit_page: string;
}
+export interface SessionEventProps {
+ [key: string]: unknown;
+
+ // Error-specific props
+ message?: string;
+ stack?: string;
+}
+
export interface SessionEvent {
timestamp: string;
pathname: string;
@@ -121,7 +130,7 @@ export interface SessionEvent {
referrer: string;
type: string;
event_name?: string;
- props?: string;
+ props?: SessionEventProps;
}
export interface SessionPageviewsAndEvents {
diff --git a/client/src/app/[site]/errors/components/ErrorDetails.tsx b/client/src/app/[site]/errors/components/ErrorDetails.tsx
index 3d6eda9dd..a632c0e3d 100644
--- a/client/src/app/[site]/errors/components/ErrorDetails.tsx
+++ b/client/src/app/[site]/errors/components/ErrorDetails.tsx
@@ -31,6 +31,7 @@ import { memo, useMemo } from "react";
import { Browser } from "../../components/shared/icons/Browser";
import { CountryFlag } from "../../components/shared/icons/CountryFlag";
import { OperatingSystem } from "../../components/shared/icons/OperatingSystem";
+import { useParams } from "next/navigation";
interface ErrorDetailsProps {
errorMessage: string;
@@ -57,6 +58,7 @@ function truncateText(text: string | null, maxLength: number = 50) {
// Component to display individual error event
function ErrorEventItem({ errorEvent }: { errorEvent: ErrorEvent }) {
const { getRegionName } = useGetRegionName();
+ const { site } = useParams();
const getFullLocation = (event: ErrorEvent) => {
let location = "";
@@ -161,10 +163,12 @@ function ErrorEventItem({ errorEvent }: { errorEvent: ErrorEvent }) {
{errorEvent.user_id && (
<Tooltip>
<TooltipTrigger asChild>
- <Badge variant="outline" className="text-xs">
- <User className="w-3 h-3 mr-1" />
- {errorEvent.user_id.substring(0, 8)}
- </Badge>
+ <Link href={`/${site}/user/${errorEvent.user_id}`}>
+ <Badge variant="outline" className="text-xs">
+ <User className="w-3 h-3 mr-1" />
+ {errorEvent.user_id.substring(0, 8)}
+ </Badge>
+ </Link>
</TooltipTrigger>
<TooltipContent>User ID: {errorEvent.user_id}</TooltipContent>
</Tooltip>
diff --git a/client/src/components/Sessions/SessionCard.tsx b/client/src/components/Sessions/SessionCard.tsx
index 4b30a84d7..1e8ff7b04 100644
--- a/client/src/components/Sessions/SessionCard.tsx
+++ b/client/src/components/Sessions/SessionCard.tsx
@@ -10,6 +10,7 @@ import {
ChevronRight,
FileText,
MousePointerClick,
+ TriangleAlert,
} from "lucide-react";
import { DateTime } from "luxon";
import { memo, useState } from "react";
@@ -116,6 +117,18 @@ export function SessionCard({ session, onClick, userId }: SessionCardProps) {
</TooltipTrigger>
<TooltipContent>Events</TooltipContent>
</Tooltip>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Badge
+ variant="outline"
+ className="flex items-center gap-1 bg-neutral-800 text-gray-300"
+ >
+ <TriangleAlert className="w-4 h-4 text-red-500" />
+ <span>{formatter(session.errors)}</span>
+ </Badge>
+ </TooltipTrigger>
+ <TooltipContent>Errors</TooltipContent>
+ </Tooltip>
</div>
{/* Pages section with tooltips for long paths */}
diff --git a/client/src/components/Sessions/SessionDetails.tsx b/client/src/components/Sessions/SessionDetails.tsx
index 687bc1ab5..b16a3f628 100644
--- a/client/src/components/Sessions/SessionDetails.tsx
+++ b/client/src/components/Sessions/SessionDetails.tsx
@@ -12,6 +12,7 @@ import {
MousePointerClick,
Smartphone,
Tablet,
+ TriangleAlert,
} from "lucide-react";
import { DateTime } from "luxon";
import Link from "next/link";
@@ -44,13 +45,15 @@ function PageviewItem({
isLast?: boolean;
nextTimestamp?: string; // Timestamp of the next event for duration calculation
}) {
- const isEvent = item.type !== "pageview";
+ const isError = item.type === "error";
+ const isEvent = item.type === "custom_event";
+ const isPageview = item.type === "pageview";
const timestamp = DateTime.fromSQL(item.timestamp, { zone: "utc" }).toLocal();
const formattedTime = timestamp.toFormat(hour12 ? "h:mm:ss a" : "HH:mm:ss");
// Calculate duration if this is a pageview and we have the next timestamp
let duration = null;
- if (!isEvent && nextTimestamp) {
+ if (isPageview && nextTimestamp) {
const nextTime = DateTime.fromSQL(nextTimestamp, { zone: "utc" }).toLocal();
const totalSeconds = Math.floor(
nextTime.diff(timestamp).milliseconds / 1000
@@ -76,7 +79,8 @@ function PageviewItem({
"flex items-center justify-center w-8 h-8 rounded-full border",
isEvent
? "bg-amber-900/30 border-amber-500/50"
- : "bg-blue-900/30 border-blue-500/50"
+ : (isError ? "bg-red-900/30 border-red-500/50"
+ : "bg-blue-900/30 border-blue-500/50")
)}
>
<span className="text-sm font-medium">{index + 1}</span>
@@ -88,13 +92,15 @@ function PageviewItem({
<div className="flex-shrink-0 mr-3">
{isEvent ? (
<MousePointerClick className="w-4 h-4 text-amber-500" />
+ ) : (isError ? (
+ <TriangleAlert className="w-4 h-4 text-red-500" />
) : (
<FileText className="w-4 h-4 text-blue-500" />
- )}
+ ))}
</div>
<div className="flex-1 min-w-0 mr-4">
- {item.type === "pageview" ? (
+ {isPageview ? (
<Link
href={`https://${item.hostname}${item.pathname}${
item.querystring ? `${item.querystring}` : ""
@@ -122,7 +128,7 @@ function PageviewItem({
{formattedTime}
</div>
</div>
- {!isEvent && duration && (
+ {isPageview && duration && (
<div className="flex items-center pl-7 mt-1">
<div className="text-xs text-gray-400">
<Clock className="w-3 h-3 inline mr-1 text-gray-400" />
@@ -152,6 +158,40 @@ function PageviewItem({
</div>
</div>
)}
+ {isError && (
+ <div className="flex items-center pl-7 mt-1">
+ <div className="text-xs text-gray-400">
+ {item.props ? (
+ <span>
+ {item.props.message && (
+ <Badge
+ key="message"
+ variant="outline"
+ className="px-1.5 py-0 h-5 text-xs bg-neutral-800 text-gray-100 font-medium"
+ >
+ <span className="text-gray-300 font-light mr-1">
+ message:
+ </span>{" "}
+ {String(item.props.message)}
+ </Badge>
+ )}
+
+ {item.props.stack && (
+ <div>
+ <p className="mt-2 mb-1 text-gray-300 font-light">
+ Stack Trace:
+ </p>
+ <pre className="text-xs text-neutral-100 bg-neutral-800 p-2 rounded overflow-x-auto whitespace-pre-wrap break-words">
+ {item.props.stack}
+ </pre>
+ </div>
+ )}
+
+ </span>
+ ) : null}
+ </div>
+ </div>
+ )}
</div>
</div>
);
@@ -253,7 +293,11 @@ export function SessionDetails({ session, userId }: SessionDetailsProps) {
}, [allEvents]);
const totalEvents = useMemo(() => {
- return allEvents.filter((p: SessionEvent) => p.type !== "pageview").length;
+ return allEvents.filter((p: SessionEvent) => p.type === "custom_event").length;
+ }, [allEvents]);
+
+ const totalErrors = useMemo(() => {
+ return allEvents.filter((p: SessionEvent) => p.type === "error").length;
}, [allEvents]);
const { getRegionName } = useGetRegionName();
@@ -308,6 +352,13 @@ export function SessionDetails({ session, userId }: SessionDetailsProps) {
<MousePointerClick className="w-3 h-3" />
<span>Events: {totalEvents}</span>
</Badge>
+ <Badge
+ variant="outline"
+ className="flex items-center gap-1 text-gray-300 bg-red-500/60"
+ >
+ <TriangleAlert className="w-3 h-3" />
+ <span>Errors: {totalErrors}</span>
+ </Badge>
</div>
<div className="px-1 pt-2 pb-1">
{allEvents.map((pageview: SessionEvent, index: number) => {
diff --git a/server/src/api/analytics/getSessions.ts b/server/src/api/analytics/getSessions.ts
index 378bc1947..7cae02c8d 100644
--- a/server/src/api/analytics/getSessions.ts
+++ b/server/src/api/analytics/getSessions.ts
@@ -36,6 +36,7 @@ export type GetSessionsResponse = {
exit_page: string;
pageviews: number;
events: number;
+ errors: number;
}[];
export interface GetSessionsRequest {
@@ -92,7 +93,8 @@ export async function getSessions(
argMinIf(pathname, timestamp, type = 'pageview') AS entry_page,
argMaxIf(pathname, timestamp, type = 'pageview') AS exit_page,
countIf(type = 'pageview') AS pageviews,
- countIf(type = 'custom_event') AS events
+ countIf(type = 'custom_event') AS events,
+ countIf(type = 'error') AS errors
FROM events
WHERE
site_id = {siteId:Int32}