Skip to content

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

Add eventsLast30Days to AdminOrganizationData and update related components

Bill Yangf62babec4e89
diff --git a/client/src/api/admin/getAdminOrganizations.ts b/client/src/api/admin/getAdminOrganizations.ts
index 3f0f15fd9..41f0a6baf 100644
--- a/client/src/api/admin/getAdminOrganizations.ts
+++ b/client/src/api/admin/getAdminOrganizations.ts
@@ -22,6 +22,7 @@ export interface AdminOrganizationData {
domain: string;
createdAt: string;
eventsLast24Hours: number;
+ eventsLast30Days: number;
}[];
members: {
userId: string;
diff --git a/client/src/app/admin/components/organizations/Organizations.tsx b/client/src/app/admin/components/organizations/Organizations.tsx
index c4c191dea..9e0e2eb54 100644
--- a/client/src/app/admin/components/organizations/Organizations.tsx
+++ b/client/src/app/admin/components/organizations/Organizations.tsx
@@ -8,6 +8,7 @@ import { Badge } from "@/components/ui/badge";
import { Skeleton } from "@/components/ui/skeleton";
import { formatDistanceToNow } from "date-fns";
import { parseUtcTimestamp } from "@/lib/dateTimeUtils";
+import { formatter } from "@/lib/utils";
import { ChevronDown, ChevronRight, User, Building2, CreditCard, UserCheck, ExternalLink } from "lucide-react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
@@ -139,7 +140,7 @@ export function Organizations() {
const isOverLimit = row.original.overMonthlyLimit;
return (
<div className={`font-medium ${isOverLimit ? "text-red-400" : ""}`}>
- {count?.toLocaleString() || 0}
+ {formatter(count || 0)}
{isOverLimit && <span className="text-red-400 ml-1">⚠️</span>}
</div>
);
@@ -151,7 +152,16 @@ export function Organizations() {
accessorFn: row => row.sites.reduce((total, site) => total + Number(site.eventsLast24Hours || 0), 0),
cell: ({ row }) => {
const total = row.original.sites.reduce((sum, site) => sum + Number(site.eventsLast24Hours || 0), 0);
- return total.toLocaleString();
+ return formatter(total);
+ },
+ },
+ {
+ id: "eventsLast30Days",
+ header: ({ column }) => <SortableHeader column={column}>30d Events</SortableHeader>,
+ accessorFn: row => row.sites.reduce((total, site) => total + Number(site.eventsLast30Days || 0), 0),
+ cell: ({ row }) => {
+ const total = row.original.sites.reduce((sum, site) => sum + Number(site.eventsLast30Days || 0), 0);
+ return formatter(total);
},
},
{
@@ -279,6 +289,9 @@ export function Organizations() {
<TableCell>
<Skeleton className="h-5 w-20" />
</TableCell>
+ <TableCell>
+ <Skeleton className="h-5 w-20" />
+ </TableCell>
<TableCell>
<Skeleton className="h-5 w-16" />
</TableCell>
@@ -317,7 +330,7 @@ export function Organizations() {
<div>
<div className="text-xs text-neutral-400 uppercase tracking-wide">Event Limit</div>
<div className="font-medium">
- {row.original.subscription.eventLimit?.toLocaleString() || "Unlimited"}
+ {row.original.subscription.eventLimit ? formatter(row.original.subscription.eventLimit) : "Unlimited"}
</div>
</div>
{row.original.subscription.currentPeriodEnd && (
@@ -357,7 +370,7 @@ export function Organizations() {
<div className="flex flex-col">
<span className="font-medium">{site.domain}</span>
<span className="text-xs text-neutral-400">
- {site.eventsLast24Hours.toLocaleString()} events (24h)
+ {formatter(site.eventsLast24Hours)} events (24h) · {formatter(site.eventsLast30Days)} (30d)
</span>
</div>
<ExternalLink className="h-3 w-3" />
diff --git a/client/src/app/admin/components/shared/GrowthChart.tsx b/client/src/app/admin/components/shared/GrowthChart.tsx
index d9e72c7ea..8b600f018 100644
--- a/client/src/app/admin/components/shared/GrowthChart.tsx
+++ b/client/src/app/admin/components/shared/GrowthChart.tsx
@@ -71,7 +71,7 @@ export function GrowthChart({ data, color = "#3b82f6", title }: GrowthChartProps
stacked: false,
}}
enableSlices="x"
- curve="monotoneX"
+ curve="linear"
axisTop={null}
axisRight={null}
axisBottom={{
diff --git a/client/src/app/admin/components/sites/Sites.tsx b/client/src/app/admin/components/sites/Sites.tsx
index 82a6343f6..da82aea02 100644
--- a/client/src/app/admin/components/sites/Sites.tsx
+++ b/client/src/app/admin/components/sites/Sites.tsx
@@ -24,6 +24,7 @@ import { GrowthChart } from "../shared/GrowthChart";
import Link from "next/link";
import { Favicon } from "../../../../components/Favicon";
import { parseUtcTimestamp } from "../../../../lib/dateTimeUtils";
+import { formatter } from "../../../../lib/utils";
export function Sites() {
const { data: sites, isLoading, isError } = useAdminSites();
@@ -88,12 +89,12 @@ export function Sites() {
{
accessorKey: "eventsLast24Hours",
header: ({ column }) => <SortableHeader column={column}>Events (24h)</SortableHeader>,
- cell: ({ row }) => <div>{Number(row.getValue("eventsLast24Hours")).toLocaleString()}</div>,
+ cell: ({ row }) => <div>{formatter(Number(row.getValue("eventsLast24Hours")))}</div>,
},
{
accessorKey: "eventsLast30Days",
header: ({ column }) => <SortableHeader column={column}>Events (30d)</SortableHeader>,
- cell: ({ row }) => <div>{Number(row.getValue("eventsLast30Days")).toLocaleString()}</div>,
+ cell: ({ row }) => <div>{formatter(Number(row.getValue("eventsLast30Days")))}</div>,
},
{
id: "subscription",
diff --git a/server/src/api/admin/getAdminOrganizations.ts b/server/src/api/admin/getAdminOrganizations.ts
index 3fa91cba4..9c600e233 100644
--- a/server/src/api/admin/getAdminOrganizations.ts
+++ b/server/src/api/admin/getAdminOrganizations.ts
@@ -35,6 +35,7 @@ export interface AdminOrganizationData {
domain: string;
createdAt: string;
eventsLast24Hours: number;
+ eventsLast30Days: number;
}[];
members: {
userId: string;
@@ -99,34 +100,61 @@ export async function getAdminOrganizations(request: FastifyRequest, reply: Fast
.from(sites)
.where(allOrgIds.length > 0 ? inArray(sites.organizationId, allOrgIds) : undefined);
- // Get event counts for the past 24 hours from ClickHouse
+ // Get event counts for the past 24 hours and 30 days from ClickHouse
const now = DateTime.now();
const yesterday = now.minus({ hours: 24 });
+ const thirtyDaysAgo = now.minus({ days: 30 });
- let siteEventMap = new Map<number, number>();
+ let siteEventMap24h = new Map<number, number>();
+ let siteEventMap30d = new Map<number, number>();
try {
- const eventCountsResult = await clickhouse.query({
+ // Query for last 24 hours
+ const eventCounts24hResult = await clickhouse.query({
query: `
- SELECT
+ SELECT
site_id,
sum(event_count) as total_events
- FROM
+ FROM
hourly_events_by_site_mv_target
- WHERE
+ WHERE
event_hour >= toDateTime('${yesterday.toFormat("yyyy-MM-dd HH:mm:ss")}') AND
event_hour <= toDateTime('${now.toFormat("yyyy-MM-dd HH:mm:ss")}')
- GROUP BY
+ GROUP BY
site_id
`,
format: "JSONEachRow",
});
- const rawEventCounts = await eventCountsResult.json();
- const eventCounts = rawEventCounts as EventCountResult[];
+ const rawEventCounts24h = await eventCounts24hResult.json();
+ const eventCounts24h = rawEventCounts24h as EventCountResult[];
- for (const event of eventCounts) {
- siteEventMap.set(Number(event.site_id), event.total_events);
+ for (const event of eventCounts24h) {
+ siteEventMap24h.set(Number(event.site_id), event.total_events);
+ }
+
+ // Query for last 30 days
+ const eventCounts30dResult = await clickhouse.query({
+ query: `
+ SELECT
+ site_id,
+ sum(event_count) as total_events
+ FROM
+ hourly_events_by_site_mv_target
+ WHERE
+ event_hour >= toDateTime('${thirtyDaysAgo.toFormat("yyyy-MM-dd HH:mm:ss")}') AND
+ event_hour <= toDateTime('${now.toFormat("yyyy-MM-dd HH:mm:ss")}')
+ GROUP BY
+ site_id
+ `,
+ format: "JSONEachRow",
+ });
+
+ const rawEventCounts30d = await eventCounts30dResult.json();
+ const eventCounts30d = rawEventCounts30d as EventCountResult[];
+
+ for (const event of eventCounts30d) {
+ siteEventMap30d.set(Number(event.site_id), event.total_events);
}
} catch (clickhouseError) {
logger.warn(clickhouseError as Error, "ClickHouse query failed, continuing without event counts");
@@ -144,7 +172,8 @@ export async function getAdminOrganizations(request: FastifyRequest, reply: Fast
name: site.name,
domain: site.domain,
createdAt: site.createdAt,
- eventsLast24Hours: siteEventMap.get(site.siteId) || 0,
+ eventsLast24Hours: siteEventMap24h.get(site.siteId) || 0,
+ eventsLast30Days: siteEventMap30d.get(site.siteId) || 0,
});
}
}