🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
feat: enhance analytics response and UI components
Bill Yang876be23de084
diff --git a/client/src/api/analytics/useSingleCol.ts b/client/src/api/analytics/useSingleCol.tsindex 7b650e6d5..c969af6c6 100644--- a/client/src/api/analytics/useSingleCol.ts+++ b/client/src/api/analytics/useSingleCol.ts@@ -9,6 +9,7 @@ type PeriodTime = "current" | "previous";export type SingleColResponse = {value: string;+ title?: string;count: number;percentage: number;pageviews?: number;diff --git a/client/src/app/[site]/main/components/sections/Pages.tsx b/client/src/app/[site]/main/components/sections/Pages.tsxindex 17f02156f..a95e93a8a 100644--- a/client/src/app/[site]/main/components/sections/Pages.tsx+++ b/client/src/app/[site]/main/components/sections/Pages.tsx@@ -14,7 +14,7 @@ import { truncateString } from "../../../../../lib/utils";import { Button } from "../../../../../components/ui/button";import { Expand } from "lucide-react";-type Tab = "pages" | "entry_pages" | "exit_pages";+type Tab = "pages" | "page_title" | "entry_pages" | "exit_pages";const MAX_LABEL_LENGTH = 70;@@ -37,6 +37,7 @@ export function Pages() {<div className="flex flex-row gap-2 justify-between items-center"><TabsList><TabsTrigger value="pages">Pages</TabsTrigger>+ <TabsTrigger value="page_title">Page Titles</TabsTrigger><TabsTrigger value="entry_pages">Entry Pages</TabsTrigger><TabsTrigger value="exit_pages">Exit Pages</TabsTrigger></TabsList>@@ -58,6 +59,20 @@ export function Pages() {close={close}/></TabsContent>+ <TabsContent value="page_title">+ <StandardSection+ filterParameter="pathname"+ title="Page Title"+ getValue={(e) => e.value}+ getKey={(e) => e.value}+ getLabel={(e) =>+ truncateString(e?.title ?? "", MAX_LABEL_LENGTH) || "Other"+ }+ getLink={(e) => `https://${siteMetadata?.domain}${e.value}`}+ expanded={expanded}+ close={close}+ />+ </TabsContent><TabsContent value="entry_pages"><StandardSectionfilterParameter="entry_page"@@ -65,7 +80,7 @@ export function Pages() {getValue={(e) => e.value}getKey={(e) => e.value}getLabel={(e) =>- truncateString(e.value, MAX_LABEL_LENGTH) || "Other"+ truncateString(e?.title ?? "", MAX_LABEL_LENGTH) || "Other"}getLink={(e) => `https://${siteMetadata?.domain}${e.value}`}expanded={expanded}diff --git a/docs/src/content/roadmap.mdx b/docs/src/content/roadmap.mdxindex b8122538d..3300d42b9 100644--- a/docs/src/content/roadmap.mdx+++ b/docs/src/content/roadmap.mdx@@ -13,7 +13,6 @@ Rybbit is a quickly growing project. We already have quite a few features, but t- Revenue tracking- Web vitals tracking- Email reports-- Traffic fitlers/bot blocking- Traffic alerts- Google Analytics import + other analytics platformsdiff --git a/server/src/api/analytics/getSingleCol.ts b/server/src/api/analytics/getSingleCol.tsindex fab110166..841e249c6 100644--- a/server/src/api/analytics/getSingleCol.ts+++ b/server/src/api/analytics/getSingleCol.ts@@ -26,6 +26,8 @@ interface GenericRequest {type GetSingleColResponse = {value: string;+ // title is only used for pathname+ title?: string;// count means sessions where this page was the entry/exitcount: number;percentage: number;@@ -165,6 +167,7 @@ const getQuery = (request: FastifyRequest<GenericRequest>) => {SELECTsession_id,pathname,+ page_title,timestamp,leadInFrame(timestamp) OVER (PARTITION BY session_id ORDER BY timestamp ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) as next_timestampFROM events@@ -178,6 +181,7 @@ const getQuery = (request: FastifyRequest<GenericRequest>) => {SELECTsession_id,pathname,+ page_title,timestamp,next_timestamp,if(isNull(next_timestamp), 0, dateDiff('second', timestamp, next_timestamp)) as time_diff_seconds@@ -186,14 +190,16 @@ const getQuery = (request: FastifyRequest<GenericRequest>) => {PathStats AS (SELECTpathname,+ page_title,count() as visits,count(DISTINCT session_id) as unique_sessions,avg(if(time_diff_seconds < 0, 0, if(time_diff_seconds > 1800, 1800, time_diff_seconds))) as avg_time_on_page_secondsFROM PageDurations- GROUP BY pathname+ GROUP BY pathname, page_title)SELECTpathname as value,+ page_title as title,unique_sessions as count,round((unique_sessions / sum(unique_sessions) OVER ()) * 100, 2) as percentage,visits as pageviews,