🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor StandardSection and update analytics data handling
Bill Yang3da096f074b7
diff --git a/client/src/api/analytics/useSingleCol.ts b/client/src/api/analytics/useSingleCol.tsindex 033875471..3875c45c8 100644--- a/client/src/api/analytics/useSingleCol.ts+++ b/client/src/api/analytics/useSingleCol.ts@@ -16,7 +16,7 @@ export type SingleColResponse = {export function useSingleCol({parameter,- limit = 10000,+ limit = 1000,periodTime,useFilters = true,}: {diff --git a/client/src/app/[site]/components/shared/StandardSection.tsx b/client/src/app/[site]/components/shared/StandardSection.tsxdeleted file mode 100644index 6948df6a0..000000000--- a/client/src/app/[site]/components/shared/StandardSection.tsx+++ /dev/null@@ -1,260 +0,0 @@-"use client";--import { Button } from "@/components/ui/button";-import {- Dialog,- DialogContent,- DialogHeader,- DialogTitle,- DialogTrigger,-} from "@/components/ui/dialog";-import { round } from "lodash";-import { AlertCircle, SquareArrowOutUpRight, RefreshCcw } from "lucide-react";-import { memo, ReactNode, useMemo } from "react";-import {- SingleColResponse,- useSingleCol,-} from "../../../../api/analytics/useSingleCol";-import { addFilter, FilterParameter } from "../../../../lib/store";-import { formatter } from "../../../../lib/utils";--const Skeleton = memo(() => {- // Generate widths following Pareto principle with top item at 100%- const widths = Array.from({ length: 10 }, (_, i) => {- if (i === 0) {- // First item always has 100% width- return 100;- } else if (i === 1) {- // Second item gets large width (60-80%)- return 60 + Math.random() * 20;- } else {- // Remaining 8 items get progressively smaller widths (10-40%)- const factor = 1 - (i - 2) / 8; // Creates a declining factor from 1 to 0.125- return 10 + factor * 30; // Creates widths from ~40% down to ~15%- }- });-- // Generate random widths for label and value placeholders- const labelWidths = Array.from({ length: 10 }, (_, i) => {- // First few items get wider labels (increased by 2.5x)- return i < 3 ? 75 + Math.random() * 100 : 40 + Math.random() * 60;- });-- const valueWidths = Array.from(- { length: 10 },- () => 20 + Math.random() * 40 // Between 20px and 60px (increased by 2.5x)- );-- return Array.from({ length: 10 }).map((_, index) => (- <div key={index} className="relative h-7 flex items-center">- <div- className="absolute inset-0 bg-neutral-800 py-2 rounded-md animate-pulse"- style={{ width: `${widths[index]}%` }}- ></div>- <div className="z-10 mx-2 flex justify-between items-center text-sm w-full">- <div className="flex items-center gap-1">- <div- className="h-4 bg-neutral-800 rounded animate-pulse"- style={{ width: `${labelWidths[index]}px` }}- ></div>- </div>- <div className="text-sm flex gap-2">- <div- className="h-4 bg-neutral-800 rounded animate-pulse"- style={{ width: `${valueWidths[index]}px` }}- ></div>- </div>- </div>- </div>- ));-});--export function StandardSection({- title,- getKey,- getLabel,- getValue,- getLink,- filterParameter,-}: {- title: string;- isFetching?: boolean;- getKey: (item: SingleColResponse) => string;- getLabel: (item: SingleColResponse) => ReactNode;- getValue: (item: SingleColResponse) => string;- getLink?: (item: SingleColResponse) => string;- filterParameter: FilterParameter;-}) {- const { data, isFetching, error, refetch } = useSingleCol({- parameter: filterParameter,- });-- const { data: previousData, isFetching: previousIsFetching } = useSingleCol({- parameter: filterParameter,- periodTime: "previous",- });-- // Determine if we're in a loading state- const isLoading = isFetching || previousIsFetching;-- const previousDataMap = useMemo(() => {- return previousData?.data?.reduce((acc, curr) => {- acc[getKey(curr)] = curr;- return acc;- }, {} as Record<string, SingleColResponse>);- }, [previousData]);-- const ratio = data?.data?.[0]?.percentage- ? 100 / data?.data?.[0]?.percentage- : 1;-- // Check for errors from either query- const hasError = error || previousData?.error;- const errorMessage =- error?.message || "An error occurred while fetching data";-- return (- <div className="flex flex-col gap-2">- {isLoading ? (- <Skeleton />- ) : hasError ? (- <div className="py-6 flex-1 flex flex-col items-center justify-center gap-3 transition-all">- <AlertCircle className="text-amber-400 w-8 h-8" />- <div className="text-center">- <div className="text-neutral-100 font-medium mb-1">- Failed to load data- </div>- <div className="text-sm text-neutral-400 max-w-md mx-auto mb-3">- {errorMessage}- </div>- </div>- <Button- variant="outline"- size="sm"- className="bg-transparent hover:bg-neutral-800 border-neutral-700 text-neutral-300 hover:text-neutral-100"- onClick={() => refetch()}- >- <RefreshCcw className="w-3 h-3" /> Try Again- </Button>- </div>- ) : (- data?.data?.slice(0, 10).map((e) => (- <div- key={getKey(e)}- className="relative h-7 flex items-center cursor-pointer hover:bg-neutral-850 group"- onClick={() =>- addFilter({- parameter: filterParameter,- value: [getValue(e)],- type: "equals",- })- }- >- <div- className="absolute inset-0 bg-accent-400 py-2 opacity-30 rounded-md"- style={{ width: `${e.percentage * ratio}%` }}- ></div>- <div className="z-10 mx-2 flex justify-between items-center text-sm w-full">- <div className="flex items-center gap-1">- {getLabel(e)}- {getLink && (- <a- href={getLink(e)}- target="_blank"- onClick={(e) => e.stopPropagation()}- >- <SquareArrowOutUpRight- className="w-3 h-3 text-neutral-300 hover:text-neutral-100"- strokeWidth={3}- />- </a>- )}- </div>- <div className="text-sm flex gap-2">- <div className="hidden group-hover:block text-neutral-400">- {round(e.percentage, 1)}%- </div>- <div>{formatter(e.count)}</div>- {/* <div>- {previousDataMap?.[getKey(e)]?.percentage ? (- <div className="text-sm flex gap-2">- <div>- {round(- e.percentage -- (previousDataMap?.[getKey(e)]?.percentage || 0),- 1- )}- %- </div>- </div>- ) : null}- </div> */}- </div>- </div>- </div>- ))- )}- {isLoading ? (- // Skeleton for "View All" button when loading- <Button variant="outline" disabled className="opacity-50">- View All- </Button>- ) : !hasError && data?.data?.length && data?.data?.length > 10 ? (- <Dialog>- <DialogTrigger asChild>- <Button variant="outline">View All</Button>- </DialogTrigger>- <DialogContent className="max-w-[90vw] w-[1000px]">- <DialogHeader>- <DialogTitle>{title}</DialogTitle>- </DialogHeader>- <div className="flex flex-col gap-2 max-h-[90vh] overflow-x-hidden">- {data?.data?.map((e) => (- <div- key={getKey(e)}- className="relative flex items-center mr-3 cursor-pointer hover:bg-neutral-850 "- onClick={() =>- addFilter({- parameter: filterParameter,- value: [getValue(e)],- type: "equals",- })- }- >- <div- className="absolute inset-0 bg-accent-400 py-2 opacity-30 rounded-md"- style={{ width: `${e.percentage * ratio}%` }}- ></div>- <div className="z-10 ml-2 mr-4 flex justify-between items-center text-sm w-full h-7">- <div className="flex items-center gap-1">- {getLabel(e)}- {getLink && (- <a- href={getLink(e)}- target="_blank"- onClick={(e) => e.stopPropagation()}- >- <SquareArrowOutUpRight- className="w-3 h-3 text-neutral-300 hover:text-neutral-100"- strokeWidth={3}- />- </a>- )}- </div>- <div className="text-sm flex">- <div>{e.count.toLocaleString()}</div>- <div className="mx-2 bg-neutral-400 w-[1px] rounded-full h-5"></div>- <div className="w-10 text-neutral-400">- {round(e.percentage, 2)}%- </div>- </div>- </div>- </div>- ))}- </div>- </DialogContent>- </Dialog>- ) : null}- </div>- );-}diff --git a/client/src/app/[site]/components/shared/StandardSection/Skeleton.tsx b/client/src/app/[site]/components/shared/StandardSection/Skeleton.tsxnew file mode 100644index 000000000..3dd693746--- /dev/null+++ b/client/src/app/[site]/components/shared/StandardSection/Skeleton.tsx@@ -0,0 +1,60 @@+import { memo } from "react";++export const Skeleton = memo(() => {+ // Generate widths following Pareto principle with top item at 100%+ const widths = Array.from({ length: 10 }, (_, i) => {+ if (i === 0) {+ // First item always has 100% width+ return 100;+ } else if (i === 1) {+ // Second item gets large width (60-80%)+ return 60 + Math.random() * 20;+ } else {+ // Remaining 8 items get progressively smaller widths (10-40%)+ const factor = 1 - (i - 2) / 8; // Creates a declining factor from 1 to 0.125+ return 10 + factor * 30; // Creates widths from ~40% down to ~15%+ }+ });++ // Generate random widths for label and value placeholders+ const labelWidths = Array.from({ length: 10 }, (_, i) => {+ // First few items get wider labels (increased by 2.5x)+ return i < 3 ? 75 + Math.random() * 100 : 40 + Math.random() * 60;+ });++ const valueWidths = Array.from(+ { length: 10 },+ () => 20 + Math.random() * 40 // Between 20px and 60px (increased by 2.5x)+ );++ return (+ <>+ <div className="flex flex-row gap-2 justify-between pr-1 text-xs text-neutral-400">+ <div className="h-3 bg-neutral-800 rounded animate-pulse w-16"></div>+ <div className="h-3 bg-neutral-800 rounded animate-pulse w-12"></div>+ </div>+ {Array.from({ length: 10 }).map((_, index) => (+ <div key={index} className="relative h-7 flex items-center">+ <div+ className="absolute inset-0 bg-neutral-800 py-2 rounded-md animate-pulse"+ style={{ width: `${widths[index]}%` }}+ ></div>+ <div className="z-10 mx-2 flex justify-between items-center text-sm w-full">+ <div className="flex items-center gap-1">+ <div+ className="h-4 bg-neutral-800 rounded animate-pulse"+ style={{ width: `${labelWidths[index]}px` }}+ ></div>+ </div>+ <div className="text-sm flex gap-2">+ <div+ className="h-4 bg-neutral-800 rounded animate-pulse"+ style={{ width: `${valueWidths[index]}px` }}+ ></div>+ </div>+ </div>+ </div>+ ))}+ </>+ );+});diff --git a/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx b/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsxnew file mode 100644index 000000000..a408f9095--- /dev/null+++ b/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx@@ -0,0 +1,252 @@+"use client";++import { Button } from "@/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from "@/components/ui/dialog";+import { round } from "lodash";+import { AlertCircle, RefreshCcw, SquareArrowOutUpRight } from "lucide-react";+import { ReactNode, useMemo } from "react";+import {+ SingleColResponse,+ useSingleCol,+} from "../../../../../api/analytics/useSingleCol";+import { addFilter, FilterParameter } from "../../../../../lib/store";+import { formatter } from "../../../../../lib/utils";+import { Skeleton } from "./Skeleton";++const Row = ({+ e,+ ratio,+ getKey,+ getLabel,+ getValue,+ getLink,+ filterParameter,+}: {+ e: SingleColResponse;+ ratio: number;+ getKey: (item: SingleColResponse) => string;+ getLabel: (item: SingleColResponse) => ReactNode;+ getValue: (item: SingleColResponse) => string;+ getLink?: (item: SingleColResponse) => string;+ filterParameter: FilterParameter;+}) => {+ return (+ <div+ key={getKey(e)}+ className="relative h-7 flex items-center cursor-pointer hover:bg-neutral-850 group"+ onClick={() =>+ addFilter({+ parameter: filterParameter,+ value: [getValue(e)],+ type: "equals",+ })+ }+ >+ <div+ className="absolute inset-0 bg-accent-400 py-2 opacity-30 rounded-md"+ style={{ width: `${e.percentage * ratio}%` }}+ ></div>+ <div className="z-10 mx-2 flex justify-between items-center text-sm w-full">+ <div className="flex items-center gap-1">+ {getLabel(e)}+ {getLink && (+ <a+ href={getLink(e)}+ target="_blank"+ onClick={(e) => e.stopPropagation()}+ >+ <SquareArrowOutUpRight+ className="w-3 h-3 text-neutral-300 hover:text-neutral-100"+ strokeWidth={3}+ />+ </a>+ )}+ </div>+ <div className="text-sm flex gap-2">+ <div className="hidden group-hover:block text-neutral-400">+ {round(e.percentage, 1)}%+ </div>+ <div>{formatter(e.count)}</div>+ {/* <div>+ {previousDataMap?.[getKey(e)]?.percentage ? (+ <div className="text-sm flex gap-2">+ <div>+ {round(+ e.percentage -+ (previousDataMap?.[getKey(e)]?.percentage || 0),+ 1+ )}+ %+ </div>+ </div>+ ) : null}+ </div> */}+ </div>+ </div>+ </div>+ );+};++export function StandardSection({+ title,+ getKey,+ getLabel,+ getValue,+ getLink,+ filterParameter,+}: {+ title: string;+ isFetching?: boolean;+ getKey: (item: SingleColResponse) => string;+ getLabel: (item: SingleColResponse) => ReactNode;+ getValue: (item: SingleColResponse) => string;+ getLink?: (item: SingleColResponse) => string;+ filterParameter: FilterParameter;+}) {+ const { data, isFetching, error, refetch } = useSingleCol({+ parameter: filterParameter,+ });++ const { data: previousData, isFetching: previousIsFetching } = useSingleCol({+ parameter: filterParameter,+ periodTime: "previous",+ });++ // Determine if we're in a loading state+ const isLoading = isFetching || previousIsFetching;++ const previousDataMap = useMemo(() => {+ return previousData?.data?.reduce((acc, curr) => {+ acc[getKey(curr)] = curr;+ return acc;+ }, {} as Record<string, SingleColResponse>);+ }, [previousData]);++ const ratio = data?.data?.[0]?.percentage+ ? 100 / data?.data?.[0]?.percentage+ : 1;++ // Check for errors from either query+ const hasError = error || previousData?.error;+ const errorMessage =+ error?.message || "An error occurred while fetching data";++ return (+ <div className="flex flex-col gap-2">+ {isLoading ? (+ <Skeleton />+ ) : hasError ? (+ <div className="py-6 flex-1 flex flex-col items-center justify-center gap-3 transition-all">+ <AlertCircle className="text-amber-400 w-8 h-8" />+ <div className="text-center">+ <div className="text-neutral-100 font-medium mb-1">+ Failed to load data+ </div>+ <div className="text-sm text-neutral-400 max-w-md mx-auto mb-3">+ {errorMessage}+ </div>+ </div>+ <Button+ variant="outline"+ size="sm"+ className="bg-transparent hover:bg-neutral-800 border-neutral-700 text-neutral-300 hover:text-neutral-100"+ onClick={() => refetch()}+ >+ <RefreshCcw className="w-3 h-3" /> Try Again+ </Button>+ </div>+ ) : (+ <>+ <div className="flex flex-row gap-2 justify-between pr-1 text-xs text-neutral-400">+ <div>{title}</div>+ <div>Sessions</div>+ </div>+ {data?.data?.slice(0, 10).map((e) => (+ <Row+ e={e}+ ratio={ratio}+ getKey={getKey}+ getLabel={getLabel}+ getValue={getValue}+ getLink={getLink}+ filterParameter={filterParameter}+ />+ ))}+ </>+ )}+ {isLoading ? (+ // Skeleton for "View All" button when loading+ <Button variant="outline" disabled className="opacity-50">+ View All+ </Button>+ ) : !hasError && data?.data?.length && data?.data?.length > 10 ? (+ <Dialog>+ <DialogTrigger asChild>+ <Button variant="outline">View All</Button>+ </DialogTrigger>+ <DialogContent className="max-w-[90vw] w-[1000px]">+ <DialogHeader>+ <DialogTitle>{title}</DialogTitle>+ </DialogHeader>+ <div className="flex flex-col gap-2">+ <div className="flex flex-row gap-2 justify-between pr-20 text-sm text-neutral-400">+ <div>{title}</div>+ <div>Sessions</div>+ </div>+ <div className="flex flex-col gap-2 max-h-[85vh] overflow-x-hidden">+ {data?.data?.map((e) => (+ <div+ key={getKey(e)}+ className="relative flex items-center mr-3 cursor-pointer hover:bg-neutral-850"+ onClick={() =>+ addFilter({+ parameter: filterParameter,+ value: [getValue(e)],+ type: "equals",+ })+ }+ >+ <div+ className="absolute inset-0 bg-accent-400 py-2 opacity-30 rounded-md"+ style={{ width: `${e.percentage * ratio}%` }}+ ></div>+ <div className="z-10 ml-2 mr-4 flex justify-between items-center text-sm w-full h-7">+ <div className="flex items-center gap-1">+ {getLabel(e)}+ {getLink && (+ <a+ href={getLink(e)}+ target="_blank"+ onClick={(e) => e.stopPropagation()}+ >+ <SquareArrowOutUpRight+ className="w-3 h-3 text-neutral-300 hover:text-neutral-100"+ strokeWidth={3}+ />+ </a>+ )}+ </div>+ <div className="text-sm flex">+ <div>{e.count.toLocaleString()}</div>+ <div className="mx-2 bg-neutral-400 w-[1px] rounded-full h-5"></div>+ <div className="w-10 text-neutral-400">+ {round(e.percentage, 2)}%+ </div>+ </div>+ </div>+ </div>+ ))}+ </div>+ </div>+ </DialogContent>+ </Dialog>+ ) : null}+ </div>+ );+}diff --git a/client/src/app/[site]/main/components/sections/Countries.tsx b/client/src/app/[site]/main/components/sections/Countries.tsxindex db6da3823..e5bfad2b3 100644--- a/client/src/app/[site]/main/components/sections/Countries.tsx+++ b/client/src/app/[site]/main/components/sections/Countries.tsx@@ -1,6 +1,6 @@"use client";import { getCountryName } from "../../../../../lib/utils";-import { StandardSection } from "../../../components/shared/StandardSection";+import { StandardSection } from "../../../components/shared/StandardSection/StandardSection";import { CountryFlag } from "../../../components/shared/icons/CountryFlag";import { useState } from "react";import {@@ -21,11 +21,11 @@ type Tab = "countries" | "regions";export function Countries() {const [tab, setTab] = useState<Tab>("countries");return (- <Card className="h-[493px]">- <CardHeader>+ <Card className="">+ {/* <CardHeader><CardTitle>Countries</CardTitle>- </CardHeader>- <CardContent className="mt-[-8px]">+ </CardHeader> */}+ <CardContent className="mt-2"><TabsdefaultValue="countries"value={tab}diff --git a/client/src/app/[site]/main/components/sections/Devices.tsx b/client/src/app/[site]/main/components/sections/Devices.tsxindex 188064e26..f52668825 100644--- a/client/src/app/[site]/main/components/sections/Devices.tsx+++ b/client/src/app/[site]/main/components/sections/Devices.tsx@@ -1,5 +1,6 @@"use client";+import { Monitor, Smartphone, Tablet } from "lucide-react";import { useState } from "react";import {Tabs,@@ -7,16 +8,10 @@ import {TabsList,TabsTrigger,} from "../../../../../components/ui/basic-tabs";-import { StandardSection } from "../../../components/shared/StandardSection";-import { OperatingSystem } from "../../../components/shared/icons/OperatingSystem";-import {- Card,- CardContent,- CardHeader,- CardTitle,-} from "../../../../../components/ui/card";+import { Card, CardContent } from "../../../../../components/ui/card";+import { StandardSection } from "../../../components/shared/StandardSection/StandardSection";import { Browser } from "../../../components/shared/icons/Browser";-import { Monitor, Smartphone, Tablet } from "lucide-react";+import { OperatingSystem } from "../../../components/shared/icons/OperatingSystem";type Tab = "devices" | "browsers" | "os" | "dimensions";@@ -24,10 +19,7 @@ export function Devices() {const [tab, setTab] = useState<Tab>("devices");return (<Card className="h-[493px]">- <CardHeader>- <CardTitle>Devices</CardTitle>- </CardHeader>- <CardContent className="mt-[-8px]">+ <CardContent className="mt-2"><TabsdefaultValue="devices"value={tab}diff --git a/client/src/app/[site]/main/components/sections/Pages.tsx b/client/src/app/[site]/main/components/sections/Pages.tsxindex 51c9ae2de..f20f984b0 100644--- a/client/src/app/[site]/main/components/sections/Pages.tsx+++ b/client/src/app/[site]/main/components/sections/Pages.tsx@@ -1,20 +1,15 @@"use client";import { useState } from "react";+import { GetSitesResponse } from "../../../../../api/admin/sites";import {Tabs,TabsContent,TabsList,TabsTrigger,} from "../../../../../components/ui/basic-tabs";-import {- Card,- CardContent,- CardHeader,- CardTitle,-} from "../../../../../components/ui/card";-import { StandardSection } from "../../../components/shared/StandardSection";-import { GetSitesResponse } from "../../../../../api/admin/sites";+import { Card, CardContent } from "../../../../../components/ui/card";+import { StandardSection } from "../../../components/shared/StandardSection/StandardSection";type Tab = "pages" | "entry_pages" | "exit_pages";@@ -26,10 +21,7 @@ export function Pages({const [tab, setTab] = useState<Tab>("pages");return (<Card className="h-[493px]">- <CardHeader>- <CardTitle>Pages</CardTitle>- </CardHeader>- <CardContent className="mt-[-8px]">+ <CardContent className="mt-2"><TabsdefaultValue="pages"value={tab}diff --git a/client/src/app/[site]/main/components/sections/Referrers.tsx b/client/src/app/[site]/main/components/sections/Referrers.tsxindex cf71cc50a..42d6935fa 100644--- a/client/src/app/[site]/main/components/sections/Referrers.tsx+++ b/client/src/app/[site]/main/components/sections/Referrers.tsx@@ -6,13 +6,8 @@ import {TabsList,TabsTrigger,} from "../../../../../components/ui/basic-tabs";-import {- Card,- CardContent,- CardHeader,- CardTitle,-} from "../../../../../components/ui/card";-import { StandardSection } from "../../../components/shared/StandardSection";+import { Card, CardContent } from "../../../../../components/ui/card";+import { StandardSection } from "../../../components/shared/StandardSection/StandardSection";type Tab = "referrers";@@ -20,10 +15,7 @@ export function Referrers() {const [tab, setTab] = useState<Tab>("referrers");return (<Card className="h-[493px]">- <CardHeader>- <CardTitle>Referrers</CardTitle>- </CardHeader>- <CardContent className="mt-[-8px]">+ <CardContent className="mt-2"><TabsdefaultValue="referrers"value={tab}diff --git a/client/src/components/ui/basic-tabs.tsx b/client/src/components/ui/basic-tabs.tsxindex 7efdce73d..5f76a0c8c 100644--- a/client/src/components/ui/basic-tabs.tsx+++ b/client/src/components/ui/basic-tabs.tsx@@ -29,7 +29,7 @@ const TabsTrigger = React.forwardRef<<TabsPrimitive.Triggerref={ref}className={cn(- "inline-flex items-center justify-center whitespace-nowrap border-b-2 border-transparent py-1 text-xs font-medium text-neutral-600 transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-950 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:border-neutral-950 data-[state=active]:text-neutral-950 dark:text-neutral-400 dark:focus-visible:ring-neutral-300 dark:data-[state=active]:border-neutral-100 dark:data-[state=active]:text-neutral-50",+ "inline-flex items-center justify-center whitespace-nowrap border-b-2 border-transparent py-1 text-sm font-medium text-neutral-600 transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-950 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:border-neutral-950 data-[state=active]:text-neutral-950 dark:text-neutral-400 dark:focus-visible:ring-neutral-300 dark:data-[state=active]:border-neutral-100 dark:data-[state=active]:text-neutral-50",className)}{...props}diff --git a/server/src/api/getSingleCol.ts b/server/src/api/getSingleCol.tsindex d87fca05d..14ad9ce61 100644--- a/server/src/api/getSingleCol.ts+++ b/server/src/api/getSingleCol.ts@@ -35,57 +35,105 @@ const getQuery = (request: GenericRequest["Querystring"]) => {const filterStatement = getFilterStatement(filters);+ const percentageStatement = `ROUND(+ COUNT(distinct(session_id)) * 100.0 / SUM(COUNT(distinct(session_id))) OVER (),+ 2+ ) as percentage`;+if (parameter === "dimensions") {return `SELECTconcat(toString(screen_width), 'x', toString(screen_height)) AS value,- COUNT(*) as count,- ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) as percentage- FROM sessions_mv+ COUNT(distinct(session_id)) as count,+ ${percentageStatement}+ FROM pageviewsWHEREsite_id = ${site}${filterStatement}- ${getTimeStatement(startDate, endDate, timezone, "sessions")}+ ${getTimeStatement(startDate, endDate, timezone)}GROUP BY value ORDER BY count desc${limit ? `LIMIT ${limit}` : ""};`;}- if (["querystring", "page_title", "pathname"].includes(parameter)) {+ // if (["querystring", "page_title", "pathname"].includes(parameter)) {+ // }++ if (parameter === "exit_page") {return `- SELECT- ${geSqlParam(parameter)} as value,- COUNT(*) as count,- ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) as percentage- FROM pageviews- WHERE- site_id = ${site}- ${filterStatement}+ SELECT+ pathname as value,+ COUNT(distinct(session_id)) as count,+ ${percentageStatement}+ FROM (+ SELECT+ session_id,+ argMax(hostname, timestamp) AS hostname,+ argMax(pathname, timestamp) AS pathname+ FROM pageviews+ WHERE+ site_id = ${site}${getTimeStatement(startDate, endDate, timezone)}- AND type = 'pageview'- GROUP BY value ORDER BY count desc- ${limit ? `LIMIT ${limit}` : ""};- `;+ GROUP BY session_id+ ) AS exit_pages+ GROUP BY value ORDER BY count desc+ ${limit ? `LIMIT ${limit}` : ""};`;+ }++ if (parameter === "entry_page") {+ return `+ SELECT+ pathname as value,+ COUNT(distinct(session_id)) as count,+ ${percentageStatement}+ FROM (+ SELECT+ session_id,+ argMin(hostname, timestamp) AS hostname,+ argMin(pathname, timestamp) AS pathname+ FROM pageviews+ WHERE+ site_id = ${site}+ ${getTimeStatement(startDate, endDate, timezone)}+ GROUP BY session_id+ ) AS entry_pages+ GROUP BY value ORDER BY count desc+ ${limit ? `LIMIT ${limit}` : ""};`;}return `SELECT- ${parameter} as value,- count() as count,- ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) as percentage,- ROUND(AVG(dateDiff('second', session_start, session_end))) as avg_session_duration,- ROUND(SUM(if(pageviews = 1, 1, 0)) * 100.0 / COUNT(), 2) as bounce_rate- FROM- sessions_mv+ ${geSqlParam(parameter)} as value,+ COUNT(distinct(session_id)) as count,+ ${percentageStatement}+ FROM pageviewsWHEREsite_id = ${site}- AND notEmpty(${parameter})- ${getTimeStatement(startDate, endDate, timezone, "sessions")}- GROUP BY- ${parameter}- ORDER BY- COUNT() DESC+ ${filterStatement}+ ${getTimeStatement(startDate, endDate, timezone)}+ AND type = 'pageview'+ GROUP BY value ORDER BY count desc${limit ? `LIMIT ${limit}` : ""};`;+ // return `+ // SELECT+ // ${parameter} as value,+ // count() as count,+ // ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) as percentage,+ // ROUND(AVG(dateDiff('second', session_start, session_end))) as avg_session_duration,+ // ROUND(SUM(if(pageviews = 1, 1, 0)) * 100.0 / COUNT(), 2) as bounce_rate+ // FROM+ // sessions_mv+ // WHERE+ // site_id = ${site}+ // AND notEmpty(${parameter})+ // ${filterStatement}+ // ${getTimeStatement(startDate, endDate, timezone, "sessions")}+ // GROUP BY+ // ${parameter}+ // ORDER BY+ // COUNT() DESC+ // ${limit ? `LIMIT ${limit}` : ""};+ // `;};export async function getSingleCol(@@ -110,6 +158,7 @@ export async function getSingleCol(const data = await processResults<GetSingleColResponse[number]>(result);return res.send({ data });} catch (error) {+ console.log(query);console.error(`Error fetching ${parameter}:`, error);return res.status(500).send({ error: `Failed to fetch ${parameter}` });}