Skip to content

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

Enhance session analytics by adding hostname to PageviewEvent and updating SessionCard for improved navigation

Bill Yangfe3154a189ec
diff --git a/client/src/api/analytics/userSessions.ts b/client/src/api/analytics/userSessions.ts
index 38b77494f..1b40b6a6e 100644
--- a/client/src/api/analytics/userSessions.ts
+++ b/client/src/api/analytics/userSessions.ts
@@ -115,6 +115,7 @@ export interface SessionDetails {
export interface PageviewEvent {
timestamp: string;
pathname: string;
+ hostname: string;
querystring: string;
page_title: string;
referrer: string;
diff --git a/client/src/app/[site]/sessions/components/SessionCard.tsx b/client/src/app/[site]/sessions/components/SessionCard.tsx
index 0018b0db4..bee36430d 100644
--- a/client/src/app/[site]/sessions/components/SessionCard.tsx
+++ b/client/src/app/[site]/sessions/components/SessionCard.tsx
@@ -34,6 +34,7 @@ import {
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Badge } from "@/components/ui/badge";
import { Alert, AlertDescription } from "@/components/ui/alert";
+import Link from "next/link";
interface SessionCardProps {
session: GetSessionsResponse[number];
@@ -122,10 +123,19 @@ function PageviewItem({
</div>
<div className="flex-1 min-w-0 mr-4">
- <div className="text-sm truncate" title={item.pathname}>
- {item.pathname}
- {item.querystring ? item.querystring : ""}
- </div>
+ <Link
+ href={`${item.hostname}${item.pathname}${
+ item.querystring ? `${item.querystring}` : ""
+ }`}
+ >
+ <div
+ className="text-sm truncate hover:underline"
+ title={item.pathname}
+ >
+ {item.pathname}
+ {item.querystring ? `${item.querystring}` : ""}
+ </div>
+ </Link>
</div>
<div className="text-xs text-gray-400 flex-shrink-0">
diff --git a/server/src/api/getSession.ts b/server/src/api/getSession.ts
index 69b5bec3b..c5fa11b06 100644
--- a/server/src/api/getSession.ts
+++ b/server/src/api/getSession.ts
@@ -31,6 +31,7 @@ export interface SessionDetails {
export interface PageviewEvent {
timestamp: string;
pathname: string;
+ hostname: string;
querystring: string;
page_title: string;
referrer: string;
@@ -99,6 +100,7 @@ LIMIT 1
SELECT
timestamp,
pathname,
+ hostname,
querystring,
page_title,
referrer,
@@ -112,16 +114,29 @@ WHERE
ORDER BY timestamp ASC
`;
- // Execute both queries
- const sessionResult = await clickhouse.query({
- query: sessionQuery,
- format: "JSONEachRow",
- });
+ // Execute both queries in parallel
+ const [sessionResultSettled, pageviewsResultSettled] =
+ await Promise.allSettled([
+ clickhouse.query({
+ query: sessionQuery,
+ format: "JSONEachRow",
+ }),
+ clickhouse.query({
+ query: pageviewsQuery,
+ format: "JSONEachRow",
+ }),
+ ]);
- const pageviewsResult = await clickhouse.query({
- query: pageviewsQuery,
- format: "JSONEachRow",
- });
+ // Check if queries were successful
+ if (sessionResultSettled.status === "rejected") {
+ throw sessionResultSettled.reason;
+ }
+ if (pageviewsResultSettled.status === "rejected") {
+ throw pageviewsResultSettled.reason;
+ }
+
+ const sessionResult = sessionResultSettled.value;
+ const pageviewsResult = pageviewsResultSettled.value;
const sessionData = await processResults<SessionDetails>(sessionResult);
const pageviewsData = await processResults<PageviewEvent>(pageviewsResult);